Ejemplo n.º 1
0
def edit_article(request, id):
    next = get_next(request)

    try:
        article = Article.objects.get(id=id)
    except ObjectDoesNotExist:
        return HttpResponseRedirect(next)

    if request.method == 'POST':
        if not request.user.is_authenticated(
        ) or not request.user.is_staff or not request.user.is_active:
            return HttpResponseRedirect('/')
        if request.user != article.user:
            return HttpResponseRedirect('/')
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            form.save()
            return HttpResponseRedirect(next)
    else:
        form = ArticleForm(instance=article)
    return render_to_response('blog/edit_article.html', {
        'form': form,
        'article': article,
        'next': next,
    },
                              context_instance=RequestContext(request))
Ejemplo n.º 2
0
def articleform(request):
    if request.method == 'POST':  # S'il s'agit d'une requete POST
        form = ArticleForm(request.POST)  # Nous reprenons les donnees

        if form.is_valid(): # Nous verifions que les donnees envoyees sont valides

            # Ici nous pouvons traiter les donnees du formulaire
            #titre       = form.cleaned_data['titre']
            #slug        = form.cleaned_data['slug']
            #auteur      = form.cleaned_data['auteur']
            #contenu     = form.cleaned_data['contenu']
            #date        = form.cleaned_data['date']
            #categorie   = form.cleaned_data['categorie']
            #Sujet = form.cleaned_data['Sujet']
            #message = form.cleaned_data['message']
            #envoyeur = form.cleaned_data['envoyeur']
            #renvoi = form.cleaned_data['renvoi']

            # Nous pourrions ici envoyer l'e-mail grace aux donnees que nous venons de recuperer

            envoi = True
            form.save()

    else: # Si ce n'est pas du POST, c'est probablement une requete GET
        form = ArticleForm()  # Nous creons un formulaire vide
    
    return render(request, 'blog/articleform.html', locals())
Ejemplo n.º 3
0
def create_article(request):  # User creating a new article.
    form = ArticleForm(request.POST)

    if form.is_valid():
        form.save()
        return redirect(reverse('show_all'))
    else:  # Else sends user back to article_form page.
        return render(request, 'article_form.html', {'form': form})
Ejemplo n.º 4
0
 def post(request, pk):
     _id = pk
     article_obj = Article.objects.filter(id=_id).first()
     form_obj = ArticleForm(request.POST, instance=article_obj)
     if form_obj.is_valid():
         form_obj.save()
         _next_url = reverse('blog:article', kwargs={'pk': 0})
         return redirect(_next_url)
     return render(request, 'blog/addblog.html', {'form_obj': form_obj, 'id': _id})
Ejemplo n.º 5
0
def newForm(request):
    form = ArticleForm()
    if request.POST :
        form = ArticleForm(request.POST)
        if form.is_valid():
            print(form.cleaned_data, form.errors)
            form.save()
            return redirect('/form/')
    return render(request, 'forms.html', {"form": form,'username': auth.get_user(request).username})
Ejemplo n.º 6
0
def article(request):
	if request.method == 'POST':
		form = ArticleForm(request.POST)
		if form.is_valid():
			form.save()

	else:
		form = ArticleForm()
	
	return render(request, 'blog/article.html', locals())	
