本文整理汇总了Python中main.PageData类的典型用法代码示例。如果您正苦于以下问题:Python PageData类的具体用法?Python PageData怎么用?Python PageData使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了PageData类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: new_facebook_user
def new_facebook_user():
pd = PageData();
logger.info('Started Facebook new user for {}, referrer was {}'.format(request.remote_addr, request.referrer))
if not check_new_user(request, nopass=True):
pd.username = request.form['username']
pd.email = request.form['email']
return redirect_back(url_for('index'))
password = ''.join(random.choice(string.printable) for _ in range(100))
if not new_user(request.form['username'], password, request.form['email'], request.remote_addr):
return render_template('error.html', pd=pd)
user_key = 'oauth-facebook-{}'.format(session['facebook_id'])
new_key(user_key, request.form['username'])
try:
user = SiteUser.create(request.form['username'])
session['username'] = user.username
profile = user.profile()
profile.profile['facebook_id'] = session['facebook_id']
profile.update()
except (NoUser, AuthFail):
return render_template('error.html', pd=pd)
logger.info('New Facebook user {} ID {} ip {}'.format(user.username, session['facebook_id'], request.remote_addr))
flash('Welcome ' + request.form['username'])
return redirect(url_for('index'))
示例2: pm
def pm(username):
pd = PageData()
try:
pd.recipient = SiteUser.create(username)
except (NoItem, NoUser):
return page_not_found(404)
if 'username' in session:
if request.method == 'POST':
message = request.form['body']
subject = request.form['subject']
if 'parent' in request.form:
parent = deobfuscate(request.form['parent'])
else:
parent = None
if message and subject:
messageid = send_pm(pd.authuser.uid, pd.recipient.uid, subject, message, messagestatus['unread_pm'], parent)
if messageid:
flash('Message sent!')
if parent:
return redirect_back('/user/' + username + '/pm')
else:
return redirect('/user/' + pd.authuser.username + '/pm/' + obfuscate((messageid)))
else:
# TODO re-fill form
flash('No message or subject')
return redirect_back('/user/' + username + '/pm')
return render_template('sendpm.html', pd=pd)
示例3: newuser
def newuser():
pd = PageData();
pd.title = "New User"
if 'username' in session:
flash('You are already logged in.')
return redirect(url_for('index'))
else:
if request.method == 'POST':
if not check_new_user(request):
pd.username = request.form['username']
pd.email = request.form['email']
return render_template('new_user.html', pd=pd)
if not new_user(request.form['username'], request.form['password'], request.form['email'], request.remote_addr):
return render_template('error.html', pd=pd)
try:
user = SiteUser.create(request.form['username'])
user.authenticate(request.form['password'])
session['username'] = user.username
except (NoUser, AuthFail):
return render_template('error.html', pd=pd)
flash('Welcome ' + request.form['username'])
return redirect(url_for('index'))
return render_template('new_user.html', pd=pd)
示例4: admin_set_accesslevel
def admin_set_accesslevel(user, level):
"""
:URL: /admin/users/<user>/accesslevel/<level>
Change a user's access level. The user requesting the access level change must be more privileged
than the level they are setting.
Redirects back if there was an error, otherwise redirects to the user's profile.
"""
pd = PageData()
if pd.authuser.accesslevel != 255 and pd.authuser.accesslevel <= int(level):
app.logger.error('Accesslevel change was denied for user: ' + pd.authuser.username)
flash("Access level change denied.")
return redirect_back('index')
try:
moduser = SiteUser.create(user)
if pd.authuser.accesslevel != 255 and moduser.accesslevel >= pd.authuser.accesslevel:
flash("Please contact an admin to modify this user's account.")
return redirect_back('index')
except NoUser:
app.logger.error('Accesslevel change attempted for invalid user by: ' + pd.authuser.username)
pd.title = "User does not exist"
pd.errortext = "The user does not exist"
return render_template('error.html', pd=pd)
moduser.newaccesslevel(level)
flash('User ' + user + '\'s accesslevel has been set to ' + level)
return redirect_back('index')
示例5: edititem
def edititem(item_id=None):
pd = PageData()
if request.method == 'POST':
if 'username' in session:
userid = pd.authuser.uid
else:
userid = 0
if 'desc' in request.form:
if request.form['name'] == '':
flash('No name for this item?')
return redirect_back("/item/new")
try:
item = SiteItem.create(request.form['uid'])
item_id = uid_by_item(request.form['name'])
if not item_id or item_id == int(request.form['uid']):
uid = request.form['uid']
ip = request.remote_addr
if item.name != request.form['name']:
item.name = request.form['name']
item.update()
old = core.digest(item.body())
new = core.digest(request.form['desc'])
# silently discard null edits
if old != new:
new_edit(uid, request.form['desc'], userid, ip)
logger.info('item {} edited by user {} ({})'.format(uid, userid, ip))
else:
logger.info('null edit discarded for item {} by user {} ({})'.format(uid, userid, ip))
return redirect('/item/' + str(uid))
else:
flash(item.name + " already exists!")
item_id = request.form['uid']
except NoItem:
if uid_by_item(request.form['name']):
flash(request.form['name'] + " already exists!")
return redirect_back("/item/new")
uid = new_item(request.form['name'], request.form['desc'], userid, request.remote_addr)
return redirect('/item/' + str(uid))
if item_id:
try:
pd.item = SiteItem.create(item_id)
except NoItem:
return page_not_found()
pd.title="Editing: %s" % pd.item.name
else:
pd.title="Editing: New Item"
return render_template('edititem.html', pd=pd)
示例6: untag_item
def untag_item(item_id, tag_ob):
try:
item = SiteItem.create(item_id)
except NoItem:
return page_not_found()
pd = PageData()
item.remove_tag(pd.decode(tag_ob))
return redirect('/item/' + str(item.uid))
示例7: show_image
def show_image(img_id):
pd = PageData()
try:
pd.img = SiteImage.create(img_id)
pd.title=pd.img.tag
except NoImage:
return page_not_found(404)
return render_template('image.html', pd=pd)
示例8: show_user_profile
def show_user_profile(username):
pd = PageData()
pd.title = "Profile for " + username
try:
pd.profileuser = SiteUser.create(username)
except NoUser:
return page_not_found()
return render_template('profile/main.html', pd=pd)
示例9: show_user_profile_collections
def show_user_profile_collections(username):
pd = PageData()
pd.title = "Collections for " + username
pd.timezones = get_timezones()
try:
pd.profileuser = SiteUser.create(username)
except NoUser:
return page_not_found()
return render_template('profile/collections.html', pd=pd)
示例10: show_user_profile
def show_user_profile(username):
pd = PageData()
pd.title = "Profile for " + username
pd.timezones = get_timezones()
try:
pd.profileuser = SiteUser.create(username)
except NoUser:
return page_not_found(404)
return render_template('profile.html', pd=pd)
示例11: mod_tag_delete
def mod_tag_delete(tag):
pd = PageData()
tree = Tags()
decode_tag = pd.decode(tag)
parent = tree.parent_of(decode_tag)
if tree.delete(decode_tag):
return redirect('/tag/' + pd.encode(parent))
else:
flash('Unable to delete tag: ' + decode_tag)
return redirect_back('/tag/' + tag)
示例12: show_item_history
def show_item_history(item_id):
pd = PageData()
try:
showitem = SiteItem.create(item_id)
except NoItem:
return redirect("/item/" + item_id + "/edit")
pd.title = showitem.name
pd.item = showitem
return render_template('itemhistory.html', pd=pd)
示例13: show_user_profile_prefs
def show_user_profile_prefs(username):
pd = PageData()
pd.title = "Preferences for " + username
pd.timezones = get_timezones()
if not hasattr(pd, 'authuser') or pd.authuser.username != username:
return page_not_found()
try:
pd.profileuser = SiteUser.create(username)
except NoUser:
return page_not_found()
return render_template('profile/preferences.html', pd=pd)
示例14: revert_item_edit
def revert_item_edit(item_id, edit):
pd = PageData()
try:
item = SiteItem.create(item_id)
item.old = True
item.edit = edit
except NoItem:
return page_not_found()
pd.title="Reverting: " + item.name
pd.item_name = item.name
pd.item = item
return render_template('edititem.html', pd=pd)
示例15: show_image
def show_image(img_id):
"""
:URL: /image/<img_id>
Render a template for viewing an image.
"""
pd = PageData()
try:
pd.img = SiteImage.create(img_id)
pd.title=pd.img.tag
except NoImage:
return page_not_found()
return render_template('image.html', pd=pd)