Skip to content
This repository was archived by the owner on Feb 26, 2024. It is now read-only.

Commit db9a3b7

Browse files
committed
First attempt at abstracting assets.
RE #39
1 parent a025303 commit db9a3b7

File tree

7 files changed

+92
-0
lines changed

7 files changed

+92
-0
lines changed

icekit/assets/__init__.py

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
default_app_config = '%s.apps.AppConfig' % __name__

icekit/assets/apps.py

+8
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
from __future__ import unicode_literals
2+
3+
from django.apps import AppConfig
4+
5+
6+
class AppConfig(AppConfig):
7+
name = '.'.join(__name__.split('.')[:-1]) # Name of package where `apps` module is located
8+
+29
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
# -*- coding: utf-8 -*-
2+
from __future__ import unicode_literals
3+
4+
from django.db import migrations, models
5+
6+
7+
class Migration(migrations.Migration):
8+
9+
dependencies = [
10+
('contenttypes', '0002_remove_content_type_name'),
11+
('icekit', '0006_auto_20150911_0744'),
12+
]
13+
14+
operations = [
15+
migrations.CreateModel(
16+
name='Asset',
17+
fields=[
18+
('id', models.AutoField(verbose_name='ID', serialize=False, auto_created=True, primary_key=True)),
19+
('title', models.CharField(help_text='The title is shown in the "title" attribute', max_length=255, blank=True)),
20+
('caption', models.TextField(blank=True)),
21+
('admin_notes', models.TextField(help_text='Internal notes for administrators only.', blank=True)),
22+
('categories', models.ManyToManyField(related_name='assets_asset_related', to='icekit.MediaCategory', blank=True)),
23+
('polymorphic_ctype', models.ForeignKey(related_name='polymorphic_assets.asset_set+', editable=False, to='contenttypes.ContentType', null=True)),
24+
],
25+
options={
26+
'abstract': False,
27+
},
28+
),
29+
]

icekit/assets/migrations/__init__.py

Whitespace-only changes.

icekit/assets/models.py

+53
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,53 @@
1+
from __future__ import unicode_literals
2+
3+
import six
4+
from django.db import models
5+
from django.utils.translation import ugettext_lazy as _
6+
from fluent_contents.models import ContentItem
7+
from polymorphic import PolymorphicModel
8+
9+
10+
class Asset(PolymorphicModel):
11+
"""
12+
A static asset available for use on a CMS page.
13+
"""
14+
title = models.CharField(
15+
max_length=255,
16+
blank=True,
17+
help_text=_('The title is shown in the "title" attribute'),
18+
)
19+
caption = models.TextField(
20+
blank=True,
21+
)
22+
categories = models.ManyToManyField(
23+
'icekit.MediaCategory',
24+
blank=True,
25+
related_name='%(app_label)s_%(class)s_related',
26+
)
27+
admin_notes = models.TextField(
28+
blank=True,
29+
help_text=_('Internal notes for administrators only.'),
30+
)
31+
32+
def get_uses(self):
33+
return [item.parent.get_absolute_url() for item in self.assetitem_set().all()]
34+
35+
def __str__(self):
36+
return self.title
37+
38+
39+
class AssetItem(ContentItem):
40+
"""
41+
Concrete uses of an Asset.
42+
"""
43+
asset = models.ForeignKey(
44+
'icekit.assets.models.Asset',
45+
)
46+
47+
class Meta:
48+
abstract = True
49+
verbose_name = _('Asset Item')
50+
verbose_name_plural = _('Asset Items')
51+
52+
def __str__(self):
53+
return six.text_type(self.asset)

icekit/tests/settings.py

+1
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@
4343
'fluent_pages.pagetypes.fluentpage',
4444
'haystack',
4545
'icekit',
46+
'icekit.assets',
4647
'icekit.page_types.article',
4748
'icekit.page_types.layout_page',
4849
'icekit.page_types.search_page',

manage.py

100644100755
File mode changed.

0 commit comments

Comments
 (0)