Beispiel #1
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()
Beispiel #2
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
    )