def get_by_date(request, page, year, month=None, day=None): """ Gets All the Video Post by Date. URL: ^date/(?P<page>\d+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$ ^date/(?P<page>\d+)/(?P<year>\d{4})/(?P<month>\d{2})/$ ^date/(?P<page>\d+)/(?P<year>\d{4})/$ """ variables = dict() page = int(page) previous_page = page - 1 next_page = page + 1 max_results = 5 if year.isdigit(): year = int(year) else: return HttpResponse(status=400) headline = _('Showing result for %(year)s.') % {'year': year} previous_page_link = "date/%d/%d/" % (previous_page, year) next_page_link = "date/%d/%d/" % (next_page, year) videopost_list = VideoPost.objects.filter(enabled=True, locked=False) videopost_list = videopost_list.filter( publication_date__year=year).order_by('-publication_date') if month and month.isdigit(): month = int(month) month_name = get_month_name(month) videopost_list = videopost_list.filter(publication_date__month=month) previous_page_link = previous_page_link + str(month) + "/" next_page_link = next_page_link + str(month) + "/" headline = _('Showing result for: %(month)s %(year)d.') % { 'month': month_name, 'year': year } if day and day.isdigit(): day = int(day) day_name = get_day_name(day) videopost_list = videopost_list.filter(publication_date__day=day) previous_page_link = previous_page_link + str(day) + "/" next_page_link = next_page_link + str(day) + "/" headline = _('Showing result for: %(day)s %(month)s %(year)d.') % { 'day': day_name, 'month': month_name, 'year': year } if videopost_list: videoposts_paginated = paginator_simple(videopost_list, max_results, page) variables['videoposts'] = videoposts_paginated variables['headline'] = headline variables['previous-page-link'] = "%d/" % previous_page variables['next-page-link'] = "%d/" % next_page else: messages.info(request, _('No Results Found.')) t = get_template('videopost/list.html') html = t.render(RequestContext(request, variables)) return HttpResponse(html)
def get_by_date(request, page, year, month=None, day=None): """ Gets All the Video Post by Date. URL: ^date/(?P<page>\d+)/(?P<year>\d{4})/(?P<month>\d{2})/(?P<day>\d{2})/$ ^date/(?P<page>\d+)/(?P<year>\d{4})/(?P<month>\d{2})/$ ^date/(?P<page>\d+)/(?P<year>\d{4})/$ """ variables = dict() page = int(page) previous_page = page - 1 next_page = page + 1 max_results = 5 if year.isdigit(): year = int(year) else: return HttpResponse(status=400) headline = _('Showing result for %(year)s.') % {'year': year} previous_page_link = "date/%d/%d/" % (previous_page, year) next_page_link = "date/%d/%d/" % (next_page, year) videopost_list = VideoPost.objects.filter(enabled=True, locked=False) videopost_list = videopost_list.filter(publication_date__year=year).order_by('-publication_date') if month and month.isdigit(): month = int(month) month_name = get_month_name(month) videopost_list = videopost_list.filter(publication_date__month=month) previous_page_link = previous_page_link + str(month) + "/" next_page_link = next_page_link + str(month) + "/" headline = _('Showing result for: %(month)s %(year)d.') % {'month': month_name, 'year': year} if day and day.isdigit(): day = int(day) day_name = get_day_name(day) videopost_list = videopost_list.filter(publication_date__day=day) previous_page_link = previous_page_link + str(day) + "/" next_page_link = next_page_link + str(day) + "/" headline = _('Showing result for: %(day)s %(month)s %(year)d.') % {'day': day_name, 'month': month_name, 'year': year} if videopost_list: videoposts_paginated = paginator_simple(videopost_list, max_results, page) variables['videoposts'] = videoposts_paginated variables['headline'] = headline variables['previous-page-link'] = "%d/" % previous_page variables['next-page-link'] = "%d/" % next_page else: messages.info(request, _('No Results Found.')) t = get_template('videopost/list.html') html = t.render(RequestContext(request, variables)) return HttpResponse(html)
def generate_date_menu(): cursor = connection.cursor() cursor.execute( 'SELECT COUNT(*) AS total, MONTH(publication_date) AS month, YEAR(publication_date) AS year FROM videopost_videopost v WHERE locked = 0 AND enabled = 1 GROUP BY YEAR(publication_date), MONTH(publication_date) ORDER BY year DESC, month' ) line = "<div class='sidebar-module'>" line += "<p id='date-sidebar-title' class='sidebar-module-title'>" + _( "Archive") + "</p>" line += "<div>" iteration_year = None for row in cursor.fetchall(): total = row[0] month_number = row[1] year_number = row[2] month_name = get_month_name(month_number) if iteration_year != year_number: if iteration_year != None: line += "</div>" line += "<h3 class='date-sidebar-year date-sidebar-year-collapsed'><a href='#'/>" line += str(year_number) line += "</a></h3>" line += "<div class='month-date-sidebar'>" iteration_year = year_number line += "<p class='date-sidebar-month'><a href='%sdate/1/%d/%d/'>" % ( settings.APP_PATH, year_number, month_number) line += "%s (%d)" % (month_name, total) line += "</a></p>" line += "</div>" line += "</div>" line += "</div>" line = line.encode("utf-8") try: gendir = '%s/date_menu.inc' % settings.GENERATOR_DIR f = open(gendir, "w") try: f.write(line) finally: f.close() except IOError: pass
def generate_date_menu(): cursor = connection.cursor() cursor.execute('SELECT COUNT(*) AS total, MONTH(publication_date) AS month, YEAR(publication_date) AS year FROM videopost_videopost v WHERE locked = 0 AND enabled = 1 GROUP BY YEAR(publication_date), MONTH(publication_date) ORDER BY year DESC, month') line = "<div class='sidebar-module'>" line += "<p id='date-sidebar-title' class='sidebar-module-title'>" + _("Archive") + "</p>" line += "<div>" iteration_year = None for row in cursor.fetchall(): total = row[0] month_number = row[1] year_number = row[2] month_name = get_month_name(month_number) if iteration_year != year_number: if iteration_year != None: line += "</div>" line += "<h3 class='date-sidebar-year date-sidebar-year-collapsed'><a href='#'/>" line += str(year_number) line += "</a></h3>" line += "<div class='month-date-sidebar'>" iteration_year = year_number line += "<p class='date-sidebar-month'><a href='%sdate/1/%d/%d/'>" % (settings.APP_PATH, year_number, month_number) line += "%s (%d)" % (month_name, total) line += "</a></p>" line += "</div>" line += "</div>" line += "</div>" line = line.encode("utf-8") try: gendir = '%s/date_menu.inc' % settings.GENERATOR_DIR f = open(gendir, "w") try: f.write(line) finally: f.close() except IOError: pass