Another Step in the Quest to clean up the code base.

This commit is contained in:
2017-09-08 07:19:50 +02:00
parent ce218080b2
commit b3ab9798b5
229 changed files with 1915 additions and 15175 deletions

43
src/events/mixins.py Normal file
View File

@@ -0,0 +1,43 @@
"""Mixins for Events."""
from . import models
# Ignore PyLintBear (R0903)
class EventArchiveMixin(object):
"""Adds an is_archive = True variable to the template context."""
context_object_name = 'event_list'
date_field = 'start'
make_object_list = True
model = models.Event
ordering = ('start', 'end')
paginate_by = 15
template_name = 'events/event_archive.html'
def get_context_data(self, **kwargs):
"""Add is_archive to the context and set it to true.
:return: TemplateContext object"""
context = super(EventArchiveMixin, self).get_context_data(**kwargs)
context['is_archive'] = True
return context
# Ignore PyLintBear (R0903)
class EventDetailMixin(object):
"""A very simple Mixin to add the related event to the template context."""
event = None
def get_context_data(self, **kwargs):
"""Add self.event or the related event of self.object to the template
context.
:return: TemplateContext object"""
context = super(EventDetailMixin, self).get_context_data(**kwargs)
if hasattr(self, 'event') and self.event:
context['event'] = self.event
elif hasattr(self, 'object') and isinstance(self.object, models.Event):
context['event'] = self.object
elif hasattr(self, 'object') and hasattr(self.object, 'event'):
context['event'] = self.object.event
print(context)
return context