Пример #1
0
    def feed_entry(cls, name, title):
        """
        Template helper which when given the name of a feed and the title
        for a particular entry will render the entry into the snippet for
        that feed. If the feed has no snippet it will use the one from
        the config file, and failing that will use default default.

        The title supplied be a regular expression.  Note that because a
        regex check is done then 'This is a long title here' will match
        a title parameter of 'This is a long title' unless ^ and & are
        used to bind the title to start/end of line.
        """
        data = {'error':'', 'entry': '', 'html_entries': False}
        feed = feedlogic.get_feed(name)
        template = FeedContent.default_snippet
        if feed:
            data['html_entries'] = feed.html_entries
            template = feed.template or FeedContent.default_snippet
            try:
                data['entry'] = util.find_entry(feed.content,
                                                title,
                                                FeedContent.short_description_size)
            except feedmodel.FeedException as fe:
                data['error'] = str(fe)
        else:
            data['error'] = _("Feed {name} not found".format(name=name))
        return p.toolkit.render_snippet(template, data)
Пример #2
0
    def edit(self, id):
        """
        Allows a user to edit an existing feed, potentially changing the URL
        and in doing so re-triggering validation of the feed.
        """
        self._check_auth("feed_update")

        data, errors, error_summary = {}, {}, {}
        c.feed = feedlogic.get_feed(id)
        if not c.feed:
            base.abort(404, _("Feed {name} does not exist".format(name=id)))

        if base.request.method == "POST":
            try:
                data = logic.clean_dict(
                        df.unflatten(
                            logic.tuplize_dict(
                                logic.parse_params(base.request.params)
                        )))
                feed = feedlogic.edit_feed(c.feed, data)
                h.redirect_to(controller=self.controller_path,
                               action='read',
                               id=feed.name)
            except feedmodels.FeedException:
                error = {'url': [u'Failed to load feed']}
                error_summary = {u'URL': u'Failed to load feed'}
                data = c.feed.as_dict()
            except df.DataError:
                base.abort(400, _(u'Integrity Error'))
            except logic.ValidationError, e:
                errors = e.error_dict
                error_summary = e.error_summary
Пример #3
0
    def read(self, id):
        """
        Shows an individual feed along with the currently held content.
        """
        self._check_auth("feed_get")

        c.feed = feedlogic.get_feed(id)
        if not c.feed:
            base.abort(404, _("Feed {name} does not exist".format(name=id)))

        return base.render("feeds/read.html")
Пример #4
0
    def delete(self, id):
        """
        Deletes the specified feed
        """
        self._check_auth("feed_delete")
        feed = feedlogic.get_feed(id)
        if not feed:
            base.abort(404, _("Feed {name} does not exist".format(name=id)))
        feedlogic.delete_feed(feed)

        h.redirect_to( controller=self.controller_path,
                       action='index')
Пример #5
0
    def update(self, id):
        """
        Fetches the data from the URL specified by the feed
        """
        self._check_auth("feed_update")

        feed = feedlogic.get_feed(id)
        if not feed:
            base.abort(404, _("Feed {name} does not exist".format(name=id)))

        feedlogic.update_feed(feed)
        h.redirect_to( controller=self.controller_path,
                       action='read',
                       id=feed.name)