当前位置: 首页>>代码示例>>Python>>正文


Python User.get_by方法代码示例

本文整理汇总了Python中models.User.get_by方法的典型用法代码示例。如果您正苦于以下问题:Python User.get_by方法的具体用法?Python User.get_by怎么用?Python User.get_by使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.User的用法示例。


在下文中一共展示了User.get_by方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: wiki_page

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def wiki_page(user_slug, wiki_slug, page_slug):
    """ Renders a wiki's page.
    -> user's slugified name; wiki's slugified title; page's slugified title
    """
    try:
        user = User.get_by(name_slug=user_slug)
    except NoResultFound:
        flash("This user does not exist,<br />\
            and consequently, their wiki does not either.")
        return redirect(url_for('main'))
    try:
        wiki = user.wiki_by_slug(wiki_slug)
    except NoResultFound:
        flash("This wiki either is private or does not exist.")
        return redirect(url_for('main'))
    try:
        page = wiki.page_by_slug(page_slug)
    except NoResultFound:
        return redirect(url_for('wiki', user_slug=user_slug, 
            wiki_slug=wiki_slug))
    if wiki.permission_to_view(user):
        return render_template('page.html', user=user, wiki=wiki, page=page)
    else:
        flash("This wiki either is private or does not exist.")
        return redirect(url_for('main'))
开发者ID:aostrega,项目名称:piki,代码行数:27,代码来源:piki.py

示例2: delete_wiki

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def delete_wiki(user_slug, wiki_slug):
    """ Deletes a wiki.
    -> user's slugified name, wiki's slugified title
    """
    try:
        user = User.get_by(name_slug=user_slug)
    except NoResultFound:
        flash("This user does not exist,<br />\
            and consequently, their wiki does not either.")
        return redirect(url_for('main'))
    try:
        wiki = user.wiki_by_slug(wiki_slug)
    except NoResultFound:
        flash("This wiki either is private or does not exist.")
        return redirect(url_for('main'))
    if user is g.user:
        title = wiki.title
        pages = get_all(Page, wiki=wiki)
        for page in pages:
            if page in models.session.new:
                page.expunge()
            else:
                page.delete()
        if wiki in models.session.new:
            wiki.expunge()
        else:
            wiki.delete()
        models.session.commit()
        flash("Deletion of %s was a success." % title)
    else:
        flash("That is not your wiki, silly.")
    return redirect(url_for('main'))
开发者ID:aostrega,项目名称:piki,代码行数:34,代码来源:piki.py

示例3: wiki

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def wiki(user_slug, wiki_slug):
    """ Renders a wiki's main page.
    -> user's slugified name; wiki's slugified title
    """
    try:
        user = User.get_by(name_slug=user_slug)
    except NoResultFound:
        flash("This user does not exist,<br />\
            and consequently, their wiki does not either.")
        return redirect(url_for('main'))
    try:
        wiki = user.wiki_by_slug(wiki_slug)
    except NoResultFound:
        if user_slug == g.user.name_slug:
            flash("This wiki does not exist.")
        else:
            flash("This wiki either is private or does not exist.")
        return redirect(url_for('main'))
    if request.method == 'POST':
        title = request.form['title']
        try:
            Page.get_by(title_slug=slugify(title))
        except NoResultFound:
            page = Page(wiki=wiki, title=title, title_slug=slugify(title), 
                content="<h1>%s</h1><p></p>" % title)
            models.session.commit()
        return redirect(url_for('wiki_page', user_slug=user.name_slug, 
            wiki_slug=wiki.title_slug, page_slug=slugify(title)))
    else:
        page = wiki.page_by_slug(wiki_slug)
    if wiki.permission_to_view(g.user):
        return render_template('page.html', user=user, wiki=wiki, page=page)
    else:
        flash("This wiki either is private or doesn't exist.")
        return redirect(url_for('main'))
开发者ID:aostrega,项目名称:piki,代码行数:37,代码来源:piki.py

