Ejemplo n.º 1
0
    def get_namespace(self, resource, context):
        # title
        title = resource.get_title(fallback=False)
        menu = resource.get_resource(resource.order_path)
        handler = menu.handler

        is_active = resource.get_property('active')
        ids = list(handler.get_record_ids_in_order())
        if not ids or not is_active:
            return {'content': None,
                    'title': title,
                    'display': False,
                    'admin_bar': None}

        if resource.get_property('random'):
            id = choice(ids)
        else:
            id = ids[0]

        record = handler.get_record(id)
        data = handler.get_record_value(record, 'data')
        here = context.resource
        content = set_prefix(data, prefix='%s/' % here.get_pathto(menu))
        # admin bar
        admin_bar = get_admin_bar(resource)

        return {'content': content,
                'title': title,
                'display': True,
                'admin_bar': admin_bar}
Ejemplo n.º 2
0
Archivo: skin.py Proyecto: hforge/itws
    def build_footer_namespace(self, context):
        data = self.footer_data
        ns = get_menu_namespace(context,
            data['depth'], data['show_first_child'],
            flat=data['flat'], src=data['src'])

        here = context.resource
        # Manipulate directly the table handler
        footer = context.site_root.get_resource('%s/menu' % data['src'])
        handler = footer.handler
        records = list(handler.get_records_in_order())
        get_value = handler.get_record_value
        prefix = here.get_pathto(footer)
        # HOOK the namespace
        for index, item in enumerate(ns.get('items', [])):
            record = records[index]
            title = get_value(record, 'title')
            path = get_value(record, 'path')
            html_content = get_value(record, 'html_content')
            item['html'] = None
            if not path and not title and html_content:
                html = set_prefix(html_content, '%s/' % prefix)
                item['html'] = html
        ns['separator'] = data.get('separator', '|')

        # admin bar
        ns['admin_bar'] = get_admin_bar(footer.parent) # menu folder

        return ns
Ejemplo n.º 3
0
    def build_footer_namespace(self, context):
        data = self.footer_data
        ns = get_menu_namespace(context, data["depth"], data["show_first_child"], flat=data["flat"], src=data["src"])

        here = context.resource
        # Manipulate directly the table handler
        footer = context.site_root.get_resource("%s/menu" % data["src"])
        handler = footer.handler
        records = list(handler.get_records_in_order())
        get_value = handler.get_record_value
        prefix = here.get_pathto(footer)
        # HOOK the namespace
        for index, item in enumerate(ns.get("items", [])):
            record = records[index]
            title = get_value(record, "title")
            path = get_value(record, "path")
            html_content = get_value(record, "html_content")
            item["html"] = None
            if not path and not title and html_content:
                html = set_prefix(html_content, "%s/" % prefix)
                item["html"] = html
        ns["separator"] = data.get("separator", "|")

        # admin bar
        ns["admin_bar"] = get_admin_bar(footer.parent)  # menu folder

        return ns
Ejemplo n.º 4
0
 def get_template(self, resource, context):
     site_root = resource.get_site_root()
     template = site_root.get_resource(self.not_found_template, soft=True)
     if template and not template.handler.is_empty():
         # When 404 occurs context.resource is the last valid resource
         # in the context.path. We need to compute prefix from context.path
         # instead of context.resource
         path = site_root.get_abspath().resolve2('.%s' % context.path)
         prefix = path.get_pathto(template.get_abspath())
         return set_prefix(template.handler.events, '%s/' % prefix)
     # default
     return BaseNotFoundView.get_template(self, resource, context)
Ejemplo n.º 5
0
    def get_item_value(self, resource, context, item, column, site_root):
        brain, item_resource = item
        if column == 'description':
            view = getattr(item_resource, 'tag_view',
                           getattr(item_resource, 'view'))
            if view:
                content = view.GET(item_resource, context)
                # set prefix
                prefix = site_root.get_pathto(item_resource)
                content = set_prefix(content, '%s/' % prefix, uri=context.uri)
                content = stream_to_str_as_xhtml(content)
                return content.decode('utf-8')
            else:
                return item_resource.get_property('description')

        return BaseRSS.get_item_value(self, resource, context, item,
                                      column, site_root)
