本文整理汇总了Python中site_helper.getModel函数的典型用法代码示例。如果您正苦于以下问题:Python getModel函数的具体用法?Python getModel怎么用?Python getModel使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了getModel函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: POST
def POST(self):
i = web.input()
if i.has_key('email'):
user = site_helper.getModel('User').getByEmail(i.email.strip())
if user is not None:
reset_model = site_helper.getModel('ResetPasswdCode')
reset = reset_model.getACode(user.Userid)
reset_model.updateACode(user.Userid, reset)
reset_model.sendACode(user, reset)
return page_helper.success('发送成功,查收您的邮箱.', '/')
elif i.has_key('password'):
user_id = site_helper.getUrlParams(site_helper.getEnv('HTTP_REFERER'))['userid']
post_code = site_helper.getUrlParams(site_helper.getEnv('HTTP_REFERER'))['rcode']
user_model = site_helper.getModel('User')
code_model = site_helper.getModel('ResetPasswdCode')
user = user_model.get(user_id)
if user is not None:
code = code_model.getByUserid(user_id)
if code is not None and code.acode == post_code and ((datetime.now() - code.created).seconds < 3600*24):
assert(len(i.password) > 0)
user_model.resetPassword(user_id, i.password)
code_model.deleteByUserid(user_id)
site_helper.login(user)
return page_helper.success('重设密码成功,已登录.', '/')
else:
return page_helper.failed('本重置密码链接已使用或已过期,请重新申请.','/accounts/forget')
else:
return page_helper.redirectToLogin()
else:
return page_helper.redirect404();
示例2: shareAll
def shareAll(self, user_id, comment, **options):
user = getModel('User').get(user_id)
if user:
model = getModel(self.MODEL_NAME)
for o in model.getsByUserid(user_id):
if o.get('share','') == 'on':
self.share(user_id, o.access_token, comment, **options)
示例3: GET
def GET(self):
session = site_helper.session
if session.is_login:
user_id = int(session.user_id)
user_model = site_helper.getModel('User')
medal_model = site_helper.getModel('Medal')
share_link_model = site_helper.getModel('ShareLink')
uhm_model = site_helper.getModel('UserHasMedal')
user = user_model.get(user_id)
if user is not None:
share_count = share_link_model.getCountByUserid(user.Userid)
UserCtrl().writeBaseInfo(user)
oauth_status = self._getOAuthStatus(user_id)
exists_medal = uhm_model.getByUserAndName(user_id, 'share_daren')
share_medal = medal_model.getOneByWhere('name=%s', ['share_daren'])
if share_medal:
share_medal = medal_model.get(share_medal.Medalid)
winner_settings = self._getWinnerSettings('share_link_winner')
latest_winner_settings = self._getWinnerSettings('share_link_latest_winner')
sub_content = site_helper.page_render_nobase.user.Share(user, share_count, oauth_status, exists_medal, winner_settings, latest_winner_settings, share_medal)
return site_helper.page_render.user.Base3(user, sub_content)
else:
return page_helper.redirect404()
else:
page_helper.redirectToLogin()
示例4: _getBoughts
def _getBoughts(self, user_id):
bought_model = site_helper.getModel('Bought')
makeup_model = site_helper.getModel('Makeup')
env = {'pagination':'fifty items', 'where':('Userid=%s',[user_id]), 'orderby':'Boughtid desc'}
boughts = map(makeup_model.get, [i.Makeupid for i in bought_model.getAll(env)])
for makeup in boughts:
makeup.bought = bought_model.getBought(user_id,makeup.Makeupid)
pagination_html = bought_model.getPaginationHtml(env)
return boughts, pagination_html
示例5: __setHtmlForTopicCommentNotice
def __setHtmlForTopicCommentNotice(self, comment_notices):
user_model = site_helper.getModel('User')
comment_model = site_helper.getModel('TopicComment')
topic_model = site_helper.getModel('Topic')
for notice in comment_notices:
author = user_model.get(notice.source_id)
comment = comment_model.get(notice.item_id)
topic = topic_model.get(comment.Topicid)
notice.html = site_helper.page_render_nobase.user.notices.TopicCommentNotice(author, comment, topic, notice)
return comment_notices
示例6: __setHtmlForReviewCommentNotice
def __setHtmlForReviewCommentNotice(self, comment_notices):
user_model = site_helper.getModel('User')
comment_model = site_helper.getModel('Comment')
review_model = site_helper.getModel('Review')
for notice in comment_notices:
author = user_model.get(notice.source_id)
comment = comment_model.get(notice.item_id)
review = review_model.get(comment.Reviewid)
notice.html = site_helper.page_render_nobase.user.notices.ReviewCommentNotice(author, comment, review, notice)
return comment_notices
示例7: _getReviews
def _getReviews(self, user_id, inp):
reviews, review_pagination = self._getReviews(user_id, inp)
wanteds, wanted_pagination = self._getWanteds(user_id, inp)
review_model = getModel('Review')
makeup_model = getModel('Makeup')
page_num = int(web.input().get('rpn',1)) # rpn is review page number
env = {'pagination':'ten items', 'page_num':page_num, 'where':('Userid=%s',[user_id]), 'orderby':'Reviewid desc'}
reviews = review_model.getAll(env)
for review in reviews:
review.makeup = makeup_model.get(review.Makeupid)
pagination_html = review_model.getPaginationHtml(env, {'para_name':'rpn'})
return reviews, pagination_html
示例8: getFollowsNotices
def getFollowsNotices(self, user_id):
'''有了新的粉丝'''
user_model = getModel('User')
user = user_model.get(user_id)
notice_model = getModel('Notice')
env = {'orderby':'Noticeid desc'}
env['select'] = 'distinct f.*'
env['from'] = 'Notice f join Follow fo on f.item_id=fo.Followid'
env['where'] = ('f.item_type=%s and fo.followed_id=%s', ['Follow', user_id])
follow_notices = notice_model.getAll(env)
return self.__setHtmlForFollowNotice(user,follow_notices)
示例9: getWanteds
def getWanteds(self, user_id):
wanted_model = site_helper.getModel('Wanted')
makeup_model = site_helper.getModel('Makeup')
wanteds = wanted_model.getWantedsByUserid(user_id)
for wanted in wanteds:
wanted.makeup = makeup_model.getWithAll(wanted.Makeupid)
score = makeup_model.calcScore(wanted.Makeupid)
if score is not None:
wanted.makeup.score = '%.1f' % score
else:
wanted.makeup.score = '未知'
return filter(lambda w:w.makeup is not None, wanteds)
示例10: POST
def POST(self, i=None):
#if i is None: i = web.input(imagefile={})
i = web.input()
has_portrait = False
i.login_ip = i.register_ip = site_helper.session.ip
assert(i.has_key('email') and len(i.email.strip()) < 100 )
assert(i.has_key('username') and 2 <= len(i.username.strip()) <= 24 )
assert(i.has_key('password') and len(i.password)<60 )
i.email = i.email.strip()
i.username = i.username.strip()
user_model = getModel('User')
if UserCtrl().isExists(i.email):
return page_helper.failed('注册失败, 邮箱已被占用 :(')
# 管理员注册不需要验证
if site_helper.session.is_admin:
i.activated = 'on'
new_id = user_model.insert(i)
user = user_model.get(new_id)
site_helper.login(user)
self.processShareLink(user)
acode_model = site_helper.getModel('ACode')
acode = acode_model.getACode(user.Userid)
acode_model.updateACode(user.Userid, acode)
acode_model.sendACode(user, acode)
if has_portrait:
#return site_helper.page_render.user.ModifyPortrait(user)
raise web.seeother('/accounts/portrait?hideupload=true')
else:
# 根据当前url中的referer跳转
params = site_helper.getUrlParams()
if params.get('referer', False):
return site_helper.page_render.Success('注册成功! 请打开您的Email进行验证, 只有验证后才能发表心得哦!', params['referer'])
# 根据上一个页面地址中的referer跳转
params = site_helper.getUrlParams(site_helper.getEnv('HTTP_REFERER'))
if params.get('referer', False):
return site_helper.page_render.Success('注册成功! 请打开您的Email进行验证, 只有验证后才能发表心得哦!', params['referer'])
return site_helper.page_render.Success('注册成功! 请打开您的Email进行验证, 只有验证后才能发表心得哦!', '/')
示例11: getLevels
def getLevels(self, wanteds, recommends):
'''返回这种格式的数据:
{level1:{
level2: {'wanteds':[makeup1, makeup2], 'recommends':[makeup1, makeup2]},
level2: {...}
},
level1:{...},
}
'''
'''返回这种格式的数据:
{level1:[
(level2: {'wanteds':[makeup1, makeup2], 'recommends':[makeup1, makeup2]}),
(level2: {...})
],
level1:[...],
}
'''
makeup_model = site_helper.getModel('Makeup')
setting_model = site_helper.getModel('WantedSetting')
settings = setting_model.getAll()
catid_key_maps = dict([(setting.MakeupCategoryid, (setting.level1, setting.level2)) for setting in settings])
dict_wanteds = {}
for wanted in wanteds:
cat_id = wanted.makeup.MakeupCategoryid
if catid_key_maps.has_key(cat_id):
key = catid_key_maps[cat_id]
dict_wanteds.setdefault(key, [])
dict_wanteds[key].append(wanted)
levels = {}
for setting in settings:
level1 = setting.level1
level2 = setting.level2
levels.setdefault(level1, [])
item = (level2,{'wanteds':dict_wanteds.get((level1, level2), []), 'recommends':recommends.get((level1, level2), [])})
if item not in levels[level1]:
levels[level1].append(item)
#原来的代码
#levels.setdefault(level1, {})
#levels[level1].setdefault(level2, {'wanteds':[], 'recommends':[]})
#levels[level1][level2]['wanteds'] = dict_wanteds.get((level1, level2), [])
#levels[level1][level2]['recommends'] = recommends.get((level1, level2), [])
return levels
示例12: loginAdminByEmail
def loginAdminByEmail(self, email, password):
email = email.strip().lower()
user = getModel('AdminUser').getOneByWhere('LOWER(email)=%s', [email])
if user and self.validatePassword(user.password, password):
return user
else:
return None
示例13: _getReviews
def _getReviews(self, user_id):
review_model = site_helper.getModel('Review')
makeup_model = site_helper.getModel('Makeup')
user_model = site_helper.getModel('User')
env = {'pagination':'ten items', 'where':('Userid=%s',[user_id]), 'orderby':'Reviewid desc'}
reviews = review_model.getAll(env)
for review in reviews:
review.username = user_model.get(review.Userid)
review.makeup = makeup_model.get(review.Makeupid)
review.comment_count = review_model.getCommentCount(review.Reviewid)
review.content_summary = site_helper.getUnicodeSummary(review.content, 100)
review.wanted_count = review_model.getWantedCount(review.Reviewid)
review.upload_image_count = site_helper.getModel('UserImage').getCount({'where':('itemtype=%s and itemid=%s',['Review', review.Reviewid])})
pagination_html = review_model.getPaginationHtml(env)
return reviews, pagination_html
示例14: assignUserInfo
def assignUserInfo(self, data, access_token):
new_data = site_helper.copy(data)
model = getModel(self.MODEL_NAME)
open_id = model.getOpenIdByAccessToken(access_token)
if open_id is None:
return new_data
url = self.getUrl('https://graph.qq.com/user/get_user_info', (
'access_token', access_token,
'oauth_consumer_key', self.APP_ID,
'openid', open_id,
'format', 'json',
))
response, content = self.getHtmlContent(url)
if response.status != 200:
return new_data
content = self.loadsJson(content)
if content.ret != 0:
return new_data
new_data['username'] = content.nickname
new_data['sex'] = content.gender
image_file = self.requestImageFile(content.figureurl_2)
if image_file is None:
return new_data
new_data['imagefile'] = image_file
return new_data
示例15: getOfficialNoticeHtml_Topic
def getOfficialNoticeHtml_Topic(self, notice):
''' ../page/user/notices/OfficialTopic.html'''
topic = getModel('Topic').get(notice.item_id)
if topic:
notice.source = 'Official'
topic.summary = site_helper.getUnicodeSummary(topic.content, 100)
return site_helper.page_render_nobase.user.notices.OfficialTopic(notice, topic) if notice else None