本文整理汇总了Python中util.render函数的典型用法代码示例。如果您正苦于以下问题:Python render函数的具体用法?Python render怎么用?Python render使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了render函数的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
def post(self):
name = self.request.get('name')
#uid = TODO get User ID
#create levelSet
util.render(self, 'set/read.html', {'name': name})
示例2: recover_password_get
def recover_password_get(self):
if web.ctx.query == '':
qs = dict()
else:
# XXX: http://bugs.python.org/issue8136
qs = parse_qs(urllib.unquote(web.ctx.query[1:]).encode('latin-1').decode('utf-8'))
if not (qs.has_key('id') and qs.has_key('key')):
return util.render().error(error_message = _('INVALID_LINK'),
help_context = 'error')
user_id = qs['id'][0]
key = qs['key'][0]
uid = user._get_uid_from_username(user_id)
if uid < 0:
return util.render().error(error_message = _('INVALID_USERNAME'),
help_context = 'error')
if user.get_password_salt(uid) != key:
return util.render().error(error_message = _('INVALID_PASSWORD_KEY'),
help_context = 'error')
self.session_set(user_id)
web.ctx.session.persistent = False
user.update_last_login(uid, web.ctx.ip)
new_pw = user.generate_random_password()
user.update_password(uid, new_pw)
return util.render().error(error_message = _('Your temporary password is "%s"(case-sensitive). Change password now.') % new_pw,
error_class = _('Information'))
示例3: get
def get(self, key):
if not len(key):
return util.error(self, 404, 'No level specified')
lvl = db.get(db.Key(key))
if not lvl:
return util.error(self, 404, 'Level not found')
util.render(self, 'level/read.html', {'level': lvl.getDict(), 'title': lvl.title})
示例4: pp
def pp(info):
pos = info['pos']
if pos == 'n':
cases_ja = [latin1.cases_ja[case[0:3]] + case[3:6] for case in info['case'].split('/')]
return util.render([pos, info['base'], info['case'], info['gender'], info['ja'], cases_ja])
else:
return util.render(info)
示例5: create_board_post
def create_board_post(self, board_name, board_id, current_uid = -1):
board_info = board.get_board_info(board_id)
if not acl.is_allowed('board', board_id, current_uid, 'create'):
return util.render().error(error_message = _('NO_PERMISSION'), help_context='error')
user_data = web.input()
comment = 1 if user_data.has_key('commentable') else 0
write_by_other = 1 if user_data.has_key('writable') else 0
indexable = 1 if user_data.has_key('indexable') else 0
show_avatar = 1 if user_data.has_key('show_avatar') else 0
owner_uid = user._get_uid_from_username(user_data.owner)
if owner_uid < 0:
return util.render().error(error_message=_('NO_SUCH_USER_FOR_BOARD_ADMIN'), help_context='error')
if user_data.name.strip() == '':
return util.render().error(error_message = _('NO_NAME_SPECIFIED'), help_context='error')
if board_name == '^root':
new_path = posixpath.join('/', user_data.name)
else:
new_path = posixpath.join('/', board_name, user_data.name)
if board._get_board_id_from_path(new_path) > 0:
return util.render().error(error_message = _('BOARD_EXISTS'), help_context='error')
settings = dict(path=new_path, board_owner = owner_uid,
cover = user_data.information,
description = user_data.description,
type = int(user_data.type),
guest_write = write_by_other,
can_comment = comment,
indexable = indexable, show_avatar = show_avatar,
current_uid = current_uid)
ret = board.create_board(board_id, settings)
if ret[0] == False:
return util.render().error(error_message = ret[1] ,help_context = 'error')
raise web.seeother(util.link('%s') % (new_path))
示例6: lost_login_post
def lost_login_post(self):
data = web.input()
recaptcha_url = 'http://www.google.com/recaptcha/api/verify'
recaptcha_data = dict(challenge = data.recaptcha_challenge_field,
response = data.recaptcha_response_field,
remoteip = web.ctx.ip,
privatekey = config.recaptcha_private_key)
req = urllib2.Request(recaptcha_url, urllib.urlencode(recaptcha_data))
response = urllib2.urlopen(req)
page = response.read().split('\n')
if page[0] == 'false':
if page[1].strip() == 'incorrect-captcha-sol':
return util.render().error(error_message = _('INCORRECT_CAPTCHA'), help_context='error')
else:
return util.render().error(error_message = _('CAPTCHA_ERROR'), help_context='error')
found_users = user.get_user_from_email(data.email)
if not found_users:
return util.render().error(error_message = _('NO_SUCH_MAIL_ADDRESS'), help_context='error')
salt_string = ''
for u in found_users:
salt = user.get_password_salt(u.uSerial)
salt_string = salt_string + '* User %s: http://noah.kaist.ac.kr/+recover_password?id=%s&key=%s\n' % (u.uId, u.uId, salt)
message_title = _('NOAH password recovery')
message_body = _('''Dear NOAH user,
Some user on IP %s requested new password of your account(s). Following list contains your account(s). Click on the corresponding link for recovering password of account.
%s
If you did not requested password recovery, then please log in into your account. This link will not be vaild after logging into the account.''') % (web.ctx.ip, salt_string)
mail.mail(data.email, message_title, message_body)
return util.render().error(error_message = _('Message Sent. Please follow instructions on the message.'),
error_class = _('Information'))
示例7: modify_post
def modify_post(self, board_name, board_id, current_uid = -1):
board_info = board.get_board_info(board_id)
if not acl.is_allowed('board', board_id, current_uid, 'modify'):
return util.render().error(error_message=_('NO_PERMISSION'), help_context='error')
data = web.input()
comment = 1 if data.has_key('commentable') else 0
write_by_other = 1 if data.has_key('writable') else 0
indexable = 1 if data.has_key('indexable') else 0
show_avatar = 1 if data.has_key('show_avatar') else 0
owner_uid = user._get_uid_from_username(web.input().owner)
if owner_uid < 0:
return util.render().error(error_message=_('NO_SUCH_USER_FOR_BOARD_ADMIN'), help_context='error')
board_info = dict(path = data.path, name = data.name,
owner = owner_uid, board_type = int(data.type),
can_comment = comment, can_write_by_other = write_by_other,
indexable = indexable, show_avatar = show_avatar,
stylesheet = data.stylesheet,
description = data.description,
cover = data.information)
result = board.board_edit(current_uid, board_id, board_info)
if result[0] == False:
return util.render().error(error_message = result[1], help_context='error')
else:
raise web.seeother(util.link('%s') % result[1])
示例8: modify_post
def modify_post(self, current_uid = -1):
user_id = current_uid
usr = user.get_user(user_id)[1]
data = web.input(profile_image = {})
if data.newpass1 and not user.verify_password(user_id, data.oldpass):
return util.render().error(error_message=_('INVALID_PASSWORD'), help_context='error')
if data.newpass1 != data.newpass2:
return util.render().error(error_message = _('PASSWORD_DO_NOT_MATCH'), help_context='error')
if len(data.newpass1) > 0 and len(data.newpass1) < 6:
return util.render().error(error_message = _('PASSWORD_TOO_SHORT'), help_context='error')
if len(data.newpass1) == 0:
password = data.oldpass
else:
password = data.newpass1
nick = data.nick
email = data.email
homepage = data.homepage
sig = data.sig
introduction = data.introduction
language = data.language
theme = data.theme
user_info = user.get_user(user_id)
change_lang = False
if language != user_info[1].language:
change_lang = True
profile_image = data.profile_image.value
delete_profile_image = data.has_key('delete_profile_image')
ret = user.modify_user(user_id, locals())
if change_lang:
web.ctx.session.lang = language
raise web.seeother(util.link('/+u'))
示例9: callback
def callback(request):
auth_user(request.cookies.get('auth'))
if g.user:
return util.redirect('/')
oauth_client = oauth2.Client2(
oauth_settings['client_id'],
oauth_settings['client_secret'],
oauth_settings['base_url']
)
code = request.GET.get('code')
if not code:
return util.render('error.pat', user=None,
error="no code")
try:
data = oauth_client.access_token(code, oauth_settings['redirect_url'])
except Exception as e:
return util.render('error.pat', user=None,
error="failed to get access token, try again")
access_token = data.get('access_token')
(headers, body) = oauth_client.request(
'https://api.github.com/user',
access_token=access_token,
token_param='access_token'
)
error = 0
try:
if headers['status'] == '200':
user = json.loads(body)
username = user['login']
email = user.get('email', '')
else:
error = 1
except Exception as e:
error = 1
if error:
return util.render('error.pat', user=None, error='bad login, try again')
user = get_user_by_name(username)
if not user:
#create new user
auth, msg = create_user_github(username, email)
if not auth:
return util.render('error.pat', user=None, error=msg)
else:
if 'g' in user['flags']:
auth = user['auth']
else:
return util.render('error.pat', user=None, error='account exists :(')
res = webob.exc.HTTPTemporaryRedirect(location='/')
res.headers['Set-Cookie'] = 'auth=' + auth + \
'; expires=Thu, 1 Aug 2030 20:00:00 UTC; path=/';
return res
示例10: GET
def GET(self, username, current_uid = -1):
user_id = user._get_uid_from_username(username)
if user_id < 0:
raise web.notfound(util.render().error(error_message = _('NO_SUCH_USER'), help_context='error'))
return util.render().myinfo(user = user.get_user(user_id)[1],
user_id = user_id,
title = _('User Information'), board_desc = _('User Information'),
help_context='myinfo')
示例11: get
def get(self):
#get key
ls = models.getUserLevelSet()
self.redirect("/levelSet/" + str(ls.key()))
return
#old stuff
levelSets = models.getUserLevelSets()
util.render(self, 'user/read.html', {'levelSets': levelSets, 'user': models.getCurrentUser()})
示例12: caller
def caller(self, board_name, action, article_id, method):
board_id = board._get_board_id_from_path(board_name)
if board_id < 0:
raise web.notfound(util.render().error(error_message = _('INVALID_BOARD'), help_context='error'))
try:
return eval('self.%s_%s' % (action, method))(board_name, board_id, int(article_id))
except AttributeError:
raise web.notfound(util.render().error(error_message = _('INVALID_ACTION'), help_context='error'))
示例13: search_byname_view
def search_byname_view(request):
error_message = None
bank = request.user.get_profile().bank
if request.POST:
#name_terms = request.POST['namecontains']
# TODO: I am a terrible person.
name_terms = request.POST['term1']
if request.POST['term2'] != "":
name_terms += " " + request.POST['search_type'].upper() + " " + \
request.POST['term2']
if request.POST['term3'] != "":
name_terms += " " + request.POST['search_type'].upper() + " " + \
request.POST['term3']
if request.POST['term4'] != "":
name_terms += " " + request.POST['search_type'].upper() + " " + \
request.POST['term4']
logger.info(name_terms)
if len(name_terms.strip()) < 1:
error_message = "No search terms entered!"
else:
if " AND " in name_terms:
# split on any AND's and strip any remaining whitespace
name_contains = [a.strip() for a in name_terms.split(' AND ')]
risks = BankRisk.objects.filter(bank=bank)
for i in name_contains:
risks = risks.filter(
name__contains=i,
)
else:
# split on any OR's and strip any remaining whitespace
name_contains = [a.strip() for a in name_terms.split(' OR ')]
risks = []
for i in name_contains:
risks.extend(BankRisk.objects.filter(
bank=bank,
name__contains=i,
))
# set the search results session var
# request.session['search_results'] = risks
return render('search_results.html',
{ 'risks': risks,
'method': "by Name",
'search_again': "name", },
request)
return render('search_byname.html',
{ 'error_message': error_message },
request)
示例14: newspage
def newspage(request, news_id):
auth_user(request.cookies.get('auth'))
news = get_news_by_id(news_id)
if not news:
return util.render('error.pat', user=g.user,
error="the news does not exist")
hack_news(news)
return util.render('news.pat', user=g.user, news=news)
示例15: documentation
def documentation(request, path='documentation'):
if '.' in path[-5:]:
template = 'documentation/%s' % path
else:
template = 'documentation/%s.html' % path
try:
return render(template, request, context_dict={'navigation_pos': 'documentation'})
except TemplateDoesNotExist:
return render('coming-soon.html', request, context_dict={'navigation_pos': 'documentation'})