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


Python template.st函数代码示例

本文整理汇总了Python中vilya.libs.template.st函数的典型用法代码示例。如果您正苦于以下问题:Python st函数的具体用法?Python st怎么用?Python st使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。


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

示例1: _q_index

def _q_index(request):
    context = {}
    if request.method == "POST":
        name = request.get_form_var('name')
        password = request.get_form_var('password')
        email = request.get_form_var('email')
        description = request.get_form_var('description')

        # Forced mail format must be correct
        if not _validate_email(email):
            context['name'] = name
            context['not_validate_email'] = True
            context['password'] = password
            context['email'] = email
            context['description'] = description
            return st('users/new.html', **context)

        user = User.add(name=name,
                        password=password,
                        description=description,
                        email=email)
        if user:
            context['user'] = user
            user.set_session(request)
            request.user = user
            return request.redirect('/')
    users = User.gets_by()
    context['users'] = users
    return st('users/index.html', **context)
开发者ID:377262688,项目名称:code,代码行数:29,代码来源:__init__.py

示例2: _q_index

def _q_index(request):
    context = {}
    current_user = request.user
    if current_user and request.method == "POST":
        name = request.get_form_var('name')
        description = request.get_form_var('description')
        p = Project.add(name=name,
                        description=description,
                        owner_id=current_user.id,
                        creator_id=current_user.id)
        if p:
            return request.redirect('%s' % p.repo_name)
        has_proj = Project.get_by_name_and_owner(name, current_user.id)
        default_error = 'Create Failure. Please contact the administrator!'
        if has_proj is not None:
            context['error'] = 'Project has exists, Please confirm!'
        else:
            context['error'] = default_error
        context['current_user'] = current_user
        return st('/errors/common.html', **context)

    projects = Project.gets_by()
    context['projects'] = projects
    context['current_user'] = current_user
    return st('projects/index.html', **context)
开发者ID:000fan000,项目名称:code,代码行数:25,代码来源:__init__.py

示例3: comment

    def comment(self, request):
        target = self.target
        issue = self.issue
        issue_id = self.issue_id
        current_user = request.user

        if request.method == 'POST':
            content = request.get_form_var('content', '').decode('utf-8')
            user = request.user
            user = user.name if user else None
            if user:
                author = user
                if content.strip():
                    comment = issue.add_comment(content, user)
                    issue.add_participant(user)
                    html = st('/widgets/issue/issue_comment.html', **locals())
                else:
                    return {'error': 'Content is empty'}

                if request.get_form_var('comment_and_close'):
                    issue.close(author)
                    # TODO: 重构feed后取消信号发送
                    issue_signal.send(author=author, content=content,
                                      issue_id=issue_id)
                    dispatch('issue', data={
                             'sender': author,
                             'content': content,
                             'issue': issue,
                             })
                    return dict(r=0, reload=1, redirect_to=issue.url)
                elif request.get_form_var('comment_and_open'):
                    issue.open()
                    # TODO: 重构feed后取消信号发送
                    issue_signal.send(author=author, content=content,
                                      issue_id=issue_id)
                    dispatch('issue', data={
                             'sender': author,
                             'content': content,
                             'issue': issue,
                             })
                    return dict(r=0, reload=1, redirect_to=issue.url)
                elif content:
                    issue_comment_signal.send(author=author,
                                              content=comment.content,
                                              issue_id=comment.issue_id,
                                              comment_id=comment.id)
                    dispatch('issue_comment', data={
                             'sender': author,
                             'content': comment.content,
                             'issue': issue,
                             'comment': comment})
                participants = issue.participants

                teams = Team.get_all_team_uids()

                participants_html = st('/widgets/participation.html',
                                       **locals())  # FIXME: locals()?
                return dict(
                    r=0, html=html, participants_html=participants_html)
        return request.redirect(issue.url)
开发者ID:000fan000,项目名称:code,代码行数:60,代码来源:issue.py

示例4: _q_index

def _q_index(request):
    context = {}
    if request.method == "POST":
        name = request.get_form_var("name")
        password = request.get_form_var("password")
        email = request.get_form_var("email")
        description = request.get_form_var("description")

        # Forced mail format must be correct
        if not _validate_email(email):
            context["name"] = name
            context["not_validate_email"] = True
            context["password"] = password
            context["email"] = email
            context["description"] = description
            return st("users/new.html", **context)

        user = User.add(name=name, password=password, description=description, email=email)
        if user:
            context["user"] = user
            user.set_session(request)
            request.user = user
            return request.redirect("/")
    users = User.gets_by()
    context["users"] = users
    return st("users/index.html", **context)
开发者ID:leeccong,项目名称:code,代码行数:26,代码来源:__init__.py

示例5: _q_exception_handler

def _q_exception_handler(request, exception):
    if isinstance(exception, TraversalError):
        error = exception
        return st('/errors/404.html', **locals())
    if isinstance(exception, AccessError):
        error = exception
        return st('/errors/401.html', **locals())
    else:
        raise exception
开发者ID:000fan000,项目名称:code,代码行数:9,代码来源:__init__.py

