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


Python Chrome.format_author方法代码示例

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


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

示例1: process_request

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import format_author [as 别名]
    def process_request(self, req):
        """Process the request. For ClearSilver, return a (template_name,
        content_type) tuple, where `template` is the ClearSilver template to use
        (either a `neo_cs.CS` object, or the file name of the template), and
        `content_type` is the MIME type of the content. For Genshi, return a
        (template_name, data, content_type) tuple, where `data` is a dictionary
        of substitutions for the template.

        For both templating systems, "text/html" is assumed if `content_type` is
        `None`.

        Note that if template processing should not occur, this method can
        simply send the response itself and not return anything.
        """

        query = req.args.get('q', '').lower()
        chrome = Chrome(self.env)

        ### user names, email addressess, full names
        users = []
        USER=0; NAME=1; EMAIL=2 # indices 

        # instead of known_users, could be
        # perm = PermissionSystem(self.env)
        # owners = perm.get_users_with_permission('TICKET_MODIFY')
        # owners.sort()
        # see: http://trac.edgewall.org/browser/trunk/trac/ticket/default_workflow.py#L232

        for user_data in self.env.get_known_users(): 
            user_data = [ i is not None and chrome.format_author(req, i) or ''
                          for i in user_data ]
            for index, field in enumerate((USER, EMAIL, NAME)): # ordered by how they appear
                value = user_data[field].lower()

                if value.startswith(query):
                    users.append((2-index, user_data)) # 2-index is the sort key
                    break
                if field == NAME:
                    lastnames = value.split()[1:]
                    if sum(name.startswith(query) for name in lastnames):
                        users.append((2-index, user_data)) # 2-index is the sort key
                        break

            
        users = [ '%s|%s|%s' % (user[USER], 
                                 user[EMAIL] and '<%s> ' % user[EMAIL] or '',
                                 user[NAME])
                  for value, user in sorted(users) ] # value unused (placeholder need for sorting)

        content = '\n'.join(users)
        if isinstance(content, unicode): 
            content = content.encode('utf-8') 
        req.send_header('Content-Length', len(content))
        req.write(content)
开发者ID:sammyyu,项目名称:trac-autocompleteuserplugin,代码行数:56,代码来源:autocompleteusers.py

示例2: _insert_crashdump_data

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import format_author [as 别名]
    def _insert_crashdump_data(self, req, crashobj, data, author_id, field_changes):
        """Insert crashobj data into the template `data`"""
        replyto = req.args.get('replyto')
        data['replyto'] = replyto
        data['version'] = crashobj.resource.version
        data['description_change'] = None
        data['author_id'] = author_id

        if crashobj.resource.version is not None:
            crashobj.values.update(values)

        context = web_context(req, crashobj.resource)

        # Display the owner and reporter links when not obfuscated
        chrome = Chrome(self.env)
        for user in 'reporter', 'owner':
            if chrome.format_author(req, crashobj[user]) == crashobj[user]:
                data['%s_link' % user] = self._query_link(req, user,
                                                          crashobj[user])
        data['context'] = context
开发者ID:aroth-arsoft,项目名称:trac-crashdump,代码行数:22,代码来源:web_ui.py

示例3: cell_value

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import format_author [as 别名]
 realm = "ticket"
 parent_realm = ""
 parent_id = ""
 email_cells = []
 for header_group in header_groups:
     cell_group = []
     for header in header_group:
         value = cell_value(result[col_idx])
         cell = {"value": value, "header": header, "index": col_idx}
         col = header["col"]
         col_idx += 1
         # Detect and create new group
         if col == "__group__" and value != prev_group_value:
             prev_group_value = value
             # Brute force handling of email in group by header
             row_groups.append((value and chrome.format_author(req, value), []))
         # Other row properties
         row["__idx__"] = row_idx
         if col in self._html_cols:
             row[col] = value
         if col in ("report", "ticket", "id", "_id"):
             row["id"] = value
         # Special casing based on column name
         col = col.strip("_")
         if col in ("reporter", "cc", "owner"):
             email_cells.append(cell)
         elif col == "realm":
             realm = value
         elif col == "parent_realm":
             parent_realm = value
         elif col == "parent_id":
开发者ID:dafrito,项目名称:trac-mirror,代码行数:33,代码来源:report.py

示例4: cell_value

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import format_author [as 别名]
 parent_realm = ''
 parent_id = ''
 email_cells = []
 for header_group in header_groups:
     cell_group = []
     for header in header_group:
         value = cell_value(result[col_idx])
         cell = {'value': value, 'header': header, 'index': col_idx}
         col = header['col']
         col_idx += 1
         # Detect and create new group
         if col == '__group__' and value != prev_group_value:
             prev_group_value = value
             # Brute force handling of email in group by header
             row_groups.append(
                 (value and chrome.format_author(req, value), []))
         # Other row properties
         row['__idx__'] = row_idx
         if col in self._html_cols:
             row[col] = value
         if col in ('report', 'ticket', 'id', '_id'):
             row['id'] = value
         # Special casing based on column name
         col = col.strip('_')
         if col in ('reporter', 'cc', 'owner'):
             email_cells.append(cell)
         elif col == 'realm':
             realm = value
         elif col == 'parent_realm':
             parent_realm = value
         elif col == 'parent_id':
开发者ID:nextview,项目名称:medicticket,代码行数:33,代码来源:report.py

