示例#1
0
    def process_request(self, req):
        req.perm.require('TAGS_VIEW')
        add_ctxtnav(req, 'Cloud', req.href.tags())
        match = re.match(r'/tags/?(.*)', req.path_info)
        if match.group(1):
            req.redirect(req.href('tags', q=match.group(1)))
        add_stylesheet(req, 'tags/css/tractags.css')
        query = req.args.get('q', '')
        data = {'title': 'Tags'}
        formatter = Formatter(self.env,
                              Context.from_request(req, Resource('tag')))

        realms = [p.get_taggable_realm() for p in self.tag_providers]
        checked_realms = [r for r in realms if r in req.args] or realms
        data['tag_realms'] = [{
            'name': realm,
            'checked': realm in checked_realms
        } for realm in realms]

        if query:
            data['tag_title'] = 'Showing objects matching "%s"' % query
        data['tag_query'] = query

        from tractags.macros import TagCloudMacro, ListTaggedMacro
        if not query:
            macro = TagCloudMacro(self.env)
        else:
            macro = ListTaggedMacro(self.env)
        query = '(%s) (%s)' % (' or '.join(
            ['realm:' + r for r in realms if r in checked_realms]), query)
        self.env.log.debug('Tag query: %s', query)
        try:
            data['tag_body'] = macro.expand_macro(formatter, None, query)
        except InvalidQuery, e:
            data['tag_query_error'] = to_unicode(e)
            data['tag_body'] = TagCloudMacro(self.env) \
                .expand_macro(formatter, None, '')
示例#2
0
    def process_request(self, req):
        req.perm.require('TAGS_VIEW')
        add_ctxtnav(req, 'Cloud', req.href.tags())
        match = re.match(r'/tags/?(.*)', req.path_info)
        if match.group(1):
            req.redirect(req.href('tags', q=match.group(1)))
        add_stylesheet(req, 'tags/css/tractags.css')
        query = req.args.get('q', '')
        data = {'title': 'Tags'}
        formatter = Formatter(
            self.env, Context.from_request(req, Resource('tag'))
            )

        realms = [p.get_taggable_realm() for p in self.tag_providers]
        checked_realms = [r for r in realms if r in req.args] or realms
        data['tag_realms'] = [{'name': realm, 'checked': realm in checked_realms}
                              for realm in realms]

        if query:
            data['tag_title'] = 'Showing objects matching "%s"' % query
        data['tag_query'] = query

        from tractags.macros import TagCloudMacro, ListTaggedMacro
        if not query:
            macro = TagCloudMacro(self.env)
        else:
            macro = ListTaggedMacro(self.env)
        query = '(%s) (%s)' % (' or '.join(['realm:' + r for r in realms
                                            if r in checked_realms]), query)
        self.env.log.debug('Tag query: %s', query)
        try:
            data['tag_body'] =  macro.expand_macro(formatter, None, query)
        except InvalidQuery, e:
            data['tag_query_error'] = to_unicode(e)
            data['tag_body'] = TagCloudMacro(self.env) \
                .expand_macro(formatter, None, '')
示例#3
0
    def filter_stream(self, req, method, filename, stream, data):
        """Return a filtered Genshi event stream, or the original unfiltered
        stream if no match.

        `req` is the current request object, `method` is the Genshi render
        method (xml, xhtml or text), `filename` is the filename of the template
        to be rendered, `stream` is the event stream and `data` is the data for
        the current template.

        See the Genshi documentation for more information.
        """

        if filename in ('ticket.html', 'agilo_ticket_new.html',):

            add_stylesheet(req, 'tags/css/tractags.css')
            add_stylesheet(req, 'loomingclouds/css/tagcloud.css')
            add_script(req, 'loomingclouds/js/tag_filler.js')
            formatter = Formatter(self.env, Context.from_request(req))
            macro = TagCloudMacro(self.env)
            cloud = macro.expand_macro(formatter, 'TagCloud', '')

            stream |= Transformer("//input[@id='field-keywords']").after(cloud).after(tag.a('More...',href='#',class_='tag-cloud-filler'))

        return stream
