app/soc/views/helper/access.py
changeset 2836 0181649aa7b0
parent 2792 14a62fcf4e02
child 2850 c935cb48f757
equal deleted inserted replaced
2835:aff661c7f936 2836:0181649aa7b0
    28   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    28   '"Sverre Rabbelier" <sverre@rabbelier.nl>',
    29   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    29   '"Lennard de Rijk" <ljvderijk@gmail.com>',
    30   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    30   '"Pawel Solyga" <pawel.solyga@gmail.com>',
    31   ]
    31   ]
    32 
    32 
    33 
       
    34 from google.appengine.api import memcache
       
    35 
    33 
    36 from django.utils.translation import ugettext
    34 from django.utils.translation import ugettext
    37 
    35 
    38 from soc.logic import dicts
    36 from soc.logic import dicts
    39 from soc.logic import rights as rights_logic
    37 from soc.logic import rights as rights_logic
    53 from soc.logic.models.student import logic as student_logic
    51 from soc.logic.models.student import logic as student_logic
    54 from soc.logic.models.student_project import logic as student_project_logic
    52 from soc.logic.models.student_project import logic as student_project_logic
    55 from soc.logic.models.student_proposal import logic as student_proposal_logic
    53 from soc.logic.models.student_proposal import logic as student_proposal_logic
    56 from soc.logic.models.timeline import logic as timeline_logic
    54 from soc.logic.models.timeline import logic as timeline_logic
    57 from soc.logic.models.user import logic as user_logic
    55 from soc.logic.models.user import logic as user_logic
       
    56 from soc.modules import callback
    58 from soc.views.helper import redirects
    57 from soc.views.helper import redirects
    59 from soc.views import out_of_band
    58 from soc.views import out_of_band
    60 
    59 
    61 
    60 
    62 DEF_NO_USER_LOGIN_MSG = ugettext(
    61 DEF_NO_USER_LOGIN_MSG = ugettext(
   278 
   277 
   279     base = params.get('rights') if params else None
   278     base = params.get('rights') if params else None
   280     self.rights = base.rights if base else {}
   279     self.rights = base.rights if base else {}
   281     self.id = None
   280     self.id = None
   282     self.user = None
   281     self.user = None
       
   282     self.core = callback.getCore()
   283 
   283 
   284   def normalizeChecker(self, checker):
   284   def normalizeChecker(self, checker):
   285     """Normalizes the checker to a pre-defined format.
   285     """Normalizes the checker to a pre-defined format.
   286 
   286 
   287     The result is guaranteed to be a list of 2-tuples, the first element is a
   287     The result is guaranteed to be a list of 2-tuples, the first element is a
   312 
   312 
   313   def key(self, checker_name):
   313   def key(self, checker_name):
   314     """Returns the key for the specified checker for the current user.
   314     """Returns the key for the specified checker for the current user.
   315     """
   315     """
   316 
   316 
   317     return "%s.%s" % (self.id, checker_name)
   317     return "checker.%s.%s" % (self.id, checker_name)
   318 
   318 
   319   def put(self, checker_name, value):
   319   def put(self, checker_name, value):
   320     """Puts the result for the specified checker in the cache.
   320     """Puts the result for the specified checker in the cache.
   321     """
   321     """
   322 
   322 
   323     retention = 30
   323     cache_key = self.key(checker_name)
   324 
   324     self.core.setRequestValue(cache_key, value)
   325     memcache_key = self.key(checker_name)
       
   326     # pylint: disable-msg=E1101
       
   327     memcache.add(memcache_key, value, retention)
       
   328 
   325 
   329   def get(self, checker_name):
   326   def get(self, checker_name):
   330     """Retrieves the result for the specified checker from cache.
   327     """Retrieves the result for the specified checker from cache.
   331     """
   328     """
   332 
   329 
   333     memcache_key = self.key(checker_name)
   330     cache_key = self.key(checker_name)
   334     # pylint: disable-msg=E1101
   331     return self.core.getRequestValue(cache_key)
   335     return memcache.get(memcache_key)
       
   336 
   332 
   337   def doCheck(self, checker_name, django_args, args):
   333   def doCheck(self, checker_name, django_args, args):
   338     """Runs the specified checker with the specified arguments.
   334     """Runs the specified checker with the specified arguments.
   339     """
   335     """
   340 
   336