Exemple #1
0
 def has_permission(self, instance=None, action=None, user=None):
   if instance:
     if action in (u'view', u'edit'):
       if auth.is_current_user_admin() or \
         (user and instance.key == user.key):
         return True
   return False
Exemple #2
0
  def emit(self, record):
    """Emit a record.

    This implementation is based on the implementation of
    StreamHandler.emit()."""
    try:
      message = self._AppLogsMessage(record)
      if isinstance(message, unicode):
        message = message.encode("UTF-8")

      if auth.is_current_user_admin():
        title = u'%s [%s:%s] inside \'%s()\'' % (record.levelname, 
          record.filename, record.lineno, record.funcName)

        try:
          sess = auth.get_session()
          current_log_records = sess.get(u'log_records', None)
          if not isinstance(current_log_records, list):
            sess[u'log_records'] = []
          if title:
            sess[u'log_records'].append({u'title': title, u'payload': message})
        except (AttributeError, KeyError), e:
          raise
    except (KeyboardInterrupt, SystemExit):
      raise
    except:
      self.handleError(record)
 def _json_global_vars(self):
   return {
     u'raw_uri' : self.request.uri,
     u'parsed_uri' : self.parsed_uri,
     u'is_admin' :  auth.is_current_user_admin(),
     u'debug' :  utils.is_debug()
   }
  def handle_exception(self, ex):
    if isinstance(ex, exc.HTTPException):
      error_code = ex.code
    else:
      if utils.is_debug() or auth.is_current_user_admin():
        error_code = 500
      else:
        error_code = 404

    self.error(error_code)

    #log the exception
    self.log_exception(ex)

    return self.respond_on_error(error_code)
 def _global_template_vars(self):
   _globals = {
     u'session': self.session,
     u'layout': self.layout,
     u'errors': self.get_template_errors(),
     u'request': self.request,
     u'body_class': self.body_class,
     u'raw_uri' : self.request.uri,
     u'parsed_uri' : self.parsed_uri,
     u'logged_in_user' : self.current_user(),
     u'is_admin' :  auth.is_current_user_admin(),
     u'auth' :  auth,
     u'utils' :  utils,
   }
   return _globals