示例#4
0
    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.
        """

        # get the GeoTicket component
        assert self.env.is_component_enabled(GeoTicket)
        geoticket = GeoTicket(self.env)

        # add the query script
        add_script(req, 'common/js/query.js')

        # get the panel configuration
        config = self.panels()

        # build the panels
        panels = []
        located_tickets = geoticket.tickets_with_location()
        for panel in config:

            # query the tickets
            query_string = panel['query']
            query = Query.from_string(self.env, query_string)

            # decide the date to sort by
            if query.order == 'time':
                date_to_display = 'time_created'
            else:
                date_to_display = 'time_changed'
            results = query.execute(req)
            n_tickets = len(results)
            results = [
                result for result in results if result['id'] in located_tickets
            ]
            locations = []
            tickets = []
            results = results[:self.dashboard_tickets]
            for result in results:
                ticket = Ticket(self.env, result['id'])
                try:

                    address, (lat, lon) = geoticket.locate_ticket(ticket)
                    content = geoticket.feature_content(req, ticket)

                    # style for the markers
                    style = {}
                    for extension in self.marker_style:
                        style.update(extension.style(ticket, req, **style))
                    style = style or None

                    locations.append({
                        'latitude': lat,
                        'longitude': lon,
                        'style': style,
                        'content': Markup(content)
                    })
                    tickets.append(ticket)
                except GeolocationException:
                    continue

            title = panel['label']
            panels.append({
                'title': title,
                'id': panel['id'],
                'locations': Markup(simplejson.dumps(locations)),
                'tickets': tickets,
                'n_tickets': n_tickets,
                'date_to_display': date_to_display,
                'query_href': query.get_href(req.href)
            })

        # add the tag cloud, if enabled
        cloud = None
        if self.display_cloud:
            if TagCloudMacro is None:
                self.log.warn(
                    "[geo] display_cloud is set but the TagsPlugin is not installed"
                )
            else:
                formatter = Formatter(self.env, Context.from_request(req))
                macro = TagCloudMacro(self.env)
                cloud = macro.expand_macro(formatter, 'TagCloud', '')
                add_stylesheet(req, 'tags/css/tractags.css')
                add_stylesheet(req, 'tags/css/tagcloud.css')

        # compile data for the genshi template
        data = dict(panels=panels,
                    cloud=cloud,
                    openlayers_url=self.openlayers_url)
        return ('mapdashboard.html', data, 'text/html')
示例#5
0
    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.
        """

        # get the GeoTicket component
        assert self.env.is_component_enabled(GeoTicket)
        geoticket = GeoTicket(self.env)

        # add the query script
        add_script(req, 'common/js/query.js')

        # get the panel configuration
        config = self.panels()

        # build the panels
        panels = []
        located_tickets = geoticket.tickets_with_location()
        for panel in config:

            # query the tickets
            query_string = panel['query']
            query = Query.from_string(self.env, query_string)

            # decide the date to sort by
            if query.order == 'time':
                date_to_display = 'time_created'
            else:
                date_to_display = 'time_changed'
            results = query.execute(req)
            n_tickets = len(results)
            results = [ result for result in results if result['id'] in located_tickets ]
            locations = []
            tickets = []
            results = results[:self.dashboard_tickets]
            for result in results:
                ticket = Ticket(self.env, result['id'])
                try:
                
                    address, (lat, lon) = geoticket.locate_ticket(ticket)
                    content = geoticket.feature_content(req, ticket)

                    # style for the markers
                    style = {}
                    for extension in self.marker_style:
                        style.update(extension.style(ticket, req, **style))
                    style = style or None

                    locations.append({'latitude': lat,
                                      'longitude': lon,
                                      'style': style,
                                      'content': Markup(content)})
                    tickets.append(ticket)
                except GeolocationException:
                    continue

            title = panel['label']
            panels.append({'title': title,
                           'id': panel['id'],
                           'locations': Markup(simplejson.dumps(locations)),
                           'tickets': tickets,
                           'n_tickets': n_tickets,
                           'date_to_display': date_to_display,
                           'query_href': query.get_href(req.href)})

        # add the tag cloud, if enabled
        cloud = None
        if self.display_cloud:
            if TagCloudMacro is None:
                self.log.warn("[geo] display_cloud is set but the TagsPlugin is not installed")
            else:
                formatter = Formatter(self.env, Context.from_request(req))
                macro = TagCloudMacro(self.env)
                cloud = macro.expand_macro(formatter, 'TagCloud', '')
                add_stylesheet(req, 'tags/css/tractags.css')
                add_stylesheet(req, 'tags/css/tagcloud.css')

        # compile data for the genshi template
        data = dict(panels=panels,
                    cloud=cloud,
                    openlayers_url=self.openlayers_url)
        return ('mapdashboard.html', data, 'text/html')