예제 #1
0
 def wrapper(*args, **kwargs):
     template = None
     if len(args) > 0:
         instance = args[0]
         if inspect.isclass(instance.__class__):
             template = path.join(instance.__class__.__name__.lower(),
                                  "%s.html" % f.__name__.lower())
             method_id = "%s.%s" % (instance.__class__.__name__,
                                    f.__name__)
     try:
         result = f(*args, **kwargs)
     except Exception:
         pass
         # TODO: Implement it
     if isinstance(result, tuple):
         model, template = result[0], result[1]
     else:
         model = result
     renderer = ApplicationContext.get_instance().get_object('renderer')
     response = args[2]
     # FIXME: Exception handling if template is None
     # FIXME: Handling from string based templates
     try:
         logger.debug("Rendering model for %s" % method_id)
         content = renderer.process(template, model)
     except Exception, e:
         content = 'Template Fehler: %s' % e
         response.status = 500
예제 #2
0
 def wrapper(*args, **kwargs):
     if prefix == 'method_id':
         if len(args) > 0:
             instance = args[0]
             if inspect.isclass(instance.__class__):
                 prefix = "%s.%s." % (instance.__class__.__name__,
                                        f.__name__)
     elif prefix is None:
         prefix = ''
     else:
         prefix += '.'
     request = args[1]
     if not request.form.has_key(key):
         pass
         # FIXME: raise Exception
     # TODO: Much more safer form param handling
     cache_key = "%s%s" % (prefix, str(request.form['id']))
     cache = ApplicationContext.get_instance().get_object(context_key)
     result = cache.get(cache_key)
     if result is not None:
         logger.debug("Cache entry found")
         # TODO: Check for pickled content
         return result
     else:
         try:
             result = f(*args, **kwargs)
         except Exception:
             pass
             # TODO: Implement it
         if not isinstance(result, (str, unicode)):
             data = pickle.dumps(result)
             logger.debug("Caching result for %s: %s" % \
                          (key, str(request.form['id'])))
             cache.set(cache_key, data)
         else:
             cache.set(cache_key, result)
         return result