def issues_list(request, year=None, month=None): issues = filter_by_date(Issue.objects.all(), year, month, field='date') data = {'issues': issues, 'year': year, 'month': month} rc = RequestContext(request) return render_to_response("issue/issues_list.html", data, context_instance=rc)
def archives(request, section=None, subsection=None, year=None, month=None, day=None): articles = filter_by_date(Article.published, year, month, day) if section: section = get_object_or_404(Section, slug=section) articles = articles.filter(section=section) if subsection: subsection = get_object_or_404(Subsection, section=section, slug=subsection) articles = articles.filter(section=section, subsection=subsection) articles = articles.order_by('pub_date') data = { 'articles': articles, 'year': year, 'month': month, 'day': day, 'section': section, 'subsection': subsection, 'poster': Poster.published.get_running(), 'sections': Section.objects.all() } if day: template = 'archives/by_day.html' elif month: template = 'archives/by_month.html' else: pub_dates = articles.values_list('pub_date', flat=True) dates = set([datetime.date(d.year, d.month, d.day) for d in pub_dates]) if not dates: # screw reverse, this place is brittle url = '/archives/' if section: url += section.slug + '/' if subsection: url += subsection.slug + '/' if year: url += year + '/' split = url.split('/') if len(split) > 3: return HttpResponseRedirect('/'.join(split[:-2] + [''])) else: # no articles at all? really? raise Http404 if year: start_date = datetime.date(int(year), 1, 1) end_date = datetime.date(int(year), 12, 31) else: start_date = min(dates) end_date = max(dates) calendar.setfirstweekday(calendar.SUNDAY) year_i, month_i = (end_date.year, end_date.month) cal = [ (year_i, month_i, calendar.monthcalendar(year_i, month_i)) ] while year_i > start_date.year or month_i > start_date.month: month_i -= 1 if month_i < 1: month_i = 12 year_i -= 1 cal.append( (year_i, month_i, calendar.monthcalendar(year_i, month_i)) ) weekdays = range(7) for year_i, month_i, month_cal in cal: for week in month_cal: for i in weekdays: if week[i] and datetime.date(year_i, month_i, week[i]) not in dates: week[i] *= -1 data['calendar'] = cal data['url_base'] = '/archives' if section: data['url_base'] += '/' + section.slug if subsection: data['url_base'] += '/' + subsection.slug template = 'archives/generic.html' rc = RequestContext(request, data) return render_to_response(template, context_instance=rc)
def archives(request, section=None, subsection=None, year=None, month=None, day=None): articles = filter_by_date(Article.published, year, month, day) if section: section = get_object_or_404(Section, slug=section) articles = articles.filter(section=section) if subsection: subsection = get_object_or_404(Subsection, section=section, slug=subsection) articles = articles.filter(section=section, subsection=subsection) articles = articles.order_by('pub_date') data = { 'articles': articles, 'year': year, 'month': month, 'day': day, 'section': section, 'subsection': subsection, 'poster': Poster.published.get_running(), 'sections': Section.objects.all() } if day: template = 'archives/by_day.html' elif month: template = 'archives/by_month.html' else: pub_dates = articles.values_list('pub_date', flat=True) dates = set([datetime.date(d.year, d.month, d.day) for d in pub_dates]) if not dates: # screw reverse, this place is brittle url = '/archives/' if section: url += section.slug + '/' if subsection: url += subsection.slug + '/' if year: url += year + '/' split = url.split('/') if len(split) > 3: return HttpResponseRedirect('/'.join(split[:-2] + [''])) else: # no articles at all? really? raise Http404 if year: start_date = datetime.date(int(year), 1, 1) end_date = datetime.date(int(year), 12, 31) else: start_date = min(dates) end_date = max(dates) calendar.setfirstweekday(calendar.SUNDAY) year_i, month_i = (end_date.year, end_date.month) cal = [(year_i, month_i, calendar.monthcalendar(year_i, month_i))] while year_i > start_date.year or month_i > start_date.month: month_i -= 1 if month_i < 1: month_i = 12 year_i -= 1 cal.append( (year_i, month_i, calendar.monthcalendar(year_i, month_i))) weekdays = range(7) for year_i, month_i, month_cal in cal: for week in month_cal: for i in weekdays: if week[i] and datetime.date(year_i, month_i, week[i]) not in dates: week[i] *= -1 data['calendar'] = cal data['url_base'] = '/archives' if section: data['url_base'] += '/' + section.slug if subsection: data['url_base'] += '/' + subsection.slug template = 'archives/generic.html' rc = RequestContext(request, data) return render_to_response(template, context_instance=rc)
def issues_list(request, year=None, month=None): issues = filter_by_date(Issue.objects.all(), year, month, field="date") data = {"issues": issues, "year": year, "month": month} rc = RequestContext(request) return render_to_response("issue/issues_list.html", data, context_instance=rc)