Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
self.field_generic = '%s__' % self.field_path
self.date_params = dict([(k, v) for k, v in params.items() if k.startswith(self.field_generic)])
today = jdatetime.date.today()
one_week_ago = today - jdatetime.timedelta(days=7)
# today_str = isinstance(self.field, jmodels.DateTimeField) \
# and today.strftime('%Y-%m-%d 23:59:59') \
# or today.strftime('%Y-%m-%d')
today_str = today.strftime('%Y-%m-%d')
last_day_this_month = 29
if today.month == 12 and today.isleap():
last_day_this_month = 30
else:
last_day_this_month = jdatetime.j_days_in_month[today.month-1]
last_day_this_year = 29
if today.isleap():
last_day_this_year = 30
self.links = (
(_('Any date'), {}),
(_('Today'), {'%s' % self.field_path: today.strftime('%Y-%m-%d')}),
(_('Past 7 days'), {
'%s__gte' % self.field_path: one_week_ago.strftime('%Y-%m-%d'),
'%s__lte' % self.field_path: today_str
}),
(_('This month'), {
'%s__gte' % self.field_path: today.replace(day=1).strftime('%Y-%m-%d'),
'%s__lte' % self.field_path: today.replace(day=last_day_this_month).strftime('%Y-%m-%d'),
}),