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


Python api.Context类代码示例

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


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

示例1: convert_content

    def convert_content(self, req, input_type, text, output_type):
        page_name = req.args.get('page', 'WikiStart')
        wikipage = WikiPage(self.env, page_name)
        
        wikiprint = WikiPrint(self.env)
        
        page = wikiprint.wikipage_to_html(text, page_name, req)
        
        #Get page title from first header in outline
        out = StringIO.StringIO()
        context = Context(Resource('wiki', page_name), req.abs_href, req.perm)
        context.req = req

        outline = OutlineFormatter(self.env, context)
        outline.format(text, out, 1, 1)
        
        title = wikipage.name
        for depth, anchor, text in outline.outline:
            if depth == 1:
                title = text
                break
        
        out = wikiprint.html_to_pdf(req, [page], book = (output_type == 'pdfbook'),
            title=title,
            subject="%s - %s" % (self.env.project_name, page_name),
            version=str(wikipage.version),
            date=format_datetime(to_datetime(None)))
        return (out, 'application/pdf')
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:28,代码来源:wikiprint.py

示例2: get_project_events

    def get_project_events(self, project, days, minutes):
        """ List all events in project that happened in a given time span.
        """
        events = []
        project_href = Href(conf.url_projects_path + "/" + project.env_name)

        req = DummyReq('user', 'password', 'method', 'uri', 'args')
        req.permissions = (
        'TICKET_VIEW', 'CHANGESET_VIEW', 'WIKI_VIEW', 'ATTACHMENT_VIEW', 'DISCUSSION_VIEW', 'MILESTONE_VIEW')
        req.authname = 'authname'
        req.abs_href = project_href

        project_env = open_environment(conf.getEnvironmentSysPath(project.env_name), use_cache=True)
        event_provider = ProjectTimelineEvents(project_env)
        last_events = event_provider.get_timeline_events(req,
            time_in_days=days,
            time_in_minutes=minutes)

        for event in last_events:
            context = Context(resource=Resource(), href=project_href)
            context.req = req
            context.perm = req.perm
            events.append([project, event, context])

        events.sort(lambda x, y: cmp(y[1]['date'], x[1]['date']))
        return events
开发者ID:alvabai,项目名称:trac-multiproject,代码行数:26,代码来源:watchlist_events.py

示例3: email_default_context

def email_default_context():
    class NoEmailViewPerm(MockPerm):
        def has_permission(self, action, realm_or_resource=None, id=False, version=False):
            return action != "EMAIL_VIEW"

        __contains__ = has_permission

    context = Context(Resource("wiki", "WikiStart"), href=Href("/"), perm=NoEmailViewPerm())
    context.req = None  # 0.12 FIXME .req shouldn't be required by formatter
    return context
开发者ID:wiraqutra,项目名称:photrackjp,代码行数:10,代码来源:wikisyntax.py

示例4: wikipage_to_html

    def wikipage_to_html(self, text, page_name, req):
        """
        Converts a wiki text to HTML, and makes some replacements in order to fix
        internal and external links and references
        """

        self.env.log.debug('WikiPrint => Start function wikipage_to_html')

        #Remove exclude expressions
        for r in EXCLUDE_RES:
            text = r.sub('', text)
        
        #Escape [[PageOutline]], to avoid wiki processing
        for r in [re.compile(r'\[\[TOC(\(.*\))?\]\]'), re.compile(r'\[\[PageOutline(\(.*\))?\]\]')]:
            text = r.sub('![[pdf-toc]]', text)
            
        for macro in self.omit_macros:
            r = re.compile(r'\[\[' + macro + r'\(.*?\]\]')
            text = r.sub('', text)
            r = re.compile(r'^\{\{\{\r?\n#!' + macro + r'\r?\n(^.*\r?\n)*?^\}\}\}', re.MULTILINE)
            text = r.sub('', text)

        link_format = req.args.get('link_format', None)
            
        if self.omit_links:
            r1 = re.compile(r'\[wiki:(.*?) (.*?)\]')
            text = r1.sub('[\g<2>]', text)            
            r2 = re.compile(r'\[wiki:(.*?)\]')
            text = r2.sub('[\g<1>]', text)            
        elif link_format:
            #Keep links to the same export format
            r = re.compile(r'(?<=\[wiki:)(.*?)(?=(?: .*?)?\])')
            text = r.sub('\g<1>?format=%s&link_format=%s' % (link_format, link_format), text)
            
        if self.rebase_links:
            r = re.compile(r'\[wiki:(.*?)\]')
            text = r.sub('[%s/wiki/\g<1>]' % self.rebase_links, text)

        self.env.log.debug('WikiPrint => Wiki input for WikiPrint: %r' % text)
        
        #First create a Context object from the wiki page
        context = Context(Resource('wiki', page_name), req.abs_href, req.perm)
        context.req = req
        
        #Now convert in that context
        page = format_to_html(self.env, context, text)
        self.env.log.debug('WikiPrint => Wiki to HTML output: %r' % page)
        
        self.env.log.debug('WikiPrint => HTML output for WikiPrint is: %r' % page)
        self.env.log.debug('WikiPrint => Finish function wikipage_to_html')

        return page
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:52,代码来源:wikiprint.py

