示例#1
0
    def test_comment(self):
        article = NoosferoArticle()
        article.profile_identifier = "profile"
        article.path = "url"
        article.title = "title"
        comment = NoosferoComment()
        comment.article = article
        url = u"/{prefix}/{profile}/{path}?view=true".format(
            prefix=self.get_prefix(), profile=article.profile_identifier, path=article.path
        )

        self.assertEqual(url, comment.url)
        self.assertEqual("title", comment.title)
示例#2
0
    def test_comment(self):
        article = NoosferoArticle()
        article.profile_identifier = "profile"
        article.path = "url"
        article.title = "title"
        comment = NoosferoComment()
        comment.article = article
        url = u'/{prefix}/{profile}/{path}?view=true'.format(
                     prefix=self.get_prefix(),
                     profile=article.profile_identifier,
                     path=article.path)

        self.assertEqual(url, comment.url)
        self.assertEqual("title", comment.title)
示例#3
0
    def fetch_articles(self):
        url = '/api/v1/articles'
        timestamp = TimeStampPlugin.get_last_updated('NoosferoArticle')

        can_updated_timestamp = True
        page = 1
        while True:
            json_data = self.get_json_data(url,
                                           page,
                                           timestamp=timestamp,
                                           order="updated_at DESC",
                                           show_comments="true")

            if not len(json_data) or not len(json_data.get('articles', [])):
                break

            json_data = json_data['articles']
            if can_updated_timestamp:
                self.save_last_update(json_data[0]['updated_at'],
                                      "NoosferoArticle")
                can_updated_timestamp = False

            for element in json_data:
                article = NoosferoArticle()
                self.fill_object_data(element, article)

                try:
                    article.save()
                except:
                    continue

                self.import_comments(element["comments"], element["id"])

                for category_json in element["categories"]:
                    category = NoosferoCategory.objects.get_or_create(
                        id=category_json["id"], name=category_json["name"])[0]
                    article.categories.add(category.id)
            page += 1
    def fetch_articles(self):
        url = '/api/v1/articles'
        timestamp = TimeStampPlugin.get_last_updated('NoosferoArticle')

        can_updated_timestamp = True
        page = 1
        while True:
            json_data = self.get_json_data(url, page, timestamp=timestamp,
                                           order="updated_at DESC",
                                           show_comments="true")

            if not len(json_data) or not len(json_data.get('articles', [])):
                break

            json_data = json_data['articles']
            if can_updated_timestamp:
                self.save_last_update(json_data[0]['updated_at'],
                                      "NoosferoArticle")
                can_updated_timestamp = False

            for element in json_data:
                article = NoosferoArticle()
                self.fill_object_data(element, article)

                try:
                    article.save()
                except:
                    continue

                self.import_comments(element["comments"], element["id"])

                for category_json in element["categories"]:
                    category = NoosferoCategory.objects.get_or_create(
                        id=category_json["id"], name=category_json["name"])[0]
                    article.categories.add(category.id)
            page += 1