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

Commit

Permalink
First attempt at abstracting assets.
Browse files Browse the repository at this point in the history
RE #39
  • Loading branch information
rstuart85 committed Oct 11, 2016
1 parent 32d04f3 commit 990e129
Show file tree
Hide file tree
Showing 6 changed files with 92 additions and 0 deletions.
1 change: 1 addition & 0 deletions icekit/assets/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = '%s.apps.AppConfig' % __name__
8 changes: 8 additions & 0 deletions icekit/assets/apps.py
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

29 changes: 29 additions & 0 deletions icekit/assets/migrations/0001_initial.py
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.
53 changes: 53 additions & 0 deletions icekit/assets/models.py
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)
1 change: 1 addition & 0 deletions icekit/tests/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@
'haystack',
'icekit',
'icekit.articles',
'icekit.assets',
'icekit.page_types.layout_page',
'icekit.page_types.search_page',
'icekit.pages_api',
Expand Down

0 comments on commit 990e129

Please sign in to comment.