示例4: signup

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def signup():
    """ Creates a user based on the fields of a sign up form.
    -] name - desired username
         password - desired password 
         email - desired email
    """
    if request.method == 'POST':
        f = request.form
        name_slug = slugify(f['name'])
        # Make sure everything checks out.
        if not f['name']:
            flash("You must choose a name.")
            return redirect(url_for('main'))
        elif not f['email']:
            flash("You must enter your email.")
            return redirect(url_for('main'))
        elif not f['password']:
            flash("You must choose a password.")
            return redirect(url_for('main'))
        else:
            # TODO: Make this nicer.
            try:
                if User.get_by(name_slug=name_slug):
                    flash("Someone already chose that name.")
                    return redirect(url_for('main'))
            except NoResultFound:
                try:
                    if User.get_by(email=f['email']):
                        flash("Someone is already using that email.")
                        return redirect(url_for('main'))
                except NoResultFound:
                    pass
            
        # Create the user and log in.
        name_slug = slugify(f['name'])
        hashed_password = generate_password_hash(f['password'])
        user = User(name=f['name'], name_slug=name_slug, \
            password=hashed_password, email=f['email'])
        session['name'] = f['name']
        if models.local:
            user.verified = True
        else:
            user.send_verification_email()
        models.session.commit()
        return redirect(url_for('main'))
    elif request.method == 'GET':
        return redirect(url_for('main'))
开发者ID:aostrega,项目名称:piki,代码行数:49,代码来源:piki.py

示例5: before_request

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def before_request():
    """ Accounts for the logged in user before every request function. """
    if 'name' in session:
        try:
            g.user = User.get_by(name=session['name'])
        except NoResultFound:
            session['name'] = None
            g.user = None
    else:
        g.user = None
开发者ID:aostrega,项目名称:piki,代码行数:12,代码来源:piki.py

示例6: get_user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def get_user():
    import cherrypy
    from elixir import session as db_session

    db_session.clear()
    from models import User

    try:
        return User.get_by(id=cherrypy.session.get("User").id)
    except AttributeError:
        return None
开发者ID:adeel,项目名称:razgovore,代码行数:13,代码来源:util.py

示例7: remove

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
    def remove(self, event):
        remove_dial = wx.MessageDialog(None, u'Tem certeza que deseja excluir o usuário?', 'Sair', wx.YES_NO | wx.NO_DEFAULT | wx.ICON_QUESTION)
        ret = remove_dial.ShowModal()
        if ret == wx.ID_YES:
            user1 = User.get_by(id=int(self.idTextCtrl.GetValue()))
            user1.delete()
            session.commit()
            remove_dial.Destroy()
            self.refreshIndex(None)
            self.getNext(None)

        else:
            event.Veto()
开发者ID:leandrobraga,项目名称:maat,代码行数:15,代码来源:WindowUser.py

示例8: user

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def user(name_slug):
    """ Renders a user's page
    -> user's slugified name
    """
    try:
        user = User.get_by(name_slug=name_slug)
    except NoResultFound:
        flash("This user does not exist.")
        return redirect(url_for('main'))
    published_wikis = []
    for wiki in user.wikis:
        if wiki.publicity == 2:
            published_wikis.append(wiki)
    print published_wikis
    return render_template('user.html', user=user, 
        published_wikis=published_wikis)
开发者ID:aostrega,项目名称:piki,代码行数:18,代码来源:piki.py

示例9: wiki_settings

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def wiki_settings(user_slug, wiki_slug):
    """ Updates the settings of a wiki.
    -> user's slugified name; wiki's slugified title
    """
    try:
        user = User.get_by(name_slug=user_slug)
    except NoResultFound:
        return "error! user does not exist"
    if user != g.user:
        return "error! unauthorized user"
    try:
        wiki = user.wiki_by_slug(wiki_slug)
    except NoResultFound:
        return "error! wiki does not exist"
    if request.method == 'POST':
        f = request.form
        main_page = Page.get_by(wiki=wiki, title=wiki.title)
        wiki.title = f['title'] or "Untitled"
        wiki.title_slug = slugify(f['title'])
        main_page.title = wiki.title
        main_page.title_slug = wiki.title_slug
        title_start = 4
        title_end = 4 + len(main_page.title)
        title = re.compile(r"(<h1>)(.*)(</h1>)")
        main_page.content = title.sub(r"\1%s\3" % wiki.title, 
            main_page.content)
        publicity = {
            'private': 0,
            'hidden': 1,
            'public': 2
        }
        if f['publicity'] == 'public' and not user.verified:
            wiki.publicity = publicity['hidden']
        else:
            wiki.publicity = publicity[f['publicity']]
        wiki.autosave = 1 if f['autosave'] == 'on' else 0
        models.session.commit()
        return slugify(f['title'])
    else:
        publicity = [False]*3
        publicity[wiki.publicity] = True
        return render_template('settings.html', user=user, wiki=wiki, 
            publicity=publicity, settings=True)