示例5: get_list_pages

def get_list_pages(request, dbp, obj, resource):
    require_permission(request.req, resource, dbp.env)

    artifact_id = request.req.args.get('artifact', None)
    if artifact_id is None:
        raise Exception("No artifact was specified.")
    dbp.load_artifact(artifact_id)
    artifact = dbp.pool.get_item(artifact_id)

    results = []
    for pagename, page_version_id, ref_count in dbp.get_wiki_page_ref_counts(artifact):
        page = WikiPage(dbp.env, pagename)

        results.append(
            {'href': get_resource_url(dbp.env, page.resource, request.req.href),
             'title': pagename,
             'date': user_time(request.req, format_datetime, page.time),
             'author': page.author,
             'excerpt': shorten_result(page.text)}
        )

    data = {
        'context': Context.from_request(request.req, resource),
        'artifact': artifact,
        'results': results,
    }
    return 'list_pages.html', data, None
开发者ID:filipefigcorreia,项目名称:TracAdaptiveSoftwareArtifacts,代码行数:27,代码来源:views.py

示例6: template_data

 def template_data(self, req, query, kwargs=None):
     db = self.env.get_read_db()
     tickets = query.execute(req, db)
     filtered_tickets = [ticket for ticket in tickets if 'TICKET_VIEW' in req.perm(Ticket(self.env, int(ticket['id'])).resource)]
     context = Context.from_request(req, 'query')
     return query.template_data(context, filtered_tickets, None,
                                datetime.now(req.tz), req)
开发者ID:KKBOX,项目名称:trac-ticket-calendar-plugin,代码行数:7,代码来源:web_ui.py

示例7: wiki_to_html

    def wiki_to_html(self, wikitext, req):
        self.env.log.debug('start function wiki_to_html') # pylint: disable-msg=E1101

        # Remove some macros (TOC is better handled in ODT itself)
        for macro in self.remove_macros:
            wikitext = re.sub('\[\[%s(\([^)]*\))?\]\]' % macro, "", wikitext)

        # Now convert wiki to HTML
        out = StringIO()
        context = Context.from_request(req, absurls=True)
        Formatter(self.env, # pylint: disable-msg=E1101
                  context('wiki', self.page_name)).format(wikitext, out)
        html = Markup(out.getvalue())
        html = html.encode("utf-8", 'replace')

        # Clean up the HTML
        html = re.sub('<span class="icon">.</span>', '', html) # Remove external link icon
        tidy_options = dict(output_xhtml=1, add_xml_decl=1, indent=1,
                            tidy_mark=0, input_encoding='utf8',
                            output_encoding='utf8', doctype='auto',
                            wrap=0, char_encoding='utf8')
        html = tidy.parseString(html, **tidy_options)
        # Replace nbsp with entity:
        # http://www.mail-archive.com/[email protected]/msg03670.html
        html = str(html).replace("&nbsp;", "&#160;")
        # Tidy creates newlines after <pre> (by indenting)
        html = re.sub('<pre([^>]*)>\n', '<pre\\1>', html)
        return html
开发者ID:xfguo,项目名称:odtexportplugin,代码行数:28,代码来源:odtexport.py

示例8: process_request

 def process_request(self, req):
     page_name = req.args.get('page_name', '')
     if page_name == '':
         page_name = 'index'
     
     # Add breadcrumb
     package_name, filename = self._get_package_and_filename(page_name)
     index_file = filename[:-len('.txt')] + '/index.txt'
     
     if not self._resource_exists(package_name, filename):
         # check if it is a folder, then match with index
         if self._resource_exists(package_name, index_file):
             filename = index_file
         else:
             error_msg = _('Page %(page_name)s not found', page_name=page_name)
             raise ResourceNotFound(error_msg)
     
     utf8_string = resource_string(package_name, filename)
     help_contents = utf8_string.decode('UTF-8')
     # add navigation bar
     self._set_prev_next(req)
     
     data = dict(context=Context.from_request(req), contents=help_contents,
                 page_name=page_name)
     return ('agilo_help.html', data, 'text/html')
开发者ID:djangsters,项目名称:agilo,代码行数:25,代码来源:web_ui.py

