Commit 8e611bd2e2296a9217962c178205ac9ee4a9637b

Authored by janek37
1 parent 711d7795

poprawione klucze do cache'a

--HG--
rename : common/templatetags/json.py => common/templatetags/jsonify.py
common/middleware.py
1 1 #-*- coding:utf-8 -*-
2 2  
3 3 from django.db import connection
  4 +from decimal import Decimal
4 5  
5 6 from accounts.util import set_history
6 7  
7 8 class MyMiddleware(object):
8 9 def process_request(self, request):
9 10 if request.user.is_authenticated():
10   - set_history(request.user)
11 11 \ No newline at end of file
  12 + set_history(request.user)
  13 +
  14 + def process_response(self, request, response):
  15 + if False:
  16 + if len(connection.queries) > 0:
  17 + print 'Queries for %s:' % request.path_info
  18 + for query in connection.queries:
  19 + print query['time'], query['sql']
  20 + print 'Total of %s queries for %s.' % (
  21 + len(connection.queries), request.path)
  22 + print 'Total time: %s' % sum(Decimal(q['time'])
  23 + for q in connection.queries)
  24 + return response
12 25 \ No newline at end of file
... ...
common/templatetags/json.py renamed to common/templatetags/jsonify.py
1 1 # -*- coding: utf-8 -*-
2 2  
  3 +import json
  4 +
3 5 from django.core.serializers import serialize
4 6 from django.db.models.query import QuerySet
5   -from django.utils import simplejson
6 7 from django.utils.safestring import mark_safe
7 8 from django.template import Library
8 9  
... ... @@ -12,4 +13,4 @@ register = Library()
12 13 def jsonify(object):
13 14 if isinstance(object, QuerySet):
14 15 return serialize('json', object)
15   - return mark_safe(simplejson.dumps(object))
  16 + return mark_safe(json.dumps(object))
... ...
common/util.py
1 1 # -*- coding: utf-8 -*-
2 2  
3   -import re
  3 +import json
4 4 import sys
5 5 from django.conf import urls
6 6 from django.http import HttpResponseRedirect, Http404
... ... @@ -93,4 +93,10 @@ class GroupDict(dict):
93 93 def add(self, key, value):
94 94 if key not in self:
95 95 self[key] = []
96   - self[key].append(value)
97 96 \ No newline at end of file
  97 + self[key].append(value)
  98 +
  99 +def json_encode(obj):
  100 + return json.dumps(obj, sort_keys=True)
  101 +
  102 +def json_decode(obj):
  103 + return json.loads(obj)
98 104 \ No newline at end of file
... ...
dictionary/ajax_lexeme_jqgrid.py
1 1 #-*- coding:utf-8 -*-
  2 +from hashlib import md5
2 3  
3   -from django.utils.simplejson import dumps as json_encode
4 4 from django.db.models import Count
5 5 from dictionary.models import Lexeme, filter_visible, visible_vocabularies, LexemeInflectionPattern, LexemeAssociation
6 6 from dictionary.ajax_jqgrid import JqGridAjax, JqGridQuery
7 7 from common.decorators import ajax
8   -from common.util import bisect_left, reverse, GroupDict
  8 +from common.util import bisect_left, reverse, GroupDict, json_encode
9 9 from django.core.cache import cache
10 10  
11 11 class LexemeGrid(JqGridAjax):
... ... @@ -226,7 +226,7 @@ def cache_key(query):
226 226 key += vocabulary.id
227 227 if query.filtering_mode():
228 228 key += query.mask
229   - return key
  229 + return md5(key).hexdigest()
230 230  
231 231 def get_cached_lexemes(query):
232 232 key = cache_key(query)
... ...
dictionary/ajax_pattern_view.py
1 1 #-*- coding:utf-8 -*-
2 2  
3   -from django.utils.simplejson import dumps as json_encode
  3 +from common.util import json_encode
4 4 from dictionary.models import Pattern, Ending, BaseFormLabel, PatternType, \
5 5 editable_qualifiers, readonly_vocabularies
6 6 from dictionary.forms import PatternEditForm, PatternTypeForm, QualifierForm
... ...
templates/base.html
... ... @@ -12,7 +12,7 @@
12 12 {% if paginer %}
13 13 <script type="text/javascript" src="{{ MEDIA_URL }}js/paginer.js"></script>
14 14 {% endif %}
15   -{% load script json %}
  15 +{% load script jsonify %}
16 16 {% script %}
17 17 var $dj = {};
18 18 {% for name,var in js_vars.iteritems %}
... ...