示例6: pledge

 def pledge(self, request):
     if request.method == 'POST':
         amount = request.get_form_var('amount')
         if not amount.isdigit():
             error = '请输入承诺贡献的PR数量'
             return st('/fair/pledge.html', request=request,
                       issue=self.issue, error=error)
         amount = int(amount)
         self.issue.update_pledge(request.user, amount)
         return request.redirect(self.issue.url)
     return st('/fair/pledge.html', request=request, issue=self.issue)
开发者ID:leeccong,项目名称:code,代码行数:11,代码来源:fair.py

示例7: edit

 def edit(self, request):
     gist = self.gist
     user = request.user
     if not user or user.username != gist.owner_id:
         raise AccessError()
     if request.method == 'POST':
         desc, is_public, names, contents, oids = _get_req_gist_data(
             request)
         gist.update(desc, names, contents, oids)
         return request.redirect(gist.url)
     tdt = dict(request=request, gist=gist, user=user)
     if is_mobile_device(request):
         return st('/m/gist/edit.html', **tdt)
     return st('/gist/edit.html', **tdt)
开发者ID:000fan000,项目名称:code,代码行数:14,代码来源:gist.py

示例8: _get_tmpl_tree

def _get_tmpl_tree(tmpl_target, ref, path, project_name, request):
    project = CodeDoubanProject.get_by_name(project_name)
    if not project:
        raise TraversalError("Wrong path for tree %s" % path)
    if project.is_mirror_project:
        mirror = CodeDoubanMirror.get_by_project_id(project.id)
        if not mirror.is_clone_completed:
            return st("/projects/mirror_cloning.html", **locals())
    if not project.repo:
        raise TraversalError("Wrong path for tree %s" % path)
    if not ref:
        ref = project.default_branch

    tree_path = path.decode("utf-8")
    last_commit = project.repo.get_last_commit(ref, path=path) if ref else ""
    tdt = _tmpl_common_data(ref, path, project_name, request)
    user = tdt["user"]
    if user is not None:
        username = user.username
        cur_user_project = project.get_forked_project(username)
        if cur_user_project is not None:
            latest_branch = _latest_update_branch(cur_user_project, ref, user)
            if latest_branch:
                cur_user_latest_branch_name = "{0}:{1}".format(username, latest_branch)
                tdt["latest_update_branch"].append((cur_user_project, cur_user_latest_branch_name, latest_branch))
    tdt.update({"lastcommit": last_commit})

    tree = []
    is_empty = True
    if last_commit:
        tree = project.repo.get_tree(ref, path)
        is_empty = False if tree else True

    if is_empty and not project.repo.is_empty:
        raise TraversalError("Wrong path for tree %s" % path)

    if isinstance(tree, basestring):
        raise TraversalError("Got a blob instead of a tree")

    # Add README code to tree if any
    for item in tree:
        if item["type"] == "blob" and (item["name"] == "README" or item["name"].startswith("README.")):
            readme_content = project.repo.get_file_by_ref("%s:%s" % (ref, item["path"]))
            tdt.update({"readme_content": format_md_or_rst(item["path"], readme_content, project.name)})
            break

    tdt.update({"tree": tree, "tree_path": tree_path, "is_empty": is_empty})
    return st(tmpl_target, **tdt)
开发者ID:leeccong,项目名称:code,代码行数:48,代码来源:source.py

示例9: comment

    def comment(self, request):
        if request.method == 'POST':
            content = request.get_form_var('content').decode('utf-8')
            if not content.strip():
                return {'error': 'Content is empty!'}
            user = request.user
            current_user = request.user
            author = user.name
            comment = self.ticket.add_comment(content, author)
            ticket = self.ticket
            pullreq = self.pullreq
            project = self.project
            html = st('/pull/ticket_comment.html', **locals())

            if request.get_form_var('comment_and_close'):

                close_pull(ticket, pullreq, user, content, comment, request)

                return dict(r=0, reload=1, redirect_to=self.url)
            elif request.get_form_var('comment_and_reopen'):
                if not pullreq.is_temp_pull():
                    ticket.open(author)
                return dict(r=0, reload=1, redirect_to=self.url)
            else:
                at_users = get_mentions_from_text(content)
                for u in at_users:
                    User(u).add_invited_pull_request(ticket.id)
            return dict(r=0, html=html)
        return request.redirect(self.url)
开发者ID:000fan000,项目名称:code,代码行数:29,代码来源:pull.py

示例10: _render

 def _render(self, request, view='', error=None):
     current_user = request.user
     # TODO: user flash message
     ticket = self.ticket
     pullreq = self.pullreq
     project = self.project
     commits = self.all_commits
     try:
         diff_length = pullreq.get_diff_length()
     except:
         # FIXME: more exception detail
         diff_length = 0
     user = request.user
     has_proj_perm = project.has_push_perm(user.name) if user else False
     show_merge_guide = (has_proj_perm or user.username == ticket.author) \
         if user and not ticket.closed else False
     if not pullreq.merged and not ticket.closed:
         # FIXME: 这使得发邮件的时机有点奇怪?没人请求页面就不发吗?
         delta_commits = self.pullreq.get_delta_commits()
         if delta_commits:
             value = ','.join(c.sha for c in delta_commits)
             author = self.pullreq.from_proj.owner_name
             if self.ticket.add_commits(value, author):
                 # 补充commits则发送通知邮件给pr参与者
                 dispatch('new_commits',
                          data={
                              'pullreq': self.pullreq,
                              'ticket': self.ticket,
                              'deltacommits': delta_commits,
                          })
     return st('/pull/ticket.html', **locals())