示例9: expand_macro

    def expand_macro(self, formatter, name, content):
        # Example: [[ASA(42)]]
        args, kw = parse_args(content)
        args = [arg.strip() for arg in args]
        if not args or not args[0].isdigit():
            raise TracError('Custom artifact id not specified')
        args, kw = parse_args(content)
        if not args or not args[0].isdigit():
            raise TracError('Custom artifact id not specified')
        artifact_id = int(args[0])
        dbp = DBPool(self.env, InstancePool())
        try:
            dbp.load_artifact(id=artifact_id)
        except ValueError:
            return system_message("Custom Artifact not found", "No custom artifact was found for id '{0}'.".format(artifact_id))
        artifact = dbp.pool.get_item(id=artifact_id)
        artifact_url = formatter.req.href.customartifacts('artifact/{0}'.format(artifact.get_id()))
        res = Core._get_resource(artifact) if not artifact in (Entity, Instance, None) and not type(artifact)==unicode else None
        spec_name, spec_url, values = _get_artifact_details(artifact, formatter.req)

        tpl='view_artifact_dialog.html'
        data = {
            'context': Context.from_request(formatter.req, res),
            'spec_name': spec_name,
            'spec_url': spec_url,
            'artifact': artifact,
            'artifact_url': artifact_url,
            'artifacts_values': values,
        }
        return Chrome(self.env).render_template(formatter.req, tpl, data, None, fragment=True)
开发者ID:filipefigcorreia,项目名称:TracAdaptiveSoftwareArtifacts,代码行数:30,代码来源:__init__.py

示例10: _do_ticket

 def _do_ticket(self, req, template, data, content_type):
     if 'ticket' in data and 'linked_tickets' in data:
         ticket = data['ticket']
         context = Context.from_request(req, ticket.resource)
         
         # Add name:#n links to link fields of Ticket instance when
         # flowing from storage to browser
         if req.method == 'GET':
             RemoteLinksProvider(self.env).augment_ticket(ticket)
         
         # Rerender link fields
         for field in data['fields']:
             if field['type'] == 'link':
                 name = field['name']
                 field['rendered'] = format_to_oneliner(self.env, context,
                                                        ticket[name])
         
         # Add RemoteTicket objects for linked issues table, and pass list
         # of rejects that could not be retrieved
         linked_tickets, linked_rejects = self._remote_tickets(ticket,
                                                               context)
         data['linked_tickets'].extend(linked_tickets)
         data['linked_rejects'].extend(linked_rejects)
     
     # Provide list of remote sites if newlinked form options are present
     if 'newlinked_options' in data:
         remote_sites = RemoteTicketSystem(self.env).get_remote_tracs()
         data['remote_sites'] = remote_sites
     
     return (template, data, content_type)
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:30,代码来源:web_ui.py

示例11: get_edit_artifact

def get_edit_artifact(request, dbp, obj, resource):
    require_permission(request.req, resource, dbp.env, operation="MODIFY")

    assert(isinstance(obj, Instance)) # otherwise, we're trying to edit something that is not an artifact

    aa_attributes = [name for name, val in obj.get_values()]
    attr_suggestions = [attr.name for attr in obj.get_attributes() if not attr.name in aa_attributes]

    values = []
    for name,val in obj.get_values():
        if type(val) is list:
            for v in val:
                values.append((str(uuid.uuid4()), name, v))
        else:
            values.append((str(uuid.uuid4()), name, val))

    # track access
    dbp.track_it("artifact", obj.get_id(), "edit", request.req.authname, str(datetime.now()))

    data = {
        'context': Context.from_request(request.req, resource),
        'spec_name': obj.__class__.get_name() if not obj.__class__ == Instance else "",
        'artifact': obj,
        'artifact_values': values,
        'attr_suggestions' : attr_suggestions,
        'default': obj.str_attr,
        'url_path': request.req.href.customartifacts('artifact', obj.get_id()),
        }
    return 'edit_artifact_%s.html' % (request.get_format(),), data, None
开发者ID:filipefigcorreia,项目名称:TracAdaptiveSoftwareArtifacts,代码行数:29,代码来源:views.py

