コード例 #1
0
 def _get(self, model, id, *extra_filters):
     model = model.lower()
     cls = None
     if _config.DEFINED_MODELS:
         cls = users if model == "users" else _config.DEFINED_MODELS.get(
             model)
         if not cls and _config.RESTRICT_TO_DEFINED_MODELS:
             raise RestrictedModelError
         if cls:
             model = cls.__name__
     if not cls:
         validate_modelname(model)
         cls = users if model == "users" else type(model,
                                                   (ScopedExpando, ), {})
     if id:
         me = False
         if model == "users":
             if id == "me":
                 me = True
                 id = current_user(required=True)
         key = parse_id(id, model)
         m = key.get()
         if not m:
             if model == "users" and me:
                 m = users()
                 m.key = key
                 setattr(m, "$unsaved", True)
                 u = config.get_current_user()
                 if hasattr(u, "email"):
                     m.email = u.email()
             else:
                 raise AppError("No {} with id {}.".format(model, id))
         return m.to_dict()
     else:
         return query(self, cls, *extra_filters)
コード例 #2
0
def current_user(required=False):
    u = config.get_current_user()
    if u:
        return ndb.Key("users", u.user_id()).urlsafe()
    if required:
        raise LoginError("User must be logged in.")
    return None
コード例 #3
0
def current_user(required=False):
  u = config.get_current_user()
  if u:
    return ndb.Key("users", u.user_id()).urlsafe()
  if required:
    raise LoginError("User must be logged in.")
  return None
コード例 #4
0
ファイル: __init__.py プロジェクト: patrickToca/tailbone
 def _get(self, model, id, *extra_filters):
     model = model.lower()
     cls = None
     if _config.DEFINED_MODELS:
         cls = users if model == "users" else _config.DEFINED_MODELS.get(model)
         if not cls and _config.RESTRICT_TO_DEFINED_MODELS:
             raise RestrictedModelError
         if cls:
             model = cls.__name__
     if not cls:
         validate_modelname(model)
         cls = users if model == "users" else type(model, (ScopedExpando,), {})
     if id:
         me = False
         if model == "users":
             if id == "me":
                 me = True
                 id = current_user(required=True)
         key = parse_id(id, model)
         m = key.get()
         if not m:
             if model == "users" and me:
                 m = users()
                 m.key = key
                 setattr(m, "$unsaved", True)
                 u = config.get_current_user()
                 if hasattr(u, "email"):
                     m.email = u.email()
             else:
                 raise AppError("No {} with id {}.".format(model, id))
         return m.to_dict()
     else:
         return query(self, cls, *extra_filters)
コード例 #5
0
ファイル: __init__.py プロジェクト: yao2907/tailbone
 def _get(self, model, id, *extra_filters):
     model = model.lower()
     cls = None
     if _config.DEFINED_MODELS:
         cls = users if model == "users" else _config.DEFINED_MODELS.get(
             model)
         if not cls and _config.RESTRICT_TO_DEFINED_MODELS:
             raise RestrictedModelError
         if cls:
             model = cls.__name__
     if not cls:
         validate_modelname(model)
         cls = users if model == "users" else type(model,
                                                   (ScopedExpando, ), {})
     logging.info("ID %s" % id)
     if id:
         me = False
         if model == "users":
             if id == "me":
                 me = True
                 id = current_user(required=True).urlsafe()
                 logging.info("users me %s" % current_user(required=True))
         if "," in id:
             ids = id.split(",")
             keys = [parse_id(i, model) for i in ids]
             results = ndb.get_multi(keys)
             return [m.to_dict() if m else m for m in results]
         key = parse_id(id, model)
         m = key.get()
         if not m:
             if model == "users" and me:
                 m = users()
                 m.key = key
             else:
                 raise AppError("No {} with id {}.".format(model, id))
         if model == "users" and me:
             u = config.get_current_user()
             if u:
                 for k, v in getAttributes(u).items():
                     if k.startswith("_"):
                         k = "$" + k[1:]
                     setattr(m, k, v)
         return m.to_dict()
     else:
         return query(self, cls, *extra_filters)
コード例 #6
0
ファイル: __init__.py プロジェクト: NamPNQ/tailbone
 def _get(self, model, id, *extra_filters):
   model = model.lower()
   cls = None
   if _config.DEFINED_MODELS:
     cls = users if model == "users" else _config.DEFINED_MODELS.get(model)
     if not cls and _config.RESTRICT_TO_DEFINED_MODELS:
       raise RestrictedModelError
     if cls:
       model = cls.__name__
   if not cls:
     validate_modelname(model)
     cls = users if model == "users" else type(model, (ScopedExpando,), {})
   logging.info("ID %s" % id)
   if id:
     me = False
     if model == "users":
       if id == "me":
         me = True
         id = current_user(required=True).urlsafe()
         logging.info("users me %s" % current_user(required=True))
     if "," in id:
       ids = id.split(",")
       keys = [parse_id(i, model) for i in ids]
       results = ndb.get_multi(keys)
       return [m.to_dict() if m else m for m in results]
     key = parse_id(id, model)
     m = key.get()
     if not m:
       if model == "users" and me:
         m = users()
         m.key = key
       else:
         raise AppError("No {} with id {}.".format(model, id))
     if model == "users" and me:
       u = config.get_current_user()
       if u:
         for k, v in getAttributes(u).items():
           if k.startswith("_"):
             k = "$" + k[1:]
           setattr(m, k, v)
     return m.to_dict()
   else:
     return query(self, cls, *extra_filters)