Example #1
0
  def dispatch(self, match, request, response, method = None):
    """docstring for dispatch
    
    @TODO lots - see body
    """
    handler_class, args, kwargs = match
    method = method or request.method.lower().replace('-', '_')

    if isinstance(handler_class, basestring):
      if handler_class not in self._handlers:
        # @TODO implement import_controller
        self._handlers[handler_class] = import_string(handler_class)
      handler_class = self._handlers[handler_class]

    # 1. Initiate controller
    handler = handler_class(self, request, response)

    # 2. Attach middleware
    # @TODO Implement functions for this and caches
    handler.config = self.config
    session = sketch.Session(handler, 'sess')
    handler.attach_session(session)

    # 3. Attach user
    if 'key' in handler.session:
      logging.info(handler.session)
      try:
        handler.user = sketch.users.User.get_by_key(handler.session['key'])
      except Exception, e:
        logging.error('Error: could not get user. destroying session (%s)' % handler.session.key)
        handler.session.destroy()
        handler.user = False
Example #2
0
 def import_app_module(self, module, obj = None, silent = False):
   # TODO do some sanitation on import and move the import_string module over
   imp = "%s.%s" % (self.app_name, module)
   if obj:
     imp = "%s:%s" % (imp, obj)
   try:
     ret = import_string(imp, silent)
   except AttributeError, e:
     logging.info("Import Error: %s" % str(e))
     return None