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})
Exemple #2
0
    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}))
    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})
Exemple #4
0
    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}))
Exemple #5
0
 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
     })
Exemple #6
0
    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}))
Exemple #7
0
 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})
Exemple #8
0
 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})
Exemple #9
0
 def get(self, request, *args, **kwargs):
     articles = Article.objects.all()
     
     articleform = ArticleForm()
     return Response({'articles': articles})
Exemple #10
0
 def get(self, request, *args, **kwargs):
     articles = Article.objects.filter(author=request.user)
     articleform = ArticleForm()
     return Response({'articleform': articleform, 'articles': articles})