Beispiel #1
0
 def fill_view_attrs(self, label, page):
     self.set_device()
     start_index = (page - 1) * info.Pager.PAGESIZE + 1
     if label:
         q = gdata.blogger.client.Query(categories=[label.encode('utf-8')],
                                        start_index=start_index,
                                        max_results=info.Pager.PAGESIZE)
     else:
         q = gdata.blogger.client.Query(start_index=start_index,
                                        max_results=info.Pager.PAGESIZE)
     feed = util.get_posts(q)
     if feed:
         self.view.blog_title = feed.title.text
         if label:
             self.view.title = label
             self.view.label_exists = True
             self.view.label = label
         else:
             self.view.title = feed.title.text
         # 'feed' is an instance of gdata.blogger.BlogPostFeed.
         # So, 'feed.entry' is actually a list of gdata.blogger.BlogPost.
         for entry in feed.entry:
             util.register_pair_of_links(entry)
         self.view.content = feed.entry
         total_posts = int(feed.total_results.text)
         self.view.pager = util.get_favorite_pager(page, total_posts)
         self.view.start_index = start_index
         # collect labels for each post, then save them.
         labels = util.collect_labels(feed.entry)
         util.save_labels(labels, self.request, self.response)
     else:
         logging.error("Fail to get Atom feed with the label %s in the page #%d" % (label, page))
Beispiel #2
0
    def fill_view_attrs(self, post_id):
        user_agent = self.request.headers['User-Agent']
        view = self.view.type
        self.view.device = device.get_device(user_agent, view)

        client = BloggerPostClient()
        settings = util.get_settings()
        entry = client.get_one_post(settings.get('blog_id'), post_id)
        if entry:
            self.view.title = entry.title.text
            self.view.permalink = entry.get_html_link().href

            labels = []
            for label in entry.category:
                labels.append(label.term)
            labels.sort()
            self.view.labels = labels
            util.save_labels(labels, self.request, self.response)

            self.view.published = util.get_datetime_from_iso8601(entry.published.text[:19])
            if entry.updated:
                self.view.isUpdated = True
                self.view.updated =  util.get_datetime_from_iso8601(entry.updated.text[:19])
            self.view.content = util.replace_permalinks(entry.content.text)
        else:
            logging.error("Fail to get Atom feed for the post, #%d" % post_id)