- from django.shortcuts import render
- from django.http import HttpResponse
- from tendenci.apps.pages.models import Page
- from tendenci.apps.categories.models import Category
- from tendenci.apps.categories.models import CategoryItem
- categories_list = Category.objects.order_by('name')
- temp_list = CategoryItem.objects.filter(category__in=categories_list).order_by('category')
- big_list = [ 0 for x in range(len(categories_list))]
- for x in range(len(temp_list)):
- for y in range(len(categories_list)):
- if str(temp_list[x].category) == str(categories_list[y].name): tempIndex = y
- else: tempIndex = -1
- if tempIndex > -1: big_list[tempIndex] = big_list[tempIndex] + 1
- counter = 0
- category_dict = {}
- for category in categories_list:
- category_dict[category.name] = big_list[counter]
- print category_dict[category.name]
- counter = counter + 1
- print category_dict
- month_list = Page.objects.dates('create_dt','month')
- year_list = Page.objects.dates('create_dt','year')
- def index(request,year='',month='',day=''):
- if day != '': pages_list = Page.objects.filter(create_dt__day=day,create_dt__month=month,create_dt__year=year).order_by('-create_dt')
- elif month != '': pages_list = Page.objects.filter(create_dt__month=month, create_dt__year=year).order_by('-create_dt')
- elif year != '': pages_list = Page.objects.filter(create_dt__year=year).order_by('-create_dt')
- else: pages_list = Page.objects.order_by('-create_dt')
- return render(request,'blog/index.html',{'category_dict':category_dict, 'year_list':year_list,'month_list':month_list,'categories_list':categories_list,'pages_list':pages_list,'view':'index'})