开发者ID:aostrega,项目名称:piki,代码行数:45,代码来源:piki.py

示例10: verify

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def verify(user_slug, code):
    """ Verifies a user.
    -> user's slugified name; user's verification code
    """
    try:
        user = User.get_by(name_slug=user_slug)
    except NoResultFound:
        flash("This user does not exist.")
        return redirect(url_for('main'))
    if user.verified:
        flash("This user is already verified.")
        return redirect(url_for('main'))
    if code == user.verification_code():
        user.verified = 1
        models.session.commit()
        flash("Verification was a success.")
        return redirect(url_for('main'))
    else:
        flash("That verification code is incorrect.")
        return redirect(url_for('main'))
开发者ID:aostrega,项目名称:piki,代码行数:22,代码来源:piki.py

示例11: blank_page

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def blank_page(user_slug, wiki_slug):
    """ Renders an untitled blank wiki page for the author.
    -> user's slugified name; wiki's slugified title
    """
    try:
        user = User.get_by(name_slug=user_slug)
    except NoResultFound:
        flash("This user does not exist,<br />\
            and consequently, their wiki does not either.")
        return redirect(url_for('main'))
    if user != g.user:
        return redirect(url_for('wiki', user_slug=user_slug, 
            wiki_slug=wiki_slug))
    try:
        wiki = user.wiki_by_slug(wiki_slug)
    except NoResultFound:
        flash("This wiki either is private or does not exist.")
        return redirect(url_for('main'))
    if not g.user or g.user.name_slug != user_slug:
        return redirect(url_for('wiki', user_slug=user_slug, 
            wiki_slug=wiki_slug))
    return render_template('page.html', user=user, wiki=wiki, page=None)
开发者ID:aostrega,项目名称:piki,代码行数:24,代码来源:piki.py

示例12: login

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def login():
    """ Logs in a user if the name and password match. 
    -] name - username
       password - user's password
    """
    if request.method == 'POST':
        f = request.form
        # Try to log in as user.
        try:
            user = User.get_by(name=f['name'])
        except NoResultFound:
            flash("A user with that name does not exist.")
            return redirect(url_for('main'))
        # If the password is correct, log the user in.
        if check_password_hash(user.password, f['password']):
            session['name'] = f['name']
            return redirect(url_for('main'))
        else:
            forgot_url = url_for('forgot_password', name=user.name_slug)
            flash("That password is incorrect.")
            return redirect(url_for('main'))
    else:
        return redirect(url_for('main'))
开发者ID:aostrega,项目名称:piki,代码行数:25,代码来源:piki.py

示例13: update_index

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def update_index(user_slug, wiki_slug):
    """ Update the order of pages in the index after a page is moved.
    -] page - the name of the moved page
       previously_preceding_page - the page that used to be behind 'page'
       new_preceding_page - the page that is now behind 'page'
    <- a string denoting success
    """
    user = User.get_by(name_slug=user_slug)
    if user != g.user:
        return False
    wiki = user.wiki_by_slug(wiki_slug)
    f = request.form
    ppp_name = f['previously_preceding']
    page_name = f['page']
    new_preceding_page_name = f['new_preceding']
    try:
        previously_preceding_page = Page.get_by(wiki=wiki, title=ppp_name)
    except NoResultFound:
        pass
    page = Page.get_by(wiki=wiki, title=page_name)
    try:
        new_preceding_page = Page.get_by(wiki=wiki, 
            title=new_preceding_page_name)
    except NoResultFound:
        pass
    if page.id == wiki.first_page_id:
        wiki.first_page_id = page.next_page_id
    else:
        previously_preceding_page.next_page_id = page.next_page_id
    if new_preceding_page:
        page.next_page_id = new_preceding_page.next_page_id
        new_preceding_page.next_page_id = page.id
    else:
        page.next_page_id = wiki.first_page_id
        wiki.first_page_id = page.id
    models.session.commit()
    return "Success!"
