def get_form_kwargs(self, **kwargs):
'''
Get the list of recent months and recent series to pass to the form
'''
numMonths = 12
lastStart = Event.objects.annotate(Min('eventoccurrence__startTime')).order_by('-eventoccurrence__startTime__min').values_list('eventoccurrence__startTime__min',flat=True).first()
if lastStart:
month = lastStart.month
year = lastStart.year
else:
month = timezone.now().month
year = timezone.now().year
months = [('',_('None'))]
for i in range(0,numMonths):
newmonth = (month - i - 1) % 12 + 1
newyear = year
if month - i - 1 < 0:
newyear = year - 1
newdate = datetime(year=newyear,month=newmonth,day=1)
newdateStr = newdate.strftime("%m-%Y")
monthStr = newdate.strftime("%B, %Y")
months.append((newdateStr,monthStr))
cutoff = timezone.now() - timedelta(days=120)
allEvents = Event.objects.filter(startTime__gte=cutoff).order_by('-startTime')
kwargs = super(SendEmailView, self).get_form_kwargs(**kwargs)
kwargs.update({
"months": months,
"recentseries": [('','None')] + [(x.id,'%s %s: %s' % (month_name[x.month],x.year,x.name)) for x in allEvents],
"customers": self.customers,
})
return kwargs
评论列表
文章目录