def get_calendar_entries(context, year=None, month=None, template='zinnia/tags/calendar.html'): """Return an HTML calendar of entries""" if not year or not month: date_month = context.get('month') or context.get('day') or \ getattr(context.get('object'), 'creation_date', None) or \ datetime.today() year, month = date_month.timetuple()[:2] calendar = ZinniaCalendar() current_month = datetime(year, month, 1) dates = list(Entry.published.dates('creation_date', 'month')) if not current_month in dates: dates.append(current_month) dates.sort() index = dates.index(current_month) previous_month = index > 0 and dates[index - 1] or None next_month = index != len(dates) - 1 and dates[index + 1] or None return {'template': template, 'next_month': next_month, 'previous_month': previous_month, 'calendar': calendar.formatmonth(year, month)}
def get_calendar_entries(context, year=None, month=None, template='zinnia/tags/calendar.html'): """Return an HTML calendar of entries""" if not year or not month: date_month = context.get('month') or context.get('day') or datetime.today() year, month = date_month.timetuple()[:2] try: from zinnia.templatetags.zcalendar import ZinniaCalendar except ImportError: return {'calendar': '<p class="notice">Calendar is unavailable for Python<2.5.</p>'} calendar = ZinniaCalendar(firstweekday=FIRST_WEEK_DAY) current_month = datetime(year, month, 1) dates = list(Entry.published.dates('creation_date', 'month')) if current_month in dates: index = dates.index(current_month) previous_month = dates[index - 1] try: next_month = dates[index + 1] except IndexError: next_month = None else: previous_month = len(dates) and dates[-1] or None next_month = None return {'template': template, 'next_month': next_month, 'previous_month': previous_month, 'calendar': calendar.formatmonth(year, month)}
def get_calendar_entries(context, year=None, month=None, template='zinnia/tags/calendar.html'): """Return an HTML calendar of entries""" if not year or not month: date_month = context.get('month') or context.get('day') or \ getattr(context.get('object'), 'creation_date', None) or \ datetime.today() year, month = date_month.timetuple()[:2] try: from zinnia.templatetags.zcalendar import ZinniaCalendar except ImportError: return {'calendar': '<p class="notice">Calendar is unavailable for Python<2.5.</p>'} calendar = ZinniaCalendar() current_month = datetime(year, month, 1) dates = list(Entry.published.dates('creation_date', 'month')) if not current_month in dates: dates.append(current_month) dates.sort() index = dates.index(current_month) previous_month = index > 0 and dates[index - 1] or None next_month = index != len(dates) - 1 and dates[index + 1] or None return {'template': template, 'next_month': next_month, 'previous_month': previous_month, 'calendar': calendar.formatmonth(year, month)}
def get_calendar_entries(context, year=None, month=None, template='zinnia/tags/calendar.html'): """Return an HTML calendar of entries""" if not year or not month: date_month = context.get('month') or context.get('day') or \ getattr(context.get('object'), 'creation_date', None) or \ timezone.now().date() year, month = date_month.timetuple()[:2] calendar = ZinniaCalendar() current_month = datetime(year, month, 1) if settings.USE_TZ: current_month = timezone.make_aware( current_month, timezone.utc) dates = list(Entry.published.dates('creation_date', 'month')) if not current_month in dates: dates.append(current_month) dates.sort() index = dates.index(current_month) previous_month = index > 0 and dates[index - 1] or None next_month = index != len(dates) - 1 and dates[index + 1] or None return {'template': template, 'next_month': next_month, 'previous_month': previous_month, 'calendar': calendar.formatmonth( year, month, previous_month=previous_month, next_month=next_month)}
def get_calendar_entries(context, year=None, month=None, template="zinnia/tags/calendar.html"): """Return an HTML calendar of entries""" if not year or not month: date_month = ( context.get("month") or context.get("day") or getattr(context.get("object"), "creation_date", None) or timezone.now().date() ) year, month = date_month.timetuple()[:2] calendar = ZinniaCalendar() current_month = datetime(year, month, 1) if settings.USE_TZ: current_month = timezone.make_aware(current_month, timezone.utc) dates = list(Entry.published.dates("creation_date", "month")) if not current_month in dates: dates.append(current_month) dates.sort() index = dates.index(current_month) previous_month = index > 0 and dates[index - 1] or None next_month = index != len(dates) - 1 and dates[index + 1] or None return { "template": template, "next_month": next_month, "previous_month": previous_month, "calendar": calendar.formatmonth(year, month, previous_month=previous_month, next_month=next_month), }
def get_calendar_entries(context, year=None, month=None, template="zinnia/tags/calendar.html"): """Return an HTML calendar of entries""" if not year or not month: date_month = ( context.get("month") or context.get("day") or getattr(context.get("object"), "creation_date", None) or datetime.today() ) year, month = date_month.timetuple()[:2] try: from zinnia.templatetags.zcalendar import ZinniaCalendar except ImportError: return {"calendar": '<p class="notice">Calendar is unavailable for Python<2.5.</p>'} calendar = ZinniaCalendar() current_month = datetime(year, month, 1) dates = list(Entry.published.dates("creation_date", "month")) if not current_month in dates: dates.append(current_month) dates.sort() index = dates.index(current_month) previous_month = index > 0 and dates[index - 1] or None next_month = index != len(dates) - 1 and dates[index + 1] or None return { "template": template, "next_month": next_month, "previous_month": previous_month, "calendar": calendar.formatmonth(year, month), }
def get_calendar_entries(context, year=None, month=None, template='zinnia/tags/calendar.html'): """Return an HTML calendar of entries""" if not year or not month: date_month = context.get('month') or context.get('day') or datetime.today() year, month = date_month.timetuple()[:2] blog = context.get('blog') try: from zinnia.templatetags.zcalendar import ZinniaCalendar except ImportError: return {'calendar': '<p class="notice">Calendar is unavailable for Python<2.5.</p>'} calendar = ZinniaCalendar() current_month = datetime(year, month, 1) filter = {} blog_slug = None if blog: blog_slug = blog.slug filter = {'blog__slug': blog_slug} dates = list(Entry.published.dates('creation_date', 'month').filter(**filter).distinct()) next_month = previous_month = None if current_month in dates: index = dates.index(current_month) if index > 0: previous_month = dates[index - 1] if index < len(dates) - 1: next_month = dates[index + 1] elif len(dates): for date in dates: if date < current_month: previous_month = date elif current_month < date: next_month = date break out = { 'template': template, 'next_month': next_month, 'previous_month': previous_month, 'calendar': calendar.formatmonth(year, month, blog_slug = blog_slug), 'ZINNIA_BLOG_ACTIVE': ZINNIA_BLOG_ACTIVE, } if blog: out.update({'blog': blog}) return out
def get_calendar_entries(context, year=None, month=None, template='zinnia/tags/calendar.html'): """Return an HTML calendar of entries""" if not year or not month: date_month = context.get('month') or context.get('day') or \ getattr(context.get('object'), 'creation_date', None) or \ timezone.now().date() year, month = date_month.timetuple()[:2] calendar = ZinniaCalendar() current_month = datetime(year, month, 1) if settings.USE_TZ: current_month = timezone.make_aware( current_month, timezone.utc) #Note: I need to make the results of the datetimes access #distinct. ".dates" does this, but datetimes does not. (All it does #is "truncate" them to the kind without guaranteeing uniqueness.) if hasattr(Entry.published, "datetimes"): dates = list(Entry.published.datetimes('creation_date', 'month', tzinfo=timezone.utc)) else: dates = list(Entry.published.dates('creation_date', 'month')) if current_month not in dates: dates.append(current_month) dates.sort() index = dates.index(current_month) previous_month = index > 0 and dates[index - 1] or None next_month = index != len(dates) - 1 and dates[index + 1] or None return {'template': template, 'next_month': next_month, 'previous_month': previous_month, 'calendar': calendar.formatmonth( year, month, previous_month=previous_month, next_month=next_month)}