當前位置: 首頁>>代碼示例>>Python>>正文


Python main.PageData類代碼示例

本文整理匯總了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'))
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:29,代碼來源:fbauth.py

示例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)
開發者ID:oamike,項目名稱:scarfage,代碼行數:34,代碼來源:pm.py

示例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)
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:28,代碼來源:user.py

示例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')
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:32,代碼來源:admin.py

示例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)
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:58,代碼來源:items.py

示例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))
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:9,代碼來源:items.py

示例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)
開發者ID:oamike,項目名稱:scarfage,代碼行數:10,代碼來源:image.py

示例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)
開發者ID:subiki,項目名稱:scarfage,代碼行數:10,代碼來源:profile.py

示例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)
開發者ID:subiki,項目名稱:scarfage,代碼行數:11,代碼來源:profile.py

示例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)
開發者ID:oamike,項目名稱:scarfage,代碼行數:11,代碼來源:profile.py

示例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)
開發者ID:oamike,項目名稱:scarfage,代碼行數:12,代碼來源:tags.py

示例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)
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:12,代碼來源:items.py

示例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)
開發者ID:subiki,項目名稱:scarfage,代碼行數:14,代碼來源:profile.py

示例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)
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:16,代碼來源:items.py

示例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)
開發者ID:cmazuc,項目名稱:scarfage,代碼行數:16,代碼來源:image.py


注:本文中的main.PageData類示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。