I have a filter that I use to support the language in my web application. But when I publish it to GAE, he constantly tells me that the processor utilization is too great.
I think I found a problem with my filters, which I use for support. I use this in my templates:
<h1>{{ "collection.header"|translate:lang }}</h1>
The filter code is as follows:
import re
from google.appengine.ext import webapp
from util import dictionary
register = webapp.template.create_template_register()
def translate(key, lang):
d = dictionary.GetDictionaryKey(lang, key)
if d == False:
return "no key for " + key
else:
return d.value
register.filter(translate)
I'm new to Python to figure out what's wrong with him. Or is this the whole wrong approach?
..fredrik
A little more about what I'm trying to do: I'm trying to move away from language support. The user should be able to update text elements through the admin page. At the moment, all text elements are stored in db.model. And use the filter to get the correct language-based key.
. . 30-50 . 1500 (900 API) . , ?
memcache , . . memcache ?
:
import re
from google.appengine.ext import webapp
from google.appengine.api import memcache
from util import dictionary
register = webapp.template.create_template_register()
def translate(key, lang):
re = "no key for " + key
data = memcache.get("dictionary" + lang)
if data is None:
data = dictionary.GetDictionaryKey(lang)
memcache.add("dictionary" + lang, data, 60)
if key in data:
return data[key]
else:
return "no key for " + key
register.filter(translate)
util.dictionary :
from google.appengine.ext import db
class DictionaryEntries(db.Model):
lang = db.StringProperty()
dkey = db.StringProperty()
value = db.TextProperty()
params = db.StringProperty()
@property
def itemid(self):
return self.key().id()
def GetDictionaryKey(lang):
entries = DictionaryEntries.all().filter("lang = ", lang)
if entries.count() > 0:
langObj = {}
for entry in entries:
langObj[entry.dkey] = entry.value
return langObj
else:
return False