This repository has been archived by the owner on Feb 26, 2024. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
First attempt at abstracting assets.
RE #39
- Loading branch information
Showing
7 changed files
with
92 additions
and
0 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
default_app_config = '%s.apps.AppConfig' % __name__ |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,8 @@ | ||
from __future__ import unicode_literals | ||
|
||
from django.apps import AppConfig | ||
|
||
|
||
class AppConfig(AppConfig): | ||
name = '.'.join(__name__.split('.')[:-1]) # Name of package where `apps` module is located | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
# -*- coding: utf-8 -*- | ||
from __future__ import unicode_literals | ||
|
||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
('contenttypes', '0002_remove_content_type_name'), | ||
('icekit', '0006_auto_20150911_0744'), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name='Asset', | ||
fields=[ | ||
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)), | ||
('title', models.CharField(help_text='The title is shown in the "title" attribute', max_length=255, blank=True)), | ||
('caption', models.TextField(blank=True)), | ||
('admin_notes', models.TextField(help_text='Internal notes for administrators only.', blank=True)), | ||
('categories', models.ManyToManyField(related_name='assets_asset_related', to='icekit.MediaCategory', blank=True)), | ||
('polymorphic_ctype', models.ForeignKey(related_name='polymorphic_assets.asset_set+', editable=False, to='contenttypes.ContentType', null=True)), | ||
], | ||
options={ | ||
'abstract': False, | ||
}, | ||
), | ||
] |
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,53 @@ | ||
from __future__ import unicode_literals | ||
|
||
import six | ||
from django.db import models | ||
from django.utils.translation import ugettext_lazy as _ | ||
from fluent_contents.models import ContentItem | ||
from polymorphic import PolymorphicModel | ||
|
||
|
||
class Asset(PolymorphicModel): | ||
""" | ||
A static asset available for use on a CMS page. | ||
""" | ||
title = models.CharField( | ||
max_length=255, | ||
blank=True, | ||
help_text=_('The title is shown in the "title" attribute'), | ||
) | ||
caption = models.TextField( | ||
blank=True, | ||
) | ||
categories = models.ManyToManyField( | ||
'icekit.MediaCategory', | ||
blank=True, | ||
related_name='%(app_label)s_%(class)s_related', | ||
) | ||
admin_notes = models.TextField( | ||
blank=True, | ||
help_text=_('Internal notes for administrators only.'), | ||
) | ||
|
||
def get_uses(self): | ||
return [item.parent.get_absolute_url() for item in self.assetitem_set().all()] | ||
|
||
def __str__(self): | ||
return self.title | ||
|
||
|
||
class AssetItem(ContentItem): | ||
""" | ||
Concrete uses of an Asset. | ||
""" | ||
asset = models.ForeignKey( | ||
'icekit.assets.models.Asset', | ||
) | ||
|
||
class Meta: | ||
abstract = True | ||
verbose_name = _('Asset Item') | ||
verbose_name_plural = _('Asset Items') | ||
|
||
def __str__(self): | ||
return six.text_type(self.asset) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters