diff --git a/icekit_events/plugins/event_content_listing/__init__.py b/icekit_events/plugins/event_content_listing/__init__.py new file mode 100644 index 0000000..dd48ee4 --- /dev/null +++ b/icekit_events/plugins/event_content_listing/__init__.py @@ -0,0 +1 @@ +default_app_config = '%s.apps.AppConfig' % __name__ diff --git a/icekit_events/plugins/event_content_listing/abstract_models.py b/icekit_events/plugins/event_content_listing/abstract_models.py new file mode 100644 index 0000000..4c73306 --- /dev/null +++ b/icekit_events/plugins/event_content_listing/abstract_models.py @@ -0,0 +1,22 @@ +from django.utils.encoding import python_2_unicode_compatible +from django.utils.translation import ugettext_lazy as _ + +from icekit.plugins.content_listing.abstract_models import \ + AbstractContentListingItem + + +@python_2_unicode_compatible +class AbstractEventContentListingItem(AbstractContentListingItem): + """ + An embedded listing of event content items. + """ + + class Meta: + abstract = True + verbose_name = _('Event Content Listing') + + def __str__(self): + return 'Event Content Listing of %s' % self.content_type + + def get_items(self): + return super(AbstractEventContentListingItem, self).get_items() diff --git a/icekit_events/plugins/event_content_listing/apps.py b/icekit_events/plugins/event_content_listing/apps.py new file mode 100644 index 0000000..4853fda --- /dev/null +++ b/icekit_events/plugins/event_content_listing/apps.py @@ -0,0 +1,7 @@ +from django.apps import AppConfig + + +class AppConfig(AppConfig): + name = '.'.join(__name__.split('.')[:-1]) + label = "ik_event_listing" + verbose_name = "Event Content Listing" diff --git a/icekit_events/plugins/event_content_listing/content_plugins.py b/icekit_events/plugins/event_content_listing/content_plugins.py new file mode 100644 index 0000000..b78d122 --- /dev/null +++ b/icekit_events/plugins/event_content_listing/content_plugins.py @@ -0,0 +1,17 @@ +""" +Definition of the plugin. +""" +from django.utils.translation import ugettext_lazy as _ + +from fluent_contents.extensions import ContentPlugin, plugin_pool + +from . import forms, models + + +@plugin_pool.register +class EventContentListingPlugin(ContentPlugin): + model = models.EventContentListingItem + category = _('Assets') + render_template = 'icekit_events/plugins/event_content_listing/default.html' + form = forms.EventContentListingAdminForm + cache_output = False diff --git a/icekit_events/plugins/event_content_listing/forms.py b/icekit_events/plugins/event_content_listing/forms.py new file mode 100644 index 0000000..628bb4d --- /dev/null +++ b/icekit_events/plugins/event_content_listing/forms.py @@ -0,0 +1,21 @@ +from icekit.plugins.content_listing.forms import ContentListingAdminForm + +from icekit_events.models import EventBase + +from .models import EventContentListingItem + + +class EventContentListingAdminForm(ContentListingAdminForm): + + class Meta: + model = EventContentListingItem + fields = '__all__' + + def filter_content_types(self, content_type_qs): + """ Filter the content types selectable to only event subclasses """ + valid_ct_ids = [] + for ct in content_type_qs: + model = ct.model_class() + if model and issubclass(model, EventBase): + valid_ct_ids.append(ct.id) + return content_type_qs.filter(pk__in=valid_ct_ids) diff --git a/icekit_events/plugins/event_content_listing/migrations/0001_initial.py b/icekit_events/plugins/event_content_listing/migrations/0001_initial.py new file mode 100644 index 0000000..5eca7b0 --- /dev/null +++ b/icekit_events/plugins/event_content_listing/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 = [ + ('fluent_contents', '0001_initial'), + ('contenttypes', '0002_remove_content_type_name'), + ] + + operations = [ + migrations.CreateModel( + name='EventContentListingItem', + fields=[ + ('contentitem_ptr', models.OneToOneField(serialize=False, primary_key=True, to='fluent_contents.ContentItem', parent_link=True, auto_created=True)), + ('limit', models.IntegerField(null=True, help_text=b'How many items to show? No limit is applied if this field is not set', blank=True)), + ('content_type', models.ForeignKey(help_text=b'Content type of items to show in a listing', to='contenttypes.ContentType')), + ], + options={ + 'db_table': 'contentitem_ik_event_listing_eventcontentlistingitem', + 'abstract': False, + 'verbose_name': 'Event Content Listing', + }, + bases=('fluent_contents.contentitem',), + ), + ] diff --git a/icekit_events/plugins/event_content_listing/migrations/__init__.py b/icekit_events/plugins/event_content_listing/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/icekit_events/plugins/event_content_listing/models.py b/icekit_events/plugins/event_content_listing/models.py new file mode 100644 index 0000000..813a35d --- /dev/null +++ b/icekit_events/plugins/event_content_listing/models.py @@ -0,0 +1,8 @@ +from .abstract_models import AbstractEventContentListingItem + + +class EventContentListingItem(AbstractEventContentListingItem): + """ + An embedded listing of event content items. + """ + pass diff --git a/icekit_events/plugins/event_content_listing/templates/icekit_events/plugins/event_content_listing/_event.html b/icekit_events/plugins/event_content_listing/templates/icekit_events/plugins/event_content_listing/_event.html new file mode 100644 index 0000000..7e07654 --- /dev/null +++ b/icekit_events/plugins/event_content_listing/templates/icekit_events/plugins/event_content_listing/_event.html @@ -0,0 +1,4 @@ +
  • + {{ event.title|safe }} +
  • + diff --git a/icekit_events/plugins/event_content_listing/templates/icekit_events/plugins/event_content_listing/default.html b/icekit_events/plugins/event_content_listing/templates/icekit_events/plugins/event_content_listing/default.html new file mode 100644 index 0000000..055e5cb --- /dev/null +++ b/icekit_events/plugins/event_content_listing/templates/icekit_events/plugins/event_content_listing/default.html @@ -0,0 +1,9 @@ +
    + {% for event in instance.get_items %} + {% include "icekit_events/plugins/event_content_listing/_event.html" %} + {% empty %} +
  • There are no items to show on this page
  • + {{ instance.get_default_embed }} + {% endfor %} +
    +