开发者ID:aostrega,项目名称:piki,代码行数:39,代码来源:piki.py

示例14: save

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
def save(user_slug, wiki_slug, page_slug):
    """ Saves page changes in the database.
    -] patch - array of changed content blocks; 'undefined' if unchanged
    <- slugified page title
    """ 
    user = User.get_by(name_slug=user_slug)
    if user != g.user:
        return False
    wiki = user.wiki_by_slug(wiki_slug)
    try:
        page = wiki.page_by_slug(page_slug)
    except NoResultFound:
        old_last_page = Page.get_by(wiki=wiki, next_page_id=-1)
        page = Page(wiki=wiki, title="", title_slug="", 
            content="<h1>Untitled</h1>", next_page_id=-1)
        models.session.commit()
        old_last_page.next_page_id = page.id
    patch = request.form.getlist('patch')
    block = re.compile('<(?:h1|h2|h3|p)>.*?</(?:h1|h2|h3|p)>')
    content_blocks = block.findall(page.content)
    # If the page's title has been changed in the content...
    new_title = page.title
    if len(patch) and patch[0] != 'undefined':
        new_title = patch[0][4:-5]
        newline = re.compile('\n')
        new_title = re.sub(newline, "", new_title)
    if page.title != new_title:
        # ..if a page exists with this title, append " (alternative)" to it.
        try:
            same_title_page = Page.get_by(title=new_title)
        except NoResultFound:
            pass
        if same_title_page:
            stp = same_title_page
            header_end = 4 + len(stp.title)
            stp.title += " (alternative)"
            stp.title_slug = slugify(stp.title)
            stp.content = stp.content[:header_end] + " (alternative)" + \
                stp.content[header_end:]
        # ..if the page with changed title was the main page, make a new one.
        if page.title == wiki.title:
            try:
                if new_title:
                    second_page = page
                else:
                    second_page = Page.get_by(id=page.next_page_id)
                next_page_id = second_page.id
            except NoResultFound:
                next_page_id = -1
            new_main_page = Page(wiki=wiki, title=wiki.title, 
                title_slug=slugify(wiki.title), 
                content="<h1>%s</h1><p></p>" % wiki.title, 
                next_page_id=next_page_id)
            models.session.commit()
            wiki.first_page_id = new_main_page.id
        # ..change the page's title in the database.
        page.title = new_title
        page.title_slug = slugify(new_title)
    # Replace content with patched content.
    for i, block in enumerate(patch):
        if block != 'undefined':
            if i < len(content_blocks):
                content_blocks[i] = block
            else:
                content_blocks.append(block)
    # Sanitize unsafe angle brackets.
    content = ''.join(content_blocks)
    unsafe_lt = re.compile(r"<(?!/?(h1|h2|h3|p|b|i|u)>)")
    content = re.sub(unsafe_lt, '&lt;', content)
    # The content is reversed to get around regex lookbehind limitation.
    unsafe_gt = re.compile(r">(?!(1h|2h|3h|p|b|i|u)/?<)")
    content = re.sub(unsafe_gt, ';tg&', content[::-1])
    page.content = content[::-1]
    # If the title is blank, delete the page.
    deleted = False
    blank_title = re.compile('<h1>(<br>)*</h1>')
    if blank_title.match(page.content):
        try:
            previous_page = Page.get_by(wiki=wiki, next_page_id=page.id)
            previous_page.next_page_id = page.next_page_id
        except NoResultFound:
            pass
        page.delete()
        deleted = True
    # Update the wiki's update date.
    wiki.update_date = datetime.now()
    # Commit to database!
    models.session.commit()
    if not deleted:
        return slugify(page.title)
    else:
        return "untitled!"
