cms.models.query: 48 total statements, 0.0% covered

Generated: Wed 2013-03-13 10:33 CET

Source file: /media/Envs/Envs/filer-gallery/lib/python2.7/site-packages/cms/models/query.py

Stats: 0 executed, 40 missed, 8 excluded, 52 ignored

  1. # -*- coding: utf-8 -*-
  2. from datetime import datetime
  3. from django.db.models import Q
  4. from django.contrib.sites.models import Site
  5. from cms.publisher.query import PublisherQuerySet
  6. from django.conf import settings
  7. from cms.exceptions import NoHomeFound
  8. from cms.utils import timezone
  9. #from cms.utils.urlutils import levelize_path
  10. class PageQuerySet(PublisherQuerySet):
  11. def on_site(self, site=None):
  12. if not site:
  13. try:
  14. site = Site.objects.get_current()
  15. except Site.DoesNotExist:
  16. site = None
  17. return self.filter(site=site)
  18. def root(self):
  19. """
  20. Return a queryset with pages that don't have parents, a.k.a. root. For
  21. current site - used in frontend
  22. """
  23. return self.on_site().filter(parent__isnull=True)
  24. def all_root(self):
  25. """
  26. Return a queryset with pages that don't have parents, a.k.a. root. For
  27. all sites - used in frontend
  28. """
  29. return self.filter(parent__isnull=True)
  30. def valid_targets(self, page_id, request, perms, page=None):
  31. """
  32. Give valid targets to move a page into the tree
  33. """
  34. if page is None:
  35. page = self.get(pk=page_id)
  36. exclude_list = []
  37. if page:
  38. exclude_list.append(page.id)
  39. for p in page.get_descendants():
  40. exclude_list.append(p.id)
  41. if perms != "All":
  42. return self.filter(id__in=perms).exclude(id__in=exclude_list)
  43. else:
  44. return self.exclude(id__in=exclude_list)
  45. def published(self, site=None):
  46. pub = self.on_site(site).filter(published=True)
  47. if settings.CMS_SHOW_START_DATE:
  48. pub = pub.filter(
  49. Q(publication_date__lt=timezone.now()) |
  50. Q(publication_date__isnull=True)
  51. )
  52. if settings.CMS_SHOW_END_DATE:
  53. pub = pub.filter(
  54. Q(publication_end_date__gte=timezone.now()) |
  55. Q(publication_end_date__isnull=True)
  56. )
  57. return pub
  58. def expired(self):
  59. return self.on_site().filter(
  60. publication_end_date__lte=timezone.now())
  61. # - seems this is not used anymore...
  62. # def get_pages_with_application(self, path, language):
  63. # """Returns all pages containing application for current path, or
  64. # any parrent. Returned list is sorted by path length, longer path first.
  65. # """
  66. # paths = levelize_path(path)
  67. # q = Q()
  68. # for path in paths:
  69. # # build q for all the paths
  70. # q |= Q(title_set__path=path, title_set__language=language)
  71. # app_pages = self.published().filter(q & Q(title_set__application_urls__gt='')).distinct()
  72. # # add proper ordering
  73. # app_pages.query.order_by.extend(('LENGTH(`cms_title`.`path`) DESC',))
  74. # return app_pages
  75. def get_all_pages_with_application(self):
  76. """Returns all pages containing applications for all sites.
  77. Doesn't cares about the application language.
  78. """
  79. return self.published().filter(title_set__application_urls__gt='').distinct()
  80. def get_home(self, site=None):
  81. try:
  82. home = self.published(site).all_root().order_by("tree_id")[0]
  83. except IndexError:
  84. raise NoHomeFound('No Root page found. Publish at least one page!')
  85. return home