示例12: _convert_query

    def _convert_query(self, req, query, sheet_query=True,
                       sheet_history=False):
        # no paginator
        query.max = 0
        query.has_more_pages = False
        query.offset = 0

        # extract all fields except custom fields
        cols = ['id']
        cols.extend(f['name'] for f in query.fields if not f.get('custom'))
        cols.extend(name for name in ('time', 'changetime')
                         if name not in cols)
        query.cols = cols

        if hasattr(self.env, 'get_read_db'):
            db = self.env.get_read_db()
        else:
            db = self.env.get_db_cnx()
        tickets = query.execute(req, db)
        # add custom fields to avoid error to join many tables
        custom_fields = [f['name'] for f in query.fields if f.get('custom')]
        self._fill_custom_fields(tickets, custom_fields, db)

        context = Context.from_request(req, 'query', absurls=True)
        cols.extend([name for name in custom_fields if name not in cols])
        data = query.template_data(context, tickets)

        book = Workbook(encoding='utf-8', style_compression=1)
        if sheet_query:
            self._create_sheet_query(req, context, data, book)
        if sheet_history:
            self._create_sheet_history(req, context, data, book)
        return get_workbook_content(book), 'application/vnd.ms-excel'
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:33,代码来源:ticket.py

示例13: process_request

 def process_request(self, req):
     # Allow all POST requests (with a valid __FORM_TOKEN, ensuring that
     # the client has at least some permission). Additionally, allow GET
     # requests from TRAC_ADMIN for testing purposes.
     if req.method != 'POST':
         req.perm.require('TRAC_ADMIN')
         
     # @todo: Embed "tips" within the rendered output for the editor
     # (recognize TracLinks, table-stuff, macros, processors)
     # @todo: Save the content in server-side user-specific field for recovery
     
     realm = req.args.get('realm', 'wiki')
     id = req.args.get('id')
     version = req.args.get('version')
     if version is not None:
         try:
             version = int(version)
         except ValueError:
             version = None
     text = req.args.get('text', '')
     flavor = req.args.get('flavor')
     options = {}
     if 'escape_newlines' in req.args:
         options['escape_newlines'] = bool(int(req.args['escape_newlines']
                                               or 0))
     if 'shorten' in req.args:
         options['shorten'] = bool(int(req.args['shorten'] or 0))
     
     resource = Resource(realm, id=id, version=version)
     context = Context.from_request(req, resource)
     rendered = format_to(self.env, flavor, context, text, **options)
     req.send(rendered.encode('utf-8'))
开发者ID:nyuhuhuu,项目名称:trachacks,代码行数:32,代码来源:__init__.py

示例14: pre_process_request

    def pre_process_request(self, req, handler):
        if req.path_info.startswith('/wiki'):
            if req.method == 'POST' and req.args.get('action','view') == 'view':
                post_handler = None
                for poster in self.macro_posters:
                    if not hasattr(poster, 'match_macro_post'): continue
                    rv = poster.match_macro_post(req)
                    if isinstance(rv, (str, unicode)):
                        rv = rv in req.args.keys()
                    if rv:
                        post_handler = poster
                        break
                if post_handler:
                    post_handler.process_macro_post(req)
                else:
                    # Silly stuff here
                    self.log.debug('MacroPostModule: Unclaimed POST, scanning page %s', req.path_info[6:])
                    page = WikiPage(self.env, req.path_info[6:])
                    matches = self.macro_re.findall(page.text) + self.proc_re.findall(page.text)
                    for name in matches:
                        self.log.debug('MacroPostModule: Found macro "%s"', name)
                        resource = Resource('wiki', name)
                        context = Context.from_request(req, resource)
                        wp = WikiProcessor(Formatter(self.env, context), name)
                        if wp.macro_provider is None:
                            self.log.debug('MacroPostModule: Invalid name!!! How did that happen')
                            continue
                        if hasattr(wp.macro_provider, 'process_macro_post') and \
                           not hasattr(wp.macro_provider, 'match_macro_post'):
                            wp.macro_provider.process_macro_post(req)
                req.environ['REQUEST_METHOD'] = 'GET' # Revert back to a GET

        return handler
开发者ID:okamototk,项目名称:kanonconductor,代码行数:33,代码来源:web_ui.py

示例15: _handle_builder

 def _handle_builder(self, req):
     m = self.BUILDER_RE.match(req.path_info)
     try:
         builder = m.group(1) or None
     except Exception as e:
         builder = None
     master = BuildBotSystem(self.buildbot_url)
     if builder is None:
         data = {'names': master.getAllBuilders()}
         return 'bbw_allbuilders.html', data, 'text/html'
     else:
         class Foo:
             pass
         b = Foo()
         b.name = str(builder)
         b.current = 'CURRENT-TEXT'
         b.recent = []
         b.slaves = []
         data = {'builder': b}
         try:
             master = BuildBotSystem(self.buildbot_url)
             data = {'builder': master.getBuilder(builder)}
         except Exception as e:
             print('Error fetching builder stats', e)
         data['context'] = Context.from_request(req, ('buildbot', builder))
         return 'bbw_builder.html', data, 'text/html'
开发者ID:rapyuta,项目名称:buildbot,代码行数:26,代码来源:web_ui.py


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