开发者ID:000fan000,项目名称:code,代码行数:31,代码来源:pull.py

示例11: _q_index

    def _q_index(self, request):
        user = request.user
        team = self.team
        page = request.get_form_var('page', 1)
        state = request.get_form_var("state", "open")
        order = get_order_type(request, 'team_issues_order')

        team_issues = []

        selected_tag_names = request.get_form_var('tags', '')
        if selected_tag_names:
            selected_tag_names = selected_tag_names.split(',')
            issue_ids = Tag.get_type_ids_by_names_and_target_id(
                TAG_TYPE_TEAM_ISSUE,
                selected_tag_names,
                team.id)
            team_issues = self.cls.gets_by_issue_ids(issue_ids, state)
        else:
            team_issues = self.cls.gets_by_target(team.id, state, order=order)

        n_team_issue = len(team_issues)
        show_tags = team.get_group_tags(selected_tag_names)
        is_closed_tab = None if state == "open" else True
        n_pages = 1
        # TODO: 分页
        return st('issue/team_issues.html', **locals())
开发者ID:000fan000,项目名称:code,代码行数:26,代码来源:team.py

示例12: _q_index

def _q_index(request):
    errors = []
    key_lines = ''
    user = request.user
    sshkeys = user.sshkeys
    if request.method == "POST":
        key_lines = request.get_form_var('ssh')
        newsshkeys = []
        errorkeys = []
        for index, line in enumerate(key_lines.splitlines()):
            valid = SSHKey.validate(user.name, line)
            if not valid:
                errorkeys.append((index, line))
                continue
            duplicated = SSHKey.is_duplicated(user.name, line)
            if duplicated:
                errorkeys.append((index, line))
                continue
            newsshkeys.append(line)

        if not errorkeys:
            for key in newsshkeys:
                SSHKey.add(user.name, key)
            return request.redirect('/settings/ssh')

        error_prefix = 'Please check your SSH Key, Line: '
        for no, key in errorkeys:
            error = error_prefix + '%s ' % no
            errors.append(error)
    return st('/settings/ssh.html', **locals())
开发者ID:000fan000,项目名称:code,代码行数:30,代码来源:ssh.py

示例13: _q_index

def _q_index(request):
    user = request.user
    if not user:
        return request.redirect("/")
    all_rooms = Room.get_all_rooms()
    messages = get_room_message('lobby').get_messages()
    return st("chat.html", **locals())
开发者ID:000fan000,项目名称:code,代码行数:7,代码来源:chat.py

示例14: revisions

 def revisions(self, request):
     user = request.user
     gist = self.gist
     page = int(request.get_form_var('page', 1))
     skip = 3 * (page - 1)
     revlist = gist.get_revlist_with_renames(max_count=3, skip=skip)
     link_prev = _make_links(self.id, int(page) - 1, ext="revisions")
     if revlist:
         link_next = _make_links(self.id, int(page) + 1, ext="revisions")
     else:
         link_next = ''
     content = []
     for r in revlist:
         # FIXME: try-except ?
         content.append(gist.repo.get_diff(r.sha, rename_detection=True))
     tdt = {
         'request': request,
         'gist': gist,
         'content': content,
         'revlist': revlist,
         'link_prev': link_prev,
         'link_next': link_next,
         'user': user,
         'current_user': user,
     }
     return st('/gist/gist_revisions.html', **tdt)
开发者ID:000fan000,项目名称:code,代码行数:26,代码来源:gist.py

示例15: _q_index

    def _q_index(self, request):
        if self.name == 'issues':
            return request.redirect(self.team.url)

        user = request.user
        team = self.team
        page = request.get_form_var('page', 1)
        state = request.get_form_var('state', 'open')
        order = get_order_type(request, 'fair_issues_order')

        all_issues = []

        selected_tag_names = request.get_form_var('tags', '')
        if selected_tag_names:
            selected_tag_names = selected_tag_names.split(',')
            issue_ids = Tag.get_type_ids_by_names_and_target_id(
                TAG_TYPE_FAIR_ISSUE,
                selected_tag_names,
                team.id)
            all_issues = self.cls.gets_by_issue_ids(issue_ids, state)
        else:
            all_issues = self.cls.gets_by_target(team.id, state, order=order)

        n_team_issue = len(all_issues)
        show_tags = team.get_group_tags(selected_tag_names)
        is_closed_tab = None if state == 'open' else True
        n_pages = 1
        return st('/fair.html', **locals())
开发者ID:leeccong,项目名称:code,代码行数:28,代码来源:fair.py


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