-
-
Save jaymzcd/1923130 to your computer and use it in GitHub Desktop.
event plugin / django-cms
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.contrib import admin | |
from dummy.models import * | |
class EventAdmin(admin.ModelAdmin): | |
fieldsets = [ | |
(None, {'fields': ['title']}), | |
('Date information', {'fields': ['date_start', 'date_end']}), | |
] | |
admin.site.register(Event, EventAdmin) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from cms.plugin_base import CMSPluginBase | |
from cms.plugin_pool import plugin_pool | |
from cms.models.pluginmodel import CMSPlugin | |
from django.utils.translation import ugettext as _ | |
from dummy.models import EventPlugin, EventListPlugin | |
""" | |
CmsPluginEvent - Handles single events | |
""" | |
class CmsPluginEvent(CMSPluginBase): | |
model = EventPlugin | |
name = _("Display single event") | |
render_template = "event_single.html" | |
def render(self, context, instance, placeholder): | |
context.update({ | |
'event':instance.event, | |
'object':instance, | |
'placeholder':placeholder | |
}) | |
return context | |
plugin_pool.register_plugin(CmsPluginEvent) | |
""" | |
CmsPluginEventList - List of Events (e.g. to use on front-page) | |
""" | |
class CmsPluginEventList(CMSPluginBase): | |
model = EventListPlugin | |
name = _("Display event listing") | |
render_template = "event_list.html" | |
def render(self, context, instance, placeholder): | |
listing = Event.published.all()[:instance.limit] | |
context.update({ | |
'instance': instance, | |
'listing': listing, | |
'placeholder': placeholder, | |
}) | |
return context | |
plugin_pool.register_plugin(CmsPluginEventList) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
from django.db import models | |
from cms.models import CMSPlugin, Page | |
import datetime | |
from django.utils.translation import ugettext as _ | |
class Event(models.Model): | |
title = models.CharField(max_length=200) | |
date_start = models.DateTimeField('date start', default=datetime.datetime.now()) | |
date_end = models.DateTimeField('date end', default=datetime.datetime.now()) | |
# how to get this? | |
pages_using = [] | |
class Meta: | |
verbose_name = _('Event') | |
verbose_name_plural = _('Events') | |
ordering = ('-date_start', ) | |
def __unicode__(self): | |
return self.title | |
def is_today(self): | |
return self.date_start.date() == datetime.date.today() | |
class EventPlugin(CMSPlugin): | |
event = models.ForeignKey(Event) | |
def __unicode__(self): | |
return self.event.title | |
class EventListPlugin(CMSPlugin): | |
limit = models.IntegerField(default=8) | |
def __unicode__(self): | |
return self.size |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<h1>Events</h1> | |
{% for event in listing %} | |
<div class="event"> | |
<h2>{{ event.title }}</h2> | |
<ul> | |
<li> | |
<span>date start:</span><span>{{ event.date_start }}</span> | |
</li> | |
<li> | |
<span>date end:</span><span>{{ event.date_end }}</span> | |
</li> | |
</ul> | |
<h3>Page(s) showing this event</h3> | |
{% for page in event.pages_using %} | |
<ul> | |
<li> | |
url: {{ page.get_absolute_url }} | |
</li> | |
</ul> | |
</div> | |
{% empty %} | |
<div class="notice"> | |
<p> | |
No events | |
</p> | |
</div> | |
{% endfor %} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
<div class="plugin bcast evemt"> | |
<h1>{{ event.title }}</h1> | |
<ul> | |
<li> | |
<span>date start:</span><span>{{ event.date_start }}</span> | |
</li> | |
<li> | |
<span>date end:</span><span>{{ event.date_end }}</span> | |
</li> | |
</ul> | |
</div> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment