コード例 #1
0
 def post(self, request):
     """Handlers posted Article creation form"""
     article_form = ArticleForm(request.POST)
     if article_form.is_valid():
         article = article_form.save(request)
         return HttpResponseRedirect('/articles/%s/%s' % (article.id, article.slug))
     else:
         return TemplateResponse(request, 'mainapp/articles/new.html', {'article_form': article_form})
コード例 #2
0
ファイル: views.py プロジェクト: Yuxxs/ImageIn
    def post(self, request, *args, **kwargs):
        article_id = kwargs.get('article_id')
        article = Article.objects.get(id=article_id)
        form = ArticleForm(request.POST, request.FILES, instance=article)

        if form.is_valid():
            form.save()
        return redirect(
            reverse('articlepage', kwargs={"article_id": article_id}))
コード例 #3
0
    def post(self, request, pk):
        article = get_object_or_404(Article, pk=pk)
        article_form = ArticleForm(request.POST, instance=article)

        if article_form.is_valid():
            article_form.save(request)
            messages.add_message(request, messages.SUCCESS, 'Article saved!')
            return HttpResponseRedirect('/articles/%d/%s' % (int(pk), article.slug))

        return TemplateResponse(request, 'mainapp/articles/edit.html', {'article': article, 'article_form': article_form})
コード例 #4
0
ファイル: views.py プロジェクト: PolinaZaletovaaa1/site
    def post(self, request, *args, **kwargs):
        form = ArticleForm(request.POST, request.FILES)

        if form.is_valid():
            note = form.save(commit=False)

            note.author = request.user

            note.save()
        return redirect(reverse('userpage',
                                kwargs={"username": request.user.username}))
コード例 #5
0
ファイル: views.py プロジェクト: Yuxxs/ImageIn
 def get(self, request, *args, **kwargs):
     article_id = kwargs.get('article_id')
     article = Article.objects.get(id=article_id)
     articleform = ArticleForm(instance=article)
     hashtagform = HashTagForm()
     hashtags = HashTag.objects.filter(article__id=article_id)
     return Response({
         'hashtags': hashtags,
         'hashtagform': hashtagform,
         'articleform': articleform,
         'article': article
     })
コード例 #6
0
ファイル: views.py プロジェクト: Yuxxs/ImageIn
    def post(self, request, *args, **kwargs):
        form = ArticleForm(request.POST, request.FILES)

        if form.is_valid():
            img_url = form.cleaned_data["url"]
            note = form.save(commit=False)
            note.author = request.user
            if img_url:

                # set any other fields, but don't commit to DB (ie. don't save())
                # name = urlparse(img_url).path.split('/')[-1]
                """
                content = urllib.request.urlretrieve(img_url,
                                                     str(settings.MEDIA_ROOT) +"/"+ Article.generate_upload_path(self=None,
                                                                                                     filename="img.jpg"))
                """
                img_temp = NamedTemporaryFile(delete=True)
                img_temp.write(urllib.request.urlopen(img_url).read())
                img_temp.flush()
                note.image = File(img_temp)
            note.save()
        return redirect(
            reverse('userpage', kwargs={"username": request.user.username}))
コード例 #7
0
ファイル: views.py プロジェクト: Yuxxs/ImageIn
 def get(self, request, *args, **kwargs):
     articles = Article.objects.filter(author=request.user)
     articleform = ArticleForm()
     filter = ArticleFilter(request.GET, queryset=articles)
     return Response({'filter': filter, 'articleform': articleform})
コード例 #8
0
ファイル: views.py プロジェクト: PolinaZaletovaaa1/site
 def get(self, request, *args, **kwargs):
     article_id = kwargs.get('article_id')
     article = Article.objects.get(id=article_id)
     articleform = ArticleForm(instance=article)
     return Response({'articleform': articleform, 'article': article})
コード例 #9
0
ファイル: views.py プロジェクト: PolinaZaletovaaa1/site
 def get(self, request, *args, **kwargs):
     articles = Article.objects.all()
     
     articleform = ArticleForm()
     return Response({'articles': articles})
コード例 #10
0
ファイル: views.py プロジェクト: PolinaZaletovaaa1/site
 def get(self, request, *args, **kwargs):
     articles = Article.objects.filter(author=request.user)
     articleform = ArticleForm()
     return Response({'articleform': articleform, 'articles': articles})