spacepaste

  1.  
  2. from django.shortcuts import render
  3. from django.http import HttpResponse
  4. from tendenci.apps.pages.models import Page
  5. from tendenci.apps.categories.models import Category
  6. from tendenci.apps.categories.models import CategoryItem
  7. categories_list = Category.objects.order_by('name')
  8. temp_list = CategoryItem.objects.filter(category__in=categories_list).order_by('category')
  9. big_list = [ 0 for x in range(len(categories_list))]
  10. for x in range(len(temp_list)):
  11. for y in range(len(categories_list)):
  12. if str(temp_list[x].category) == str(categories_list[y].name): tempIndex = y
  13. else: tempIndex = -1
  14. if tempIndex > -1: big_list[tempIndex] = big_list[tempIndex] + 1
  15. counter = 0
  16. category_dict = {}
  17. for category in categories_list:
  18. category_dict[category.name] = big_list[counter]
  19. print category_dict[category.name]
  20. counter = counter + 1
  21. print category_dict
  22. month_list = Page.objects.dates('create_dt','month')
  23. year_list = Page.objects.dates('create_dt','year')
  24. def index(request,year='',month='',day=''):
  25. if day != '': pages_list = Page.objects.filter(create_dt__day=day,create_dt__month=month,create_dt__year=year).order_by('-create_dt')
  26. elif month != '': pages_list = Page.objects.filter(create_dt__month=month, create_dt__year=year).order_by('-create_dt')
  27. elif year != '': pages_list = Page.objects.filter(create_dt__year=year).order_by('-create_dt')
  28. else: pages_list = Page.objects.order_by('-create_dt')
  29. 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'})
  30.