本文整理汇总了Python中model.User.birthday方法的典型用法代码示例。如果您正苦于以下问题:Python User.birthday方法的具体用法?Python User.birthday怎么用?Python User.birthday使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类model.User
的用法示例。
在下文中一共展示了User.birthday方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import birthday [as 别名]
def post(self, error_msg=None):
email = self.request.get("email")
username = self.request.get("username")
users = User.all().filter('email', email)
user = User()
user.email = email
user.username = username
user.fullname = self.request.get("firstname")+" "+self.request.get("lastname")
user.birthday = datetime.datetime.strptime(self.request.get("birthday"), '%Y-%m-%d')
user.set_password(self.request.get("password")) #set password. need encrypt.
user.firstname = self.request.get("firstname")
user.lastname = self.request.get("lastname")
user.country = self.request.get("country")
gender = self.request.get("gender")
if gender:
gender_ = str(gender)[0:1]
user.gender = gender_
if users.count() == 0:
user.put()
#init() the session
sessions.Session().login_user(user)
self.redirect("/")
return
else:
error_msg = "That email address has already been registered."
template_values = {
"temp_user": user,
"error": error_msg
}
self.generate('signup.html',template_values)
示例2: get
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import birthday [as 别名]
def get(self):
args = self.args_to_dict()
s = {}
self.session = sessions.Session()
if self.session['openid_stuff']:
try:
s = pickle.loads(str(self.session['openid_stuff']))
except:
pass
consumer = Consumer(s, store.DatastoreStore())
if not consumer:
return
fetchers.setDefaultFetcher(fetcher.UrlfetchFetcher())
auth_response = consumer.complete(args, self.request.uri)
if auth_response.status == 'success':
openid = auth_response.getDisplayIdentifier()
#when user add openid from profile setting, just return status.
if self.session['openid_userid']:
user = User.get(self.session['openid_userid'])
if user:
users = User.all().filter('openids', openid)
if users.count() == 0:
user.openids += [db.Category(openid.strip().encode('utf8'))]
user.put()
else:
msg = "OpenID had already been attached to another user."
if users.count()==1 and users.get() == user:
msg = "OpenID had already been attached to you."
self.generate('user/user_profile_openid_verify.html',
{"status":"fail","msg":msg})
return
self.generate('user/user_profile_openid_verify.html',
{"status":"success","msg":"Attach OpenID to user successfully."})
return
sreg_data = sreg.SRegResponse.fromSuccessResponse(auth_response)
users = User.all().filter('openids', openid)
if users.count() == 0:
user = User()
user.openids = [db.Category(openid.strip().encode('utf8'))]
if sreg_data:
user.username = sreg_data["nickname"]
user.fullname = sreg_data["fullname"]
user.country = sreg_data["country"]
user.birthday = datetime.datetime.strptime(sreg_data["dob"], '%Y-%m-%d')
user.gender = sreg_data["gender"]
user.language = sreg_data["language"]
user.postcode = sreg_data["postcode"]
#user.email = sreg_data["email"]
else:
user.username = openid
user.put()
self.session.login_user(user)
self.redirect('/user')
return
else:
user = users[0]
self.session.login_user(user)
self.redirect('/')
return
else:
#when user add openid from profile setting, just return status.
if self.session['openid_userid']:
self.generate('user/user_profile_openid_verify.html',
{"status":"fail","msg":"Attach OpenID to user unsuccessfully: OpenID verification failed."})
return
self.show_main_page('OpenID verification failed.')
示例3: __get_attributes
# 需要导入模块: from model import User [as 别名]
# 或者: from model.User import birthday [as 别名]
def __get_attributes(self, res):
if res.status_code != 200:
return
main = BeautifulSoup(res.content)('div', id='viewprofile')
if len(main) == 0:
return
profile_str = str(main[0])
profile_str = profile_str \
.replace('Настоящее имя:', 'username') \
.replace('Пол:', 'sex') \
.replace('Женский', 'female') \
.replace('Мужской', 'male') \
.replace('Возраст:', 'birthday') \
.replace('Местонахождение:', 'location') \
.replace('Зарегистрирован:', 'registered') \
.replace('Провел на форуме:', 'on_board') \
.replace('ICQ:', 'icq') \
.replace('Skype:', 'skype') \
.replace('Mail Agent:', 'mail_agent') \
.replace('Обо мне:', 'about') \
.replace('Сообщений:', 'posts_num') \
.replace('Интересы:', 'interests')
profile = BeautifulSoup(profile_str)
# self.response.out.write(profile.extract())
# return
fields = [
'nickname',
'rolename',
'username',
'sex',
'birthday',
'location',
'registered',
'avatar',
'signature',
'icq',
'skype',
'mail_agent',
'about',
'posts_num',
'interests'
]
lis = profile('li')
nickname = lis.pop(0).strong.string
rolename = lis.pop(0).strong.string
avatar = lis.pop(0)
signature = profile('div', id='profile-signature')
def get_attr(li):
if li.span:
if li.span.string == 'posts_num':
return ('posts_num', re.search('\d+', str(li.strong)).group())
return (li.span and li.span.string, li.strong.string)
return ('', '')
attributes = dict(map(get_attr, lis))
attributes['nickname'] = nickname
attributes['rolename'] = rolename
attributes['avatar'] = avatar.div and avatar.div.img['src']
attributes['signature'] = signature and signature[0]('p')[0]
user = User()
for key in fields:
val = attributes.get(key)
if val:
if key == 'birthday':
birthday = re.search(r'\((.*)\)', val).group(1)
user.birthday = datetime.strptime(birthday, '%Y-%m-%d').date()
elif key == 'registered':
user.registered = datetime.strptime(val, '%Y-%m-%d').date()
elif key == 'posts_num':
user.posts_num = int(val)
elif key == 'avatar':
if val:
avatar = urlfetch.fetch('http://uarat.3bb.ru/' + val).content
if avatar:
user.avatar = db.Blob(avatar)
else:
user.__dict__['_' + key] = unicode(val)
return user