Ejemplo n.º 7
0
def create_article(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.user = request.user
            form.save()
            return HttpResponseRedirect('/home/')
    else:
        form = ArticleForm()
    return render(request, 'create_article.html', {'form': form})
Ejemplo n.º 8
0
 def post(self, request):
     """发布文章提交表单处理,验证通过则添加记录重定向到文章详情页面,否则回到发布文章页面显示错误"""
     article_form = ArticleForm(request.POST)
     if article_form.is_valid():
         article_form.instance.user_id = request.session['user']['id']
         article_form.save()
         return redirect(
             reverse('blog:article_detail',
                     args=[article_form.instance.id]))
     return render(request, 'publish_article.html', {'form': article_form})
Ejemplo n.º 9
0
def ajout(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        #prepopulated_fields = {'Article.slug': ('Article.titre', ), }
        if form.is_valid():
            form.save()
            return redirect(view_redirection)
    else:
        form = ArticleForm
    return render(request, 'blog/ajout.html', locals())
Ejemplo n.º 10
0
Archivo: views.py Proyecto: Mbobby/Blog
def create(request):
	if request.method == "POST":
		form = ArticleForm(request.POST, request.FILES)
		if form.is_valid():
			form.save()
		return HttpResponseRedirect('/all')
	c = {}
	c.update(csrf(request))
	c['form'] = ArticleForm()
	return render_to_response('create.html', c)
Ejemplo n.º 11
0
def nouvel_article(request):
    """AJout d'un article via formulaire"""
    if request.method == "POST":
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()
            envoi = True
    else:
        form = ArticleForm()

    return render(request, "blog/nouvel-article.html", locals())
Ejemplo n.º 12
0
def addArticle(request):
    if request.method == 'POST':
        print(request.POST)
        print(request.FILES)
        form = ArticleForm(request.POST, request.FILES)
        # print(form)
        if form.is_valid():
            form.save()
            return JsonResponse({"err": "false", "message": "data added"})
        else:
            return JsonResponse({"err": "true", "message": "data not added"})
Ejemplo n.º 13
0
def edit_article(request, id):
    if request.method == 'POST':  # S'il s'agit d'une requête POST
        article = get_object_or_404(Article, id=id)
        article_form = ArticleForm(request.POST, instance=article)
        if article_form.is_valid():
            article_form.save()
        return redirect('blog.views.edit_article', id)
    else:
        article = get_object_or_404(Article, id=id)
        article_form = ArticleForm(instance=article)
        return render(request, 'blog/edit_article.html', {'article_form': article_form, 'id': id})
Ejemplo n.º 14
0
def nouvel_article(request):
    """AJout d'un article via formulaire"""
    if request.method == "POST":
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()
            envoi = True
    else:
        form = ArticleForm()

    return render(request, "blog/nouvel-article.html", locals())
Ejemplo n.º 15
0
def Article_Formu(request):
    article = Article()
    if request.method == 'POST':
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            form.save()

            envoi = True
    else:
        form = ArticleForm(request.POST, instance=article)
    return render(request, 'blog/HTML/creation_article.html', locals())
Ejemplo n.º 16
0
def articleform(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()   #sauvegarder l'article creer
            form=ArticleForm()
            envoi=True 

    else:
        form= ArticleForm()

    return render(request,'blog/articleform.html',locals())
Ejemplo n.º 17
0
def update_article(request, article_id):
    args = {}
    article = get_object_or_404(Article, id=article_id)
    form = ArticleForm(instance=article)
    if request.POST:
        form = ArticleForm(data=request.POST, instance=article)
        if form.is_valid():
            form.save()
            messages.add_message(request, messages.INFO, 'Успешно изменено')
            return redirect('index')
    args['form'] = form
    return render(request, 'cr_up_article_page.html', args)
Ejemplo n.º 18
0
def articleform(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            form.save()  #sauvegarder l'article creer
            form = ArticleForm()
            envoi = True

    else:
        form = ArticleForm()

    return render(request, 'blog/articleform.html', locals())
Ejemplo n.º 19
0
def update_post(request, slug, template="create_post.html"):
    post = get_object_or_404(Post.objects.select_related("user"), slug=slug)
    if post.user != request.user:
        raise Http404
    if request.method == "POST":
        form = ArticleForm(instance=post, data=request.POST, files=request.FILES)
        if form.is_valid():
            form.save()
            return redirect("detail", post.slug)
    else:
        form = ArticleForm(instance=post)
    return render(request, template, {"form": form, "is_deletable": True, "slug": slug})
Ejemplo n.º 20
0
Archivo: views.py Proyecto: P4ll/csdprt
 def post(self, request):
     post = Post(author_id=request.user)
     form = ArticleForm(request.POST, request.FILES, instance=post)
     if form.is_valid():
         form.save()
         return redirect('blog:article_admin')
     else:
         error = form.errors
         return render(request, 'blog/articles/admin/create.html', {
             'form': form,
             'error': error
         })
Ejemplo n.º 21
0
def add(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            titre = form.cleaned_data['titre']
            auteur = form.cleaned_data['auteur']
            contenu = form.cleaned_data['contenu']
            categorie = form.cleaned_data['categorie']
            form.save()
            return HttpResponseRedirect('/blog/facts')
    else:
        form = ArticleForm()
    return render(request, 'blog/add_fact.html', {'title': 'Ajouter !', 'form': form})
Ejemplo n.º 22
0
 def post(self, request):
     pk = request.GET.get("id")
     article_obj = Article.objects.get(id=pk) if pk else None
     dic = request.POST.dict()
     date = dic.pop("add_date")
     dic.update({"add_date": datetime.strptime(date, '%Y-%m-%d')})
     form_obj = ArticleForm(dic, request.FILES, instance=article_obj)
     if form_obj.is_valid():
         form_obj.save()
         self.make_md()
         AJAX_DATA["path"] = "/cms/article"
         return JsonResponse(AJAX_DATA)
     else:
         AJAX_DATA["status"] = form_obj.errors
         return JsonResponse(AJAX_DATA)
Ejemplo n.º 23
0
def article(request):
    # Create Article
    current_date = date.today()
    if request.method == "POST":
        form = ArticleForm(request.POST)

        if form.is_valid():
            article = form.save(commit=False)
            article.author = request.user
            article.published_date = timezone.now()
            article.save()
            return redirect('blog_details', id=article.id)
        else:
            return render(request, 'post_edit.html', {
                'form': form,
                'date': current_date
            })

    # Viewing an Article
    else:
        form = CommentForm()
        return render(request, 'post_edit.html', {
            'form': form,
            'date': current_date
        })
Ejemplo n.º 24
0
def add_article(request):
    # context = RequestContext(request)
    topic_tags, other_tags = get_tag_lists()
    current_user = request.user

    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            new_article = form.save()
            raw_tags = form.cleaned_data['tags'].split(',')
            if raw_tags:
                for raw_tag in raw_tags:
                    raw_tag = raw_tag.strip().replace(' ', '_').lower()
                    tag_name = urllib.quote(raw_tag)
                    tag, created = Tag.objects.get_or_create(name=tag_name)
                    if created:
                        tag.article_count = 1
                    else:
                        tag.article_count += 1
                    tag.save()
                    tag.articles.add(new_article)
            return redirect(index)
        else:
            print form.errors
    else:
        form = ArticleForm(initial={'author': current_user})

    context = {
        'form': form,
        'topic_tags': topic_tags,
        'other_tags': other_tags,
    }

    return render(request, 'add_article.html', context)
Ejemplo n.º 25
0
def article_update(request, slug=None):
    user = request.user
    #if not user.is_staff or not user.is_superuser:
    #    raise Http404
    instance = get_object_or_404(Article, slug=slug)
    if instance.author != user:
        raise Http404
    # Para poder actualizar un articulo, su imagen es necesario request.FILES or NOne
    form = ArticleForm(request.POST or None, request.FILES or None, instance=instance)
    if form.is_valid():
        instance = form.save(commit=False)
        # form.instance.author = request.user
        instance.save()
        # message success
        # messages.success(request, "<a href='#'>Item</a>Saved", extra_tags='html_safe')
        messages.success(request, "Tu artículo ha sido actualizado")
        return HttpResponseRedirect(instance.get_absolute_url())
    context = {
        'title': instance.title,
        'instance': instance,
        'form': form,
    }
    if user.is_authenticated():
        context['userprofile'] = user.profile
    return render(request, 'blog/article_form.html', context)
Ejemplo n.º 26
0
def post_article(request):
    if request.POST and request.method == "POST" and request.user.is_authenticated:
        f = ArticleForm(request.POST)
        new_article = f.save()
        return HttpResponseRedirect("/blog/superuser")
    else:
        return HttpResponseRedirect("/blog/superuser")
Ejemplo n.º 27
0
def add_article(request):
	# context = RequestContext(request)
	topic_tags, other_tags = get_tag_lists()
	current_user = request.user

	if request.method == 'POST':
		form = ArticleForm(request.POST)
		if form.is_valid():
			new_article = form.save()
			raw_tags = form.cleaned_data['tags'].split(',')
			if raw_tags:
				for raw_tag in raw_tags:
					raw_tag = raw_tag.strip().replace(' ', '_').lower()
					tag_name = urllib.quote(raw_tag)
					tag, created = Tag.objects.get_or_create(name=tag_name)
					if created:
						tag.article_count=1
					else:
						tag.article_count +=1
					tag.save()
					tag.articles.add(new_article)
			return redirect(index)
		else:
			print form.errors
	else:
		form = ArticleForm(initial={'author': current_user})

	context = {
		'form': form,
		'topic_tags': topic_tags,
		'other_tags': other_tags,
	}

	return render(request, 'add_article.html', context)	
Ejemplo n.º 28
0
def edit_one_article(request, article_pk=0):
    try:
        article = Article.objects.get(pk=article_pk,
                                      author=request.user.get_profile())
    except Article.DoesNotExist:
        article = None
    if request.method == 'POST':
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            art = form.save(commit=False)
            art.author = request.user.get_profile()
            art.save()

        messages.add_message(request, messages.INFO,
                             _('Your edits have been saved successfully.'))

        return render_to_response('blog/edit_one_article.html', {
            'article_pk': article_pk,
            'form': form
        },
                                  context_instance=RequestContext(request))
    else:
        try:
            article = Article.objects.get(pk=article_pk,
                                          author=request.user.get_profile())
        except Article.DoesNotExist:
            form = ArticleForm()

        return render_to_response('blog/edit_one_article.html', {
            'article_pk': article_pk,
            'form': form
        },
                                  context_instance=RequestContext(request))
Ejemplo n.º 29
0
def article_edit(request, pk):
    article = get_object_or_404(Article, pk=pk)
    if request.method == "POST":
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            f = form.save(commit=False)
            ru = request.user.username
            a = form.cleaned_data['author']
            print(a.username)
            print(ru)
            if ru != a.username:
                messages.add_message(
                    request, messages.ERROR,
                    'Invalid username auther not same logged user:'******'Invalid username auther not same logged user: %(value)s'),
                #                       code='invalid',
                #                       params={'value': value}, )
            else:
                f.author = a
                ps = form.cleaned_data['post_status']
                if ps == 'published':
                    f.published_date = timezone.now()
                f.save()
                return redirect('article-detail', pk=f.pk)
    else:
        form = ArticleForm(instance=article)
    return render(request, 'blog/article_edit.html', {
        'form': form,
        'pk': article.pk
    })
Ejemplo n.º 30
0
def article_new(request):
    if request.method == "POST":
        form = ArticleForm(request.POST)
        if form.is_valid():
            f = form.save(commit=False)
            ru = request.user.username
            a = form.cleaned_data['author']
            print(a.username)
            print(ru)
            if ru != a.username:
                print('Invalid username auther not same logged user:   '******'Invalid username auther not same logged user:'******'Invalid username auther not same logged user: %(value)s'),
                #                       code='invalid',
                #                       params={'value': value}, )
            else:
                print(form.cleaned_data['post_status'])
                f.author = a
                ps = form.cleaned_data['post_status']
                if ps == 'published':
                    f.published_date = timezone.now()
                f.save()
                send_mail('subject', "new post", '*****@*****.**', [a.mail])
                return redirect('article-detail', pk=f.pk)
    else:
        form = ArticleForm()
    return render(request, 'blog/article_edit.html', {'form': form})
Ejemplo n.º 31
0
def edit_one_article(request, article_pk=0):
	try:
		article = Article.objects.get(pk=article_pk, author=request.user.get_profile())
	except Article.DoesNotExist:
		article = None
	if request.method == 'POST':
		form = ArticleForm(request.POST, instance=article)
		if form.is_valid():
			art = form.save(commit=False)
			art.author = request.user.get_profile()
			art.save()

		messages.add_message(request, messages.INFO, 
			_('Your edits have been saved successfully.'))

		return render_to_response('blog/edit_one_article.html', 
			{'article_pk': article_pk, 'form': form}, 
			context_instance=RequestContext(request))
	else:
		try:
			article = Article.objects.get(pk=article_pk, author=request.user.get_profile())
		except Article.DoesNotExist:	
			form = ArticleForm()

		return render_to_response('blog/edit_one_article.html', 
			{'article_pk': article_pk, 'form': form}, 
			context_instance=RequestContext(request))
Ejemplo n.º 32
0
def modifArticle(request, id):
    article = get_object_or_404(Article, id=id)
    if request.method == 'POST':  # S'il s'agit d'une requête POST
        # form = ArticleForm(request.POST)  # Nous reprenons les données

        form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            form.save()

            # Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer

            envoi = True

    else:  # Si ce n'est pas du POST, c'est probablement une requête GET
        form = ArticleForm(instance=article)  # Nous créons un formulaire vide

    return render(request, 'blog/modifArticle.html', locals())
Ejemplo n.º 33
0
def add_article(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST, request.FILES)
        if form.is_valid():
            form = form.save(commit=False)
            volunteer = get_object_or_404(Volunteer, user=request.user)
            form.author = volunteer
            form.save()
            return HttpResponseRedirect(reverse('ArticlesList', args=[]))
    else:
        form = ArticleForm()

    template_name = 'blog/new_article.html'
    context = {
        'form': form,
    }
    return render(request, template_name, context)
Ejemplo n.º 34
0
def post_edited_article(request, pk):
    if request.POST and request.method == "POST" and request.user.is_authenticated:
        f = ArticleForm(request.POST)
        a = get_object_or_404(Article, pk=pk)
        print("inside")
        if f.is_valid():
            f.save(commit=False)
            cd = f.cleaned_data
            a.title = cd["title"]
            a.short = cd["short"]
            a.content = cd["content"]
            a.save()
            return HttpResponseRedirect("/blog/superuser")
        else:
            print("not valid")
    else:
        print("not logged")
Ejemplo n.º 35
0
def ajoutArticle(request):
    if request.method == 'POST':  # S'il s'agit d'une requête POST
        form = ArticleForm(request.POST)  # Nous reprenons les données

        #form = ArticleForm(request.POST, instance=article)
        if form.is_valid():
            form.save()

            # Nous pourrions ici envoyer l'e-mail grâce aux données que nous venons de récupérer

            envoi = True
            return redirect('/blog/article/')

    else:  # Si ce n'est pas du POST, c'est probablement une requête GET
        form = ArticleForm()  # Nous créons un formulaire vide

    return render(request, 'blog/ajoutArticle.html', locals())
Ejemplo n.º 36
0
def add_article(request):
    """添加新文章"""
    context = {}
    if request.user.is_authenticated:
        user = request.user

        if request.method == "GET":
            context['form'] = ArticleForm()
            return render(request, 'blog/article_add.html', context)

        if request.method == "POST":
            form = ArticleForm(request.POST)
            if form.is_valid():
                form_obj = form.save(commit=False)
                form_obj.author = user
                form.save()
                messages.success(request, '文章添加成功')
                return HttpResponseRedirect(reverse('blog:articles'))
Ejemplo n.º 37
0
def post(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST, request.FILES)
        if form.is_valid():
            article = form.save(commit=False)
            article.user = request.user
            article.fileItem_id = request.POST['id_file']
            article.save()
        else:
            print(form.errors)
    return view_media(request)
Ejemplo n.º 38
0
def post_edit(request, pk):
    post = get_object_or_404(BlogPost, pk=pk)
    if request.method == "POST":
        form = ArticleForm(request.POST, instance=post)
        if form.is_valid():
            post = form.save(commit=False)
            post.save()
        return redirect('show_blogs_editing')
    else:
        form = ArticleForm(instance=post)
    return render(request, 'blog/edit/form.html', {'form': form})
Ejemplo n.º 39
0
def new_article(request):
  if request.method == 'POST':
    form = ArticleForm(request.POST)
    if form.is_valid():
      article = form.save(commit=False)
      article.user = request.user
      article.author = article.user
      article.save()
      return redirect('article_details', id=article.id)
  else:
    form = ArticleForm()
  return render(request, 'new_article.html', {'form': form})  
Ejemplo n.º 40
0
def article_new(request):
    if request.method == 'POST':
        form = ArticleForm(request.POST)
        if form.is_valid():
            article = form.save(commit=False)
            article.article_author = request.user
            article.save()
            return redirect("blog:home")

    else:
        form = ArticleForm()
    return render(request, 'blog/add_article.html', context={"form": form})
Ejemplo n.º 41
0
 def post(self, request):
     if request.method == 'POST':
         newArticle = ArticleForm(request.POST)
         if newArticle.is_valid():
             article = newArticle.save(commit=False)
             article.body = newArticle.cleaned_data['body']
             article.title = newArticle.cleaned_data['title']
             article.author = request.user
             if request.user.is_redactor:
                 article.status = 'approve'
             article.save()
     return redirect('all')
Ejemplo n.º 42
0
def article_add(request):
    # sticks in a POST or renders empty form
    form = ArticleForm(request.POST or None)
    if form.is_valid():
        cmodel = form.save()
        #This is where you might chooose to do stuff.
        #cmodel.name = 'test1'
        cmodel.save()
        return HttpResponse('Record Saved!')

    return render_to_response('blog/contact.html',
                              {'article_form': form},
                              context_instance=RequestContext(request))
Ejemplo n.º 43
0
def add(request):
    if request.method == 'POST':
        formData = ArticleForm(request.POST, request.FILES)
        if formData.is_valid():
            edited = formData.save(commit=False)
            edited.user = request.user
            edited.save()
        return redirect("list")

    view_url = reverse("add")
    upload_url, upload_data = prepare_upload(request, view_url)

    return render(request, "add.html", {"form": ArticleForm, "action": "Add new", 'upload_url': upload_url, 'upload_data': upload_data})
Ejemplo n.º 44
0
def article_edit_page(request, id):
    if not request.user.is_superuser:
        return HttpResponseRedirect('/article/%s/' % id)
    c = get_common_context(request)
    c['article'] = Article.objects.get(id=id)
    
    if request.method == 'POST':
        if (request.POST['action'] == 'save') or (request.POST['action'] == 'save_back'):
            af = ArticleForm(request.POST, instance=c['article'])
            if af.is_valid(): 
                af.save()
                if request.POST['action'] == 'save_back':
                    return HttpResponseRedirect('/article/%s/' % id)
                else:
                    return HttpResponseRedirect('/article/%s/edit/' % id)
            else:
                pass
        return HttpResponseRedirect(request.path)
    categories = c['article'].category.all().filter(show=True)

    c['articles'] = Article.objects.filter(category__in=categories)
    
    c['article_form'] = ArticleForm(instance=c['article'])
    return render_to_response('article_edit.html', c, context_instance=RequestContext(request))
Ejemplo n.º 45
0
def edit_article(request, id):
    next=get_next(request)
    
    try:
        article=Article.objects.get(id=id)
    except ObjectDoesNotExist:
        return HttpResponseRedirect(next)
        
    if request.method == 'POST': 
        if not request.user.is_authenticated() or not request.user.is_staff or not request.user.is_active: 
            return HttpResponseRedirect('/')
        if request.user!=article.user:
            return HttpResponseRedirect('/')
        form = ArticleForm(request.POST, instance=article)
        if form.is_valid(): 
            form.save()
            return HttpResponseRedirect(next) 
    else:
        form = ArticleForm(instance=article) 
    return render_to_response('blog/edit_article.html', {
        'form': form,
        'article': article,
        'next': next,
    },context_instance=RequestContext(request))
Ejemplo n.º 46
0
def edit(request, pk):
    article = get_object_or_404(Article, pk=pk)
    form = ArticleForm(instance=article)

    if request.method == 'POST':
        formData = ArticleForm(request.POST, request.FILES, instance=article)
        if formData.is_valid():
            edited = formData.save(commit=False)
            edited.user = request.user
            edited.save()
        return redirect("list")

    view_url = reverse("edit", kwargs={"pk":pk})
    upload_url, upload_data = prepare_upload(request, view_url)

    return render_to_response("add.html", {"form": form, "action": "Edit", 'upload_url': upload_url, 'upload_data': upload_data})
Ejemplo n.º 47
0
def new(request):
	if request.user.is_authenticated():
		if request.method == 'POST':
			form = ArticleForm(request.POST)
			if form.is_valid():
				blag = form.save(commit=False)
				blag.author = request.user
				blag.save()
				return index(request)
			else:
				print form.errors
		else:	
			form = ArticleForm()
	else:
		return HttpResponse("You must be an autheticated user to be here.")
	return render(request, 'blog/new.html', {'form': form})
Ejemplo n.º 48
0
def create_post(request, template="create_post.html"):
    if request.method == "POST":
        form = ArticleForm(data=request.POST, files=request.FILES)
        if form.is_valid():
            post = form.save(commit=False)
            post.user = request.user
            post.date = date.today()
            post.is_active = False
            post.save()
            send_mail_with_template(
                u"Yeni yazı var", settings.MY_MAIL, "mails/newpost.html", {"post": post, "user": request.user}
            )
            return redirect("detail", post.slug)
    else:
        form = ArticleForm()
    return render(request, template, {"form": form})
Ejemplo n.º 49
0
 def create(self,request, *args, **kwargs):
     """
     创建收藏:
     URL:/iapi/blog/article/
     参数:
     title : 收藏标题
     content : 收藏内容
     desc :收藏描述(可选)
     like : 赞
     source : 收藏来源
     ctype : 收藏内容类型 (链接:link)  (可选) 默认是按照纯文字展现
     """
     f = ArticleForm(request.POST)
     if f.is_valid():
         try:
             instance = f.save()
         except:
             log.error('article_create_error',exc_info=traceback)
     else:
         raise FormValidationError(f)
     return instance