diff --git a/icekit/assets/__init__.py b/icekit/assets/__init__.py new file mode 100644 index 00000000..dd48ee45 --- /dev/null +++ b/icekit/assets/__init__.py @@ -0,0 +1 @@ +default_app_config = '%s.apps.AppConfig' % __name__ diff --git a/icekit/assets/apps.py b/icekit/assets/apps.py new file mode 100644 index 00000000..129ec942 --- /dev/null +++ b/icekit/assets/apps.py @@ -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 + diff --git a/icekit/assets/migrations/0001_initial.py b/icekit/assets/migrations/0001_initial.py new file mode 100644 index 00000000..23e45ff1 --- /dev/null +++ b/icekit/assets/migrations/0001_initial.py @@ -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, + }, + ), + ] diff --git a/icekit/assets/migrations/__init__.py b/icekit/assets/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/icekit/assets/models.py b/icekit/assets/models.py new file mode 100644 index 00000000..56d768e3 --- /dev/null +++ b/icekit/assets/models.py @@ -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) diff --git a/icekit/tests/settings.py b/icekit/tests/settings.py index bd8af354..e63b3754 100644 --- a/icekit/tests/settings.py +++ b/icekit/tests/settings.py @@ -43,6 +43,7 @@ 'fluent_pages.pagetypes.fluentpage', 'haystack', 'icekit', + 'icekit.assets', 'icekit.page_types.article', 'icekit.page_types.layout_page', 'icekit.page_types.search_page', diff --git a/manage.py b/manage.py old mode 100644 new mode 100755