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

Commit

Permalink
Initial implementation of content listing plugin for Events
Browse files Browse the repository at this point in the history
New `EventContentListingPlugin` to list events in page content, based
on the new `ContentListingPlugin` feature from ICEkit.
  • Loading branch information
jmurty committed Feb 21, 2017
1 parent 4b8ab97 commit 9e11ffa
Show file tree
Hide file tree
Showing 10 changed files with 118 additions and 0 deletions.
1 change: 1 addition & 0 deletions icekit_events/plugins/event_content_listing/__init__.py
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
default_app_config = '%s.apps.AppConfig' % __name__
22 changes: 22 additions & 0 deletions icekit_events/plugins/event_content_listing/abstract_models.py
Original file line number Diff line number Diff line change
@@ -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()
7 changes: 7 additions & 0 deletions icekit_events/plugins/event_content_listing/apps.py
Original file line number Diff line number Diff line change
@@ -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"
17 changes: 17 additions & 0 deletions icekit_events/plugins/event_content_listing/content_plugins.py
Original file line number Diff line number Diff line change
@@ -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
21 changes: 21 additions & 0 deletions icekit_events/plugins/event_content_listing/forms.py
Original file line number Diff line number Diff line change
@@ -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)
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 = [
('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',),
),
]
Empty file.
8 changes: 8 additions & 0 deletions icekit_events/plugins/event_content_listing/models.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,8 @@
from .abstract_models import AbstractEventContentListingItem


class EventContentListingItem(AbstractEventContentListingItem):
"""
An embedded listing of event content items.
"""
pass
Original file line number Diff line number Diff line change
@@ -0,0 +1,4 @@
<li><a href="{{ event.get_absolute_url }}">
{{ event.title|safe }}
</a></li>

Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
<div class="content-listing">
{% for event in instance.get_items %}
{% include "icekit_events/plugins/event_content_listing/_event.html" %}
{% empty %}
<li>There are no items to show on this page</li>
{{ instance.get_default_embed }}
{% endfor %}
</div>

0 comments on commit 9e11ffa

Please sign in to comment.