当前位置: 首页>>代码示例>>Python>>正文


Python User.key方法代码示例

本文整理汇总了Python中model.User.key方法的典型用法代码示例。如果您正苦于以下问题:Python User.key方法的具体用法?Python User.key怎么用?Python User.key使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在model.User的用法示例。


在下文中一共展示了User.key方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: get

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import key [as 别名]
    def get(self):
        user = self.getUser()
        now = datetime.datetime.now()

        if not user:
            user = User(createdOn=now, lastAccessedOn=now, lastEntrySet=-1)

        entries, newEntrySetNumber = self.getEntrySetForUser(user)

        user.lastEntrySet = newEntrySetNumber
        user.lastAccessedOn = now

        try:
            user.put()
            userKeyToWrite = str(user.key())
        except Exception as e:
            logging.error(str(e))
            userKeyToWrite = None

        def dictionarize(e):
            return {'a': e[0], 'w': e[1], 't': e[2]}   #to save bandwidth

        jsonifiedData = json.dumps({'userKey': userKeyToWrite, 'entries': [dictionarize(entry) for entry in entries]})

        callbackParam = self.request.get('callback')
        if callbackParam:        #if exists, then return as JSONP
            self.response.headers['Content-Type'] = 'application/javascript'
            self.response.out.write('{}({});'.format(callbackParam, jsonifiedData))
        else:
            self.response.headers['Content-Type'] = 'application/json'
            self.response.out.write(jsonifiedData)
开发者ID:aliok,项目名称:flashcards,代码行数:33,代码来源:service.py

示例2: insert_user

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import key [as 别名]
def insert_user(user_json):
  #print "INSERT USER"
  #print user_json
 
  user_string = json.loads(user_json)
  userAddress = Address(number = user_string["number"],
                    street = user_string["street"],
                    postalCode = user_string["postalCode"],
                    city = user_string["city"],
                    province = user_string["province"])

  #print "pizzaId: " + user_string["pizzaId"]
  
  userOrder = Order(qty = int(user_string["quantity"]),
								size = int(user_string["pizzaSize"]),
                pizza_type = int(user_string["pizzaId"]))   
  userAddress.put()
  userOrder.put()
  user = User(name = user_string["name"],
              phoneNumber = user_string["phoneNumber"],
              email = user_string["email"],
              addressId = userAddress.key(), 
              orderId = userOrder.key())  

  user.put()
  return user.key();
开发者ID:gmacleod,项目名称:PizzaButton,代码行数:28,代码来源:model_wrapper.py

示例3: BaseHandler

# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import key [as 别名]
class BaseHandler(webapp2.RequestHandler):

    # current user, a User item
    # This will be configured by setupUser
    user = None

    # constants used to determine the kind of post:
    # either a SEARCH, triggered by the search button
    # or a POST or POST_PHOTO, triggered by the post portal
    SEARCH = 2
    POST = 5
    POST_PHOTO = 6
    FEED_LENGTH = 10
    
    def setupUser(self):
        self.session = sessions.Session()
        # configure user

        if self.session.get("userKey"):
            userKey = self.session["userKey"]["key"]
            # print userKey
            self.user = db.get(userKey)
            return

        cookie = facebook.get_user_from_cookie(self.request.cookies,
                                               FACEBOOK_APP_ID,
                                               FACEBOOK_APP_SECRET)

        if cookie != None:
            # print "fetching from fbk"
            graph = facebook.GraphAPI(cookie["access_token"])
            profile = graph.get_object("me")

            id = profile["id"]

            q = User.all().filter('id =', id)

            self.user = q.get()

            if self.user == None:
                self.user = User(id = profile["id"],
                    name = profile["name"],
                    profile_url = profile["link"],
                    access_token = cookie["access_token"],
                    items = [])

            self.user.access_token = cookie["access_token"]

            self.user.put()
            userKey = str(self.user.key())
            self.session["userKey"] = {"key":userKey}


        else:
            # redirection logic might go here
            print "no cookie was found"

    def write(self, s):
        self.response.out.write(s)

    def itemToDisplayItem(self, item):
        user = db.get(item.seller[0])
        disp = DisplayItem(id = item.key(),
            itemName = item.itemName,
            price = item.price,
            sellerName = user.name,
            sellerURL = user.profile_url,
            description = item.description,
            blobKey = item.blobKey,
            category = item.category,
            )
        return disp
开发者ID:iliu88,项目名称:usell,代码行数:74,代码来源:basehandler.py


注:本文中的model.User.key方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。