开发者ID:aostrega,项目名称:piki,代码行数:94,代码来源:piki.py

示例15: save

# 需要导入模块: from models import User [as 别名]
# 或者: from models.User import get_by [as 别名]
    def save(self,event):
        if self.idTextCtrl.GetValue() != '':

            if self.valida(int(self.idTextCtrl.GetValue()),self.nameTextCtrl.GetValue(),self.loginTextCtrl.GetValue()):
                user1 = User.get_by(id=self.idTextCtrl.GetValue())
                user1.name = self.nameTextCtrl.GetValue().title()
                user1.login = self.loginTextCtrl.GetValue().lower()

                if self.passwordTextCtrl.IsEditable():

                    if self.validaPassword(self.passwordTextCtrl.GetValue(), self.confirmPasswordTextCtrl.GetValue()):
                        user1.password = unicode(hashlib.sha1(self.passwordTextCtrl.GetValue()).hexdigest())
                    else:
                        return 0
                if self.cb.GetValue():
                    user1.level = 0
                else:
                    user1.level = 1

                session.commit()
                self.refreshIndex(self.idTextCtrl.GetValue())
                self.message = wx.MessageDialog(None, u'Usuário alterado com sucesso!', 'Info', wx.OK)
                self.message.ShowModal()

                self.idTextCtrl.SetEditable(False)
                self.nameTextCtrl.SetEditable(False)
                self.loginTextCtrl.SetEditable(False)
                self.cb.Disable()
                self.passwordTextCtrl.SetValue('')
                self.passwordTextCtrl.SetEditable(False)
                self.passwordTextCtrl.Disable()
                self.confirmPasswordTextCtrl.SetValue('')
                self.confirmPasswordTextCtrl.SetEditable(False)
                self.confirmPasswordTextCtrl.Disable()

                self.toolBar.EnableTool(ID_TOOLBAR_USER_FIRST, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_LAST, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_PREVIOUS, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_NEXT, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_NEW, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_SAVE, False)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_REMOVE, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_EDIT, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_FIND, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_CANCEL, False)

        else:

            if self.valida(self.idTextCtrl.GetValue(),self.nameTextCtrl.GetValue(),self.loginTextCtrl.GetValue()) and self.validaPassword(self.passwordTextCtrl.GetValue(),self.confirmPasswordTextCtrl.GetValue()):
                if self.cb.GetValue():
                    level = 0
                else:
                    level = 1

                user1 = User(name=self.nameTextCtrl.GetValue().title(),login=self.loginTextCtrl.GetValue().lower(),level=level,password=unicode(hashlib.sha1(self.passwordTextCtrl.GetValue()).hexdigest()))
                session.commit()

                self.refreshIndex(user1.id)
                self.idTextCtrl.SetValue(unicode(user1.id))
                self.message = wx.MessageDialog(None, u'Usuário cadastrado com sucesso!', 'Info', wx.OK)
                self.message.ShowModal()

                self.idTextCtrl.SetEditable(False)
                self.nameTextCtrl.SetEditable(False)
                self.loginTextCtrl.SetEditable(False)
                self.cb.Disable()
                self.passwordTextCtrl.SetValue('')
                self.passwordTextCtrl.Disable()
                self.passwordTextCtrl.SetEditable(False)
                self.confirmPasswordTextCtrl.SetValue('')
                self.confirmPasswordTextCtrl.Disable()
                self.confirmPasswordTextCtrl.SetEditable(False)


                self.toolBar.EnableTool(ID_TOOLBAR_USER_FIRST, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_LAST, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_PREVIOUS, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_NEXT, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_NEW, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_SAVE, False)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_REMOVE, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_EDIT, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_FIND, True)
                self.toolBar.EnableTool(ID_TOOLBAR_USER_CANCEL, False)
开发者ID:leandrobraga,项目名称:scp,代码行数:86,代码来源:userWindow.py


注:本文中的models.User.get_by方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。