Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
def get_previous_event_time(self):
"""Determines the previous event time"""
if not self._previous:
try:
qs = EventTime.objects.all().exclude(id__exact=self.id)
event_time= qs.filter(start__lte=self.start).order_by('-start')[0]
except (EventTime.DoesNotExist, IndexError):
event_time = None
self._previous = event_time
return self._previous
class RelatedEvent(models.Model):
eventtime = models.ForeignKey(EventTime)
content_type = models.ForeignKey(ContentType)
object_id = models.PositiveIntegerField()
content_object = generic.GenericForeignKey('content_type', 'object_id')
def __unicode__(self):
return self.eventtime.event.__unicode__()
def render(self, context):
if self.calendar_slug == 'all':
events = EventTime.upcoming_objects.all().order_by('start')
else:
events = EventTime.upcoming_objects.filter(event__calendar__slug=self.calendar_slug).order_by('start')
if self.excluded_cals:
for cal_slug in self.excluded_cals:
events = events.exclude(event__calendar__slug=cal_slug)
logging.debug('Fetching %s events from calendar %s excluding %s.' % (self.limit, self.calendar_slug, self.excluded_cals))
if self.limit == 1:
try:
context[self.varname] = events[0]
except:
context[self.varname] = None
else:
try:
context[self.varname] = events[:self.limit]
def get_next_event_time(self):
"""Determines the next event time"""
if not self._next:
try:
qs = EventTime.objects.filter(event=self.event).exclude(id__exact=self.id)
event_time= qs.filter(start__gte=self.start).order_by('start')[0]
except (EventTime.DoesNotExist, IndexError):
event_time = None
self._next = event_time
return self._next
def render(self, context):
if self.calendar_slug == 'all':
events = EventTime.upcoming_objects.all().order_by('start')
else:
events = EventTime.upcoming_objects.filter(event__calendar__slug=self.calendar_slug).order_by('start')
if self.excluded_cals:
for cal_slug in self.excluded_cals:
events = events.exclude(event__calendar__slug=cal_slug)
logging.debug('Fetching %s events from calendar %s excluding %s.' % (self.limit, self.calendar_slug, self.excluded_cals))
if self.limit == 1:
try:
context[self.varname] = events[0]
except:
context[self.varname] = None
else:
try:
context[self.varname] = events[:self.limit]
except:
context[self.varname] = None
def save(self, *args, **kwargs):
if not self.slug:
self.slug = self.event.slug
if self.place and not self.place_string:
self.place_string = self.place.__unicode__()
super(EventTime, self).save(*args, **kwargs)
@property
def full_name(self):
return u'%s %s' % (self.first_name, self.last_name)
@property
def on_board(self):
for t in self.term_set.all():
if t.group.order == 10:
return True
@models.permalink
def get_absolute_url(self):
return ('cm-person-detail', None, {'slug': self.slug})
class Meeting(MarkupMixin, TimeStampedModel, EventTime):
'''
Meeting model.
A general meeting model.
'''
group = models.ForeignKey(Group)
agenda = models.TextField(_('Agenda'), blank=True, null=True)
rendered_agenda = models.TextField(_('Rendered agenda'), blank=True, null=True)
business_arising=models.TextField(_('Business arising'), blank=True, null=True)
def __init__(self, *args, **kwargs):
super (Meeting, self).__init__(*args, **kwargs)
self._next = None
self._previous = None
class Meta:
def get_previous_event_time(self):
"""Determines the previous event time"""
if not self._previous:
try:
qs = EventTime.objects.all().exclude(id__exact=self.id)
event_time= qs.filter(start__lte=self.start).order_by('-start')[0]
except (EventTime.DoesNotExist, IndexError):
event_time = None
self._previous = event_time
return self._previous
def get_queryset(self):
try:
if self.kwargs['cal_slug']:
return EventTime.upcoming_objects.filter(event__calendar__slug=self.kwargs['cal_slug'])
except:
pass
try:
if self.kwargs['slug']:
return EventTime.upcoming_objects.filter(event__slug=self.kwargs['slug'])
except:
logging.debug('Returning all upcoming events...')
return EventTime.upcoming_objects.all()
cal_slug = self.kwargs['cal_slug']
self.calendar = get_object_or_404(Calendar, slug=cal_slug)
except:
self.calendar = None
return EventTime.upcoming_objects.all()
def get_context_data(self, **kwargs):
context = super(EventListView, self).get_context_data(**kwargs)
context['month'] = EventCalendar(self.get_queryset()).formatmonth(datetime.now().year, datetime.now().month)
if self.calendar:
context['calendar'] = self.calendar
return context
class EventDetailView(DateDetailView):
context_object_name = "event"
queryset=EventTime.upcoming_objects.all()
allow_future = True
date_field = 'start'
class EventYearView(YearArchiveView):
context_object_name = "event_list"
allow_future = True
date_field = 'start'
allow_empty = True
def get_queryset(self):
try:
if self.kwargs['cal_slug']:
return EventTime.upcoming_objects.filter(event__calendar__slug=self.kwargs['cal_slug'])
except:
pass
def get_queryset(self):
try:
cal_slug = self.kwargs['cal_slug']
self.calendar = get_object_or_404(Calendar, slug=cal_slug)
except:
self.calendar = None
return EventTime.upcoming_objects.all()