Ejemplo n.º 6
0
    def get_namespace(self, resource, context):
        here = context.resource
        # Build namespace
        namespace = {"id": self.id}

        # Manage buttons
        manage_buttons = self.get_manage_buttons(resource, context)
        allowed_to_edit = len(manage_buttons) > 0
        namespace["admin_bar"] = get_admin_bar(resource, manage_buttons)

        # Bar items
        views = []
        for view in self.subviews:
            item = view.item
            stream = view.GET(item, context)
            if view.get_view_is_empty():
                continue
            prefix = here.get_pathto(item)
            stream = set_prefix(stream, "%s/" % prefix)
            css = self.boxes_css_class
            specific_css = item.get_specific_css()
            if specific_css:
                css = "%s %s" % (css, specific_css)
            views.append(
                {
                    "id": self._get_item_id(item, context),
                    "css_class": css,
                    "format": item.class_id,
                    "admin_bar": get_admin_bar(item),
                    "content": stream,
                }
            )

        namespace["views"] = views
        # Do not display the box if there is no items
        display = True
        if allowed_to_edit is False and len(views) == 0:
            display = False
        namespace["display"] = display
        # Del context._bar_aware
        del context._bar_aware

        return namespace
Ejemplo n.º 7
0
 def get_item_value(self, resource, context, item, column, site_root):
     brain, item_resource = item
     if column in ('link', 'guid'):
         value = context.uri.resolve(context.get_link(item_resource))
         return str(value)
     elif column == 'pubDate':
         return brain.pub_datetime
     elif column == 'title':
         return item_resource.get_title()
     elif column == 'description':
         if issubclass(item_resource.__class__, WebPage):
             data = item_resource.get_html_data()
             if data is None:
                 # Skip empty content
                 return ''
             # Set the prefix
             prefix = site_root.get_pathto(item_resource)
             data = set_prefix(data, '%s/' % prefix, uri=context.uri)
             data = stream_to_str_as_xhtml(data)
             return data.decode('utf-8')
         else:
             return item_resource.get_property('description')
Ejemplo n.º 8
0
    def get_email_html(self, context, web_version=False):
        header = []
        if web_version is False:
            header = MSG(u"""
                <center>
                  <span style="font-size:10px;font-weight:bold;
                    font-family:Arial,Helvetica,sans-serif;">
                    <a href="{page_uri}" target="_blank">Click here</a>
                    to see this news on you browser
                  </span>
                </center>
                """).gettext(page_uri=self.get_newsletter_uri(context))
            header = HTMLParser(header.encode('utf-8'))
        footer = MSG(u"""
            <center>
              <span style="font-size:10px;font-weight:bold;
                font-family:Arial,Helvetica,sans-serif;">
                <a href="{unsub_uri}" target="_blank">Click here</a>
                to unsubscribe
              </span>
            </center>
            """).gettext(unsub_uri=self.get_unsubscribe_uri(context))
        footer = HTMLParser(footer.encode('utf-8'))

        handler = self.handler
        body = handler.get_body()
        events = (handler.events[:body.start + 1]
                  + header
                  + handler.events[body.start + 1:body.end]
                  + footer
                  + handler.events[body.end:])
        # Rewrite link with scheme and autority
        prefix = self.get_site_root().get_pathto(self)
        html_data = set_prefix(events, prefix='%s/' % prefix, uri=context.uri)
        html_data = stl(events=html_data, mode='xhtml')
        return html_data
Ejemplo n.º 9
0
            articles.extend(feed_articles)
            # Generate the feed summary

            try:
                feeds_summary[uri] = {'title': feed.channel['title'],
                                      'nb_articles': len(feed_articles),
                                      'articles': feed_articles}
            except KeyError:
                # Channel is not well formed -> no attribute title
                continue

            # Add the anchors
            uri_ref = get_reference(uri)
            for number, article in enumerate(articles):
                # Set prefix with url for article content
                description = set_prefix(article['description'],
                        prefix='.', uri=uri_ref)
                # Transform generator into list
                article['description'] = list(description)
                # Anchor
                article['anchor'] = 'anchor%d' % number
                article['reverse_anchor'] = 'reverse_anchor%d' % number

        # restore the default timeout
        socket.setdefaulttimeout(default_timeout)

        # Save informations
        handler.last_download_time = datetime.now()
        handler.last_articles = articles
        list_errors = []
        for index, x in enumerate(errors):
            # FIXME (old comment 2010-12-27,