示例5: process_request

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import format_author [as 别名]
    def process_request(self, req):
        """Process the request. For ClearSilver, return a (template_name,
        content_type) tuple, where `template` is the ClearSilver template to use
        (either a `neo_cs.CS` object, or the file name of the template), and
        `content_type` is the MIME type of the content. For Genshi, return a
        (template_name, data, content_type) tuple, where `data` is a dictionary
        of substitutions for the template.

        For both templating systems, "text/html" is assumed if `content_type` is
        `None`.

        Note that if template processing should not occur, this method can
        simply send the response itself and not return anything.
        """

        query = req.args.get('q', '').lower()
        want_groups = req.args.get('groups')

        if want_groups:
            req.perm.require('PERMISSION_GRANT')
        if 'TICKET_CREATE' not in req.perm and 'TICKET_MODIFY' not in req.perm:
            raise PermissionError(env=self.env)

        if len(query) < 2:
            req.send('', 'text/plain')
            return

        chrome = Chrome(self.env)

        ### user names, email addressess, full names
        users = []
        USER = 0; NAME = 1; EMAIL = 2 # indices

        perm = PermissionSystem(self.env)

        groups = set()
        for user_data in self.env.get_known_users(): 
            user_data = [ i is not None and chrome.format_author(req, i) or ''
                          for i in user_data ]
            for index, field in enumerate((USER, EMAIL, NAME)): # ordered by how they appear
                value = user_data[field].lower()

                if value.startswith(query):
                    users.append((2-index, user_data)) # 2-index is the sort key
                    break
                if field == NAME:
                    lastnames = value.split()[1:]
                    if sum(name.startswith(query) for name in lastnames):
                        users.append((2-index, user_data)) # 2-index is the sort key
                        break
            for provider in perm.store.group_providers:
                groups.update(provider.get_permission_groups(user_data[USER]))

        groups = sorted(['%s||group' % (group,) for group in groups if group.lower().startswith(query)])
        
        users = [ '%s|%s|%s' % (user[USER], 
                                 user[EMAIL] and '&lt;%s&gt;' % user[EMAIL] or '',
                                 user[NAME])
                  for value, user in sorted(users) ] # value unused (placeholder need for sorting)

        if want_groups and groups:
            users.extend(groups)

        users = users[:3] # Limit only to three results

        req.send('\n'.join(users).encode('utf-8'), 'text/plain')
开发者ID:trac-hacks,项目名称:trac-autocompleteusers,代码行数:68,代码来源:autocompleteusers.py

示例6: describe_tagged_resource

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import format_author [as 别名]
 def describe_tagged_resource(self, req, resource):
     # The plugin already uses the title as main description
     post = BlogPost(self.env, resource.id)
     chrome = Chrome(self.env)
     return "'" + resource.id + "' by " \
                                 + chrome.format_author(req, post.author)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:8,代码来源:tags.py

示例7: _render_view

# 需要导入模块: from trac.web.chrome import Chrome [as 别名]
# 或者: from trac.web.chrome.Chrome import format_author [as 别名]

#.........这里部分代码省略.........
            elif col[0] == '_':                             # _col
                header['hidden'] = True
            elif col[-1] == '_':                            # col_
                header_groups.append([])
            header_group.append(header)

        # Structure the rows and cells:
        #  - group rows according to __group__ value, if defined
        #  - group cells the same way headers are grouped
        chrome = Chrome(self.env)
        row_groups = []
        authorized_results = []
        prev_group_value = None
        for row_idx, result in enumerate(results):
            col_idx = 0
            cell_groups = []
            row = {'cell_groups': cell_groups}
            realm = self.realm
            parent_realm = ''
            parent_id = ''
            email_cells = []
            for header_group in header_groups:
                cell_group = []
                for header in header_group:
                    value = cell_value(result[col_idx])
                    cell = {'value': value, 'header': header, 'index': col_idx}
                    col = header['col']
                    col_idx += 1
                    # Detect and create new group
                    if col == '__group__' and value != prev_group_value:
                        prev_group_value = value
                        # Brute force handling of email in group by header
                        row_groups.append(
                            (value and chrome.format_author(req, value), []))
                    # Other row properties
                    row['__idx__'] = row_idx
                    if col in self._html_cols:
                        row[col] = value
                    if col in ('report', 'ticket', 'id', '_id'):
                        row['id'] = value
                    # Special casing based on column name
                    col = col.strip('_')
                    if col in ('reporter', 'cc', 'owner'):
                        email_cells.append(cell)
                    elif col == 'realm':
                        realm = value
                    elif col == 'parent_realm':
                        parent_realm = value
                    elif col == 'parent_id':
                        parent_id = value
                    cell_group.append(cell)
                cell_groups.append(cell_group)
            if parent_realm:
                resource = Resource(realm, row.get('id'),
                                    parent=Resource(parent_realm, parent_id))
            else:
                resource = Resource(realm, row.get('id'))
            # FIXME: for now, we still need to hardcode the realm in the action
            if resource.realm.upper()+'_VIEW' not in req.perm(resource):
                continue
            authorized_results.append(result)
            if email_cells:
                for cell in email_cells:
                    emails = chrome.format_emails(context.child(resource),
                                                  cell['value'])
                    result[cell['index']] = cell['value'] = emails
开发者ID:pkdevbox,项目名称:trac,代码行数:70,代码来源:report.py


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