Exemplo n.º 1
0
    def setUp(self):
        self.factory = RequestFactory()
        self.outlet1 = Outlet.objects.create(name='Sample Feed',
                                             description="Description",
                                             url='http://example.org',
                                             language='en-US',
                                             updated=None)
        self.outlet2 = Outlet.objects.create(name='Sample Feed 2',
                                             description="Description 2",
                                             url='http://example2.org',
                                             language='en-GB',
                                             updated=datetime.datetime(
                                                 2002,
                                                 9,
                                                 7,
                                                 0,
                                                 0,
                                                 1,
                                                 tzinfo=timezone.utc))
        self.author1 = Author(name='Author1')
        self.author2 = Author(name='Author2',
                              profile='http://plus.google.com/Author2',
                              twitter='@author2')
        self.outlet1.author_set.add(self.author1)
        self.outlet1.author_set.add(self.author2)

        self.article1 = Article(title='Title1',
                                summary='Summary1',
                                url='http://example.com/articles/1',
                                pub_date=datetime.datetime(
                                    2002, 9, 7, 0, 0, 1, tzinfo=timezone.utc),
                                content='Content1')
        self.article2 = Article(title='Title2',
                                summary='Summary2',
                                url='http://example.com/articles/2',
                                pub_date=datetime.datetime(
                                    2002, 9, 7, 0, 1, 1, tzinfo=timezone.utc),
                                content='Content2')
        self.outlet1.article_set.add(self.article1)
        self.outlet1.article_set.add(self.article2)
        self.article1.authors.add(self.author1, self.author2)
        self.article2.authors.add(self.author1)

        self.tag1 = Tag.objects.create(term='Tag1')
        self.tag2 = Tag.objects.create(term='Tag2')
        self.article1.tags.add(self.tag1)
        self.article2.tags.add(self.tag2)
Exemplo n.º 2
0
	def keepData(self,arr):
		article=arr['article']
		pubdate=arr['pubdate']
		title=arr['title']
		link=arr['link']
		brief=arr['brief']
		descr=arr['descr']
		content=arr['content']
		a1=Article(article=article,title=title,link=link,pubdate=pubdate,brief=brief,descr=descr,content=content)
		a1.save()
Exemplo n.º 3
0
def article_add(request, site_id, article_id=None):
    site = get_object_or_404(Site, pk=site_id)
    user = request.user
    added = False
    changed = False
    if article_id:   # article_id が指定されている (修正時
        article = get_object_or_404(Article, pk=article_id)
        changed = True
        print("changed")
    else:               # article_id が指定されていない (追加時)
        article = Article()
        added = True
        print("added")

    if request.method == 'POST':
        article_form = ArticleForm(request.POST, instance=article)
        if article_form.is_valid():
            article = article_form.save(commit=False)
            article.title = request.POST['title']
            url = request.POST['url']
            article.url = url
            article.content = get_content(url)
            article.user = user
            article.site = site
            article.save()
            # TODO: 登録後のページ変える、登録or編集しましたというアラートつける
            context = {
                "site_id": site_id,
                "added": added,
                "changed": changed,
            }
            return redirect('result:article_list', site_id=site_id)

    elif request.method == 'GET':
        article_form = ArticleForm(instance=article)  # site インスタンスからフォームを作成

    context = {
        "site_id": site_id,
        "article_id": article_id,
        'user': user,
        'article_form': article_form,
    }
    return render(
        request,
        'register/article_add.html',
        context
    )