Author: batiste.bieler
Date: Sat Feb 14 15:53:18 2009
New Revision: 340

Modified:
    trunk/example/settings.py
    trunk/pages/middleware.py
    trunk/pages/models.py
    trunk/pages/settings.py
    trunk/pages/templates/admin/pages/page/menu.html
    trunk/pages/templatetags/pages_tags.py

Log:
Add some cache into the admin for basic stuff that needed to be cached

Modified: trunk/example/settings.py
==============================================================================
--- trunk/example/settings.py   (original)
+++ trunk/example/settings.py   Sat Feb 14 15:53:18 2009
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
  # Django settings for cms project.
  import os
  PROJECT_DIR = os.path.dirname(__file__)
@@ -83,6 +84,8 @@
      # Don't forget to use absolute paths, not relative paths.
      os.path.join(PROJECT_DIR, 'templates'),
  )
+
+CACHE_BACKEND = "locmem:///?timeout=300&max_entries=3000"

  INSTALLED_APPS = (
      'django.contrib.auth',

Modified: trunk/pages/middleware.py
==============================================================================
--- trunk/pages/middleware.py   (original)
+++ trunk/pages/middleware.py   Sat Feb 14 15:53:18 2009
@@ -1,4 +1,6 @@
+# -*- coding: utf-8 -*-
  from pages.utils import get_site_from_request
+import settings

  class LazySite(object):
      def __get__(self, request, obj_type=None):
@@ -7,6 +9,21 @@
          return request._cached_site

  class CurrentSiteMiddleware(object):
+
      def process_request(self, request):
          request.__class__.site = LazySite()
          return None
+
+    if settings.PAGE_SQL_DEBUGGING:
+        def process_response(self, request, response):
+            from django import db
+            import logging
+            logging.basicConfig(filename="sql_log.txt",  
level=logging.DEBUG,)
+            logging.debug(request.path + " : " +  
str(len(db.connection.queries)))
+            a = []
+            for q in db.connection.queries:
+                a.append(q['sql'])
+            a.sort()
+            for q in a:
+                logging.debug(q)
+            return response

Modified: trunk/pages/models.py
==============================================================================
--- trunk/pages/models.py       (original)
+++ trunk/pages/models.py       Sat Feb 14 15:53:18 2009
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
  from datetime import datetime

  from django.db import models
@@ -97,12 +98,20 @@
          """
          get the url of this page, adding parent's slug
          """
+        PAGE_URL_KEY = "page_%d_language_%s_url"
+        url = cache.get(PAGE_URL_KEY % (self.id, language))
+        if url:
+            return url
+
          if settings.PAGE_UNIQUE_SLUG_REQUIRED:
              url = u'%s/' % self.slug(language)
          else:
              url = u'%s-%d/' % (self.slug(language), self.id)
          for ancestor in self.get_ancestors(ascending=True):
              url = ancestor.slug(language) + u'/' + url
+
+        cache.set(PAGE_URL_KEY % (self.id, language), url)
+
          return url

      def slug(self, language=None, fallback=True):

Modified: trunk/pages/settings.py
==============================================================================
--- trunk/pages/settings.py     (original)
+++ trunk/pages/settings.py     Sat Feb 14 15:53:18 2009
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
  """
  Convenience module for access of custom pages application settings,
  which enforces default settings when the main settings module does not
@@ -66,3 +67,6 @@
  # an automatic form to create and directly link a new instance of this  
model
  # with your page.
  PAGE_CONNECTED_MODELS = getattr(settings, 'PAGE_CONNECTED_MODELS', False)
+
+# provide some informations about SQL requests into a log file
+PAGE_SQL_DEBUGGING = False

Modified: trunk/pages/templates/admin/pages/page/menu.html
==============================================================================
--- trunk/pages/templates/admin/pages/page/menu.html    (original)
+++ trunk/pages/templates/admin/pages/page/menu.html    Sat Feb 14 15:53:18  
2009
@@ -1,4 +1,4 @@
-{% load pages_tags i18n adminmedia %}
+{% load pages_tags i18n adminmedia cache %}

  {% if has_permission %}
  <tr id="page-row-{{ page.id }}" class="child-of-{{ page.parent.id }}">
@@ -40,10 +40,14 @@
  {% endifequal %}
  </td>
  <td>
-{{ page.get_template }}
+{% cache 600 page_template page.id %}
+    {{ page.get_template }}
+{% endcache %}
  </td>
  <td>
-{% firstof page.author.get_full_name page.author.first_name  
page.author.username %}
+{% cache 3600 page_author page.author.id %}
+    {% firstof page.author.get_full_name page.author.first_name  
page.author.username %}
+{% endcache %}
  </td>
  </tr>
  {% endif %}

Modified: trunk/pages/templatetags/pages_tags.py
==============================================================================
--- trunk/pages/templatetags/pages_tags.py      (original)
+++ trunk/pages/templatetags/pages_tags.py      Sat Feb 14 15:53:18 2009
@@ -1,3 +1,4 @@
+# -*- coding: utf-8 -*-
  from django import template
  from django.core.cache import cache
  from django.utils.safestring import SafeUnicode, mark_safe

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"pinax-updates" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to 
[email protected]
For more options, visit this group at 
http://groups.google.com/group/pinax-updates?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to