• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Python template.st函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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


示例16: search

 def search(self, request):
     key_word = request.get_form_var('q')
     if not key_word:
         return self._index(request)
     status = request.get_form_var('status')
     user = request.user
     page = request.get_form_var('page', 1)
     project = self.project
     tickets = []
     ticket_len = Ticket.get_count_by_proj_id(project.id)
     search_result = PullRequestSearch.search_a_phrase(
         key_word, project.id, size=ticket_len)
     if search_result and not search_result.get('error'):
         ticket_ids = [id for id, in SearchEngine.decode(
             search_result, ['ticket_id'])]
         tickets = Ticket.gets_by_projectid_and_ticketnumbers(
             project.id, ticket_ids)
         if status == "closed":
             tickets = [t for t in tickets if t.closed]
         else:
             tickets = [t for t in tickets if not t.closed]
     ticket_total_len = len(tickets)
     limit = TICKETS_COUNT_PER_PAGE
     start = TICKETS_COUNT_PER_PAGE * (int(page) - 1)
     tickets = tickets[start:start + limit]
     n_pages = (ticket_total_len - 1) / TICKETS_COUNT_PER_PAGE + 1
     if status == "closed":
         is_closed_tab = True
     else:
         is_closed_tab = False
     open_tab_link = self.open_tab_link
     close_tab_link = self.close_tab_link
     return st('/pull/pulls.html', **locals())
开发者ID:000fan000,项目名称:code,代码行数:33,代码来源:pull.py


示例17: _q_index

def _q_index(request):
    user = request.user
    if user:
        all = request.get_form_var('all')
        scope = request.get_form_var('scope')
        unread = not all or all != '1'
        scope = ActionScope.getScope(scope) or ''  # 不带scope则默认所有

        actions = Notification.get_data(user.name)

        # 迁移数据
        all_actions = [migrate_notif_data(action, user.name)
                       for action in actions]

        if scope:
            actions = [action for action in all_actions
                       if action.get('scope') == scope]
        else:
            actions = all_actions

        if unread:
            actions = [action for action in actions if not action.get('read')]
            count_dict = {s: len([a for a in all_actions
                          if a.get('scope') == s and not a.get('read')])
                          for s in ActionScope.all_scopes}
        else:
            count_dict = {s: len([a for a in all_actions
                          if a.get('scope') == s])
                          for s in ActionScope.all_scopes}
        count_dict['all'] = sum(count_dict.values())

        return st('notifications.html', **locals())
    else:
        return request.redirect("/hub/teams")
开发者ID:000fan000,项目名称:code,代码行数:34,代码来源:notification.py


示例18: add_team

def add_team(request):
    user = request.user
    if not user:
        return request.redirect("/")

    uid = request.get_form_var('uid') or ''
    name = request.get_form_var('name') or ''
    description = request.get_form_var('description') or ''

    errors = ""
    if request.method == "POST":
        teams = Team.gets()
        team_uid_pattern = re.compile(r'[a-zA-Z0-9\_]*')
        if not uid:
            error = 'uid_not_exists'
        elif not name:
            error = 'name_not_exists'
        elif uid != re.findall(team_uid_pattern, uid)[0]:
            error = 'invilid_uid'
        elif uid in [team.uid for team in teams]:
            error = 'uid_existed'
        elif User.check_exist(uid):
            error = 'user_id_existed'
        elif name in [team.name for team in teams]:
            error = 'name_existed'
        else:
            team = Team.add(uid, name, description)
            if team:
                team_created_signal.send(user.name,
                                         team_name=team.name,
                                         team_uid=team.uid)
                team.add_user(user, TEAM_OWNER)
                return request.redirect(team.url)

    return st('/teams/add_team.html', **locals())
开发者ID:000fan000,项目名称:code,代码行数:35,代码来源:__init__.py


示例19: _q_lookup

 def _q_lookup(self, request, revrange):
     current_user = request.user
     try:
         sha1, sha2 = revrange.split('...')
     except ValueError:
         raise TraversalError(
             'please provide valid start & end revisions: /compare/sha1...sha2')  # noqa
     project = self.project
     commits = project.repo.get_commits(sha2, sha1)
     if commits is False:
         raise TraversalError()
     lasttime = commits and commits[0].author_time.strftime(
         "%Y-%m-%d %H:%M:%S") or 'UNKNOWN'
     grouped_commits = groupby(commits, lambda c: c.author_time.date())
     n_commits = len(commits)
     n_authors = len(set(c.author.username for c in commits))
     diff = project.repo.get_diff(sha2,
                                  from_ref=sha1,
                                  rename_detection=True)
     #diffs = project.git.get_3dot_diff(sha1, sha2)
     n_files = diff.length if diff else 0
     comments = []
     for ci in commits:
         comments.extend(Comment.gets_by_proj_and_ref(project.id, ci.sha))
     branches = project.repo.branches
     tags = project.repo.tags
     ref = project.default_branch
     n_comments = len(comments)
     ref_type = 'branch' if ref in branches else 'tag' \
                if ref in tags else 'tree'
     return st('compare.html', **locals())
开发者ID:000fan000,项目名称:code,代码行数:31,代码来源:compare.py


示例20: _q_index

def _q_index(request):
    user = request.user
    my_issues = []
    if user:
        username = user.username

        your_projects = CodeDoubanProject.get_projects(owner=username,
                                                       sortby='lru')
        watched_projects = CodeDoubanProject.get_watched_others_projects_by_user(  # noqa
            user=username,
            sortby='lru')

        teams = Team.get_by_user_id(user.name)
        actions = get_user_inbox(username).get_actions(
            stop=PAGE_ACTIONS_COUNT - 1)
        badge_items = user.get_badge_items()

        # pull request
        # your_tickets = user.get_user_pull_requests_rank(limit=5)
        your_tickets = user.get_user_submit_pull_requests(limit=5)

        # issue
        project_ids = CodeDoubanProject.get_ids(user.name)
        dt = {
            'state': "open",
            'limit': 5,
            'start': 0,
        }
        my_issues = ProjectIssue.gets_by_project_ids(project_ids, **dt)

        return st('newsfeed.html', **locals())
    return request.redirect("/teams/")
开发者ID:000fan000,项目名称:code,代码行数:32,代码来源:__init__.py



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Python issue.Issue类代码示例发布时间:2022-05-26
下一篇:
Python store.execute函数代码示例发布时间:2022-05-26
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap