本文整理汇总了Python中models.user.User.gql方法的典型用法代码示例。如果您正苦于以下问题:Python User.gql方法的具体用法?Python User.gql怎么用?Python User.gql使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.user.User
的用法示例。
在下文中一共展示了User.gql方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: get
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import gql [as 别名]
def get(self):
c = h.context()
logging.info("***Auth2")
cookies = h.get_default_cookies(self)
c['cookies'] = cookies
logging.info("***cookies: "+str(cookies))
c['access_token'] = self.request.get("access_token")
if self.request.get("access_token") == '':
logging.error("No access token set, but we expected on %s" % str(self.request.url))
else:
logging.warning("Got access token %s" % self.request.get("access_token"))
user = User.gql("WHERE fb_oauth_access_token = :1", self.request.get("access_token")).get()
if user != None:
# If the user currently exists in the DB
logging.info("***SCU1")
h.set_current_user(cookies, user)
logging.info("***cookies: "+str(cookies))
c['current_user'] = user
else:
# Look user up in graph, and either find them in the DB or create them if they don't exist
try:
graph = facebook.GraphAPI(self.request.get("access_token"))
me = graph.get_object('me')
except Exception, e:
logging.error(
"ERROR! Failed to access Facebook Graph for access_token=" +
self.request.get("access_token") +
"::" + str(e))
me = None
c['error'] = e
if me != None:
og_user = User.gql("WHERE fb_user_id = :1", str(me['id'])).get()
if og_user == None:
new_user = User(
fb_user_id = str(me['id']),
fb_oauth_access_token = self.request.get("access_token"),
fb_oauth_access_token_stored_at = datetime.datetime.utcnow(),
first_name = me['first_name'],
last_name = me['last_name'])
if 'email' in me:
new_user.email = me['email']
new_user.put()
logging.info("***SCU2")
h.set_current_user(cookies, new_user)
logging.info("***cookies: "+str(cookies))
c['current_user'] = new_user
else: # Update auth token for user because it's out of date
og_user.fb_oauth_access_token = self.request.get("access_token")
og_user.fb_oauth_access_token_stored_at = datetime.datetime.utcnow()
og_user.put()
logging.info("***SCU3")
h.set_current_user(cookies, og_user)
logging.info("***cookies: "+str(cookies))
c['current_user'] = og_user
示例2: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import gql [as 别名]
def post(self):
username = self.request.POST['username']
password = self.request.POST['password']
user = User.gql("where email = :1",username)
user = user.get()
if user is None:
self.session.add_flash("Invalid Username!",key='error')
self.redirect("/login")
else:
manager = CRYPTPasswordManager(SHA256CRYPT)
if manager.check(user.password,password):
self.session["current_user"] = str(user.key())
self.redirect("/")
else:
self.session.add_flash("Invalid Password!",key='error')
self.redirect("/login")
示例3: post
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import gql [as 别名]
def post(self):
query = User.all()
query.order('-created_at')
cursor = self.request.get('cursor')
if cursor != None:
query.with_cursor(cursor)
users = query.fetch(25)
for user in users:
page_view_with_user = PageView.gql("WHERE user = :1 ORDER BY created_at ASC", user).get()
if page_view_with_user == None:
logging.error("Couldn't find PageView for User(key=%s,fb_user_id=%s)" % (str(user.key()), str(user.fb_user_id)))
page_view_with_user = PageView() # Fake it till we make it
if page_view_with_user.session_id != None and len(page_view_with_user.session_id) > 0:
page_view_with_session_id = PageView.gql("WHERE session_id = :1 ORDER BY created_at ASC", page_view_with_user.session_id).get()
else:
page_view_with_session_id = page_view_with_user
referring_page_view = page_view_with_session_id
if not referring_page_view.is_saved():
referring_page_view = None
installed_at = user.created_at
if page_view_with_session_id.referrer == None or len(page_view_with_session_id.referrer) < 10:
url_to_parse = page_view_with_session_id.url
else:
url_to_parse = page_view_with_session_id.referrer
if url_to_parse == None:
url_to_parse = ''
parsed_referral_url = urlparse(url_to_parse)
params = cgi.parse_qs(parsed_referral_url.query)
if 'suid' in params and params['suid'] != None and len(params['suid'][0]) > 0:
installed_via_newsfeed = True
referring_user = User.gql("WHERE fb_user_id = :1", params['suid'][0]).get()
newsfeed_search_term = '|'.join(params['q'])
newsfeed_verb = '|'.join(params['v'])
ad_name = None
installed_via_ad = False
installed_via_unknown = False
elif 'q' in params and params['q'] != None and len(params['q'][0]) > 0:
installed_via_newsfeed = False
referring_user = None
newsfeed_search_term = None
newsfeed_verb = None
ad_name = '|'.join(params['q'])
installed_via_ad = True
installed_via_unknown = False
else:
installed_via_newsfeed = False
referring_user = None
newsfeed_search_term = None
newsfeed_verb = None
ad_name = None
installed_via_ad = False
installed_via_unknown = True
install_metric = InstallMetric.gql("WHERE user = :1", user).get()
if install_metric == None:
install_metric = InstallMetric(
fb_user_id = user.fb_user_id,
user = user,
installed_at = installed_at,
installed_via_ad = installed_via_ad,
ad_name = ad_name,
installed_via_newsfeed = installed_via_newsfeed,
referring_user = referring_user,
newsfeed_search_term = newsfeed_search_term,
newsfeed_verb = newsfeed_verb,
installed_via_unknown = installed_via_unknown,
referring_page_view = referring_page_view
)
else:
install_metric.fb_user_id = user.fb_user_id
install_metric.user = user
install_metric.installed_at = installed_at
install_metric.installed_via_ad = installed_via_ad
install_metric.ad_name = ad_name
install_metric.installed_via_newsfeed = installed_via_newsfeed
install_metric.referring_user = referring_user
install_metric.newsfeed_search_term = newsfeed_search_term
install_metric.newsfeed_verb = newsfeed_verb
install_metric.installed_via_unknown = installed_via_unknown
install_metric.referring_page_view = referring_page_view
install_metric.put()
self.response.out.write(simplejson.dumps({'status': 'ok', 'cursor': str(query.cursor()), 'count': len(users) }))
示例4: get_current_user
# 需要导入模块: from models.user import User [as 别名]
# 或者: from models.user.User import gql [as 别名]
def get_current_user(cookies):
if 'uk' in cookies and 'oat' in cookies:
return User.gql("WHERE __key__ = :1 AND fb_oauth_access_token = :2", db.Key(cookies['uk']), cookies['oat']).get()
return None