Ejemplo n.º 1
0
def edit_article(request, id):
    article_instance = Article.objects.get(id=id)
    form = ArticleForm(request.POST or None, instance=article_instance)
    if form.is_valid():
        form.save()

    t = get_template('blog/edit_article.html')
    c = RequestContext(request, locals())
    return HttpResponse(t.render(c))
Ejemplo n.º 2
0
def create_article(request):
    form = ArticleForm(request.POST or None)
    if form.is_valid():
        form.save()
        form = ArticleForm()

    t = get_template('blog/create_article.html')
    c = RequestContext(request, locals())
    return HttpResponse(t.render(c))
Ejemplo n.º 3
0
def article_update(request, item_slug, category_slug, article_slug):
    if not request.user.is_staff or not request.user.is_superuser:
        raise Http404
    title = _('Форма оновлення статті')
    button_create = _('змінити статтю')
    button_cancel = _('відміна')
    instance = get_object_or_404(
        Article,
        article_category__menu_category__menu_name=item_slug,
        article_category__category_name=category_slug,
        article_slug=article_slug)
    form = ArticleForm(request.POST or None,
                       request.FILES or None,
                       instance=instance)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        messages.success(request,
                         _("Ура, стаття оновлена!"),
                         extra_tags='success')
        return redirect(instance)
    return_path = instance.get_absolute_url()
    context = {
        'title': title,
        'button_create': button_create,
        'button_cancel': button_cancel,
        'return_path': return_path,
        'form': form,
        'article': instance,
    }
    return render(request, 'article_form.html', context)
Ejemplo n.º 4
0
def article_create(request, item_slug, category_slug=None):
    if not request.user.is_superuser:
        raise Http404
    form = ArticleForm(request.POST or None, request.FILES or None)
    category = get_object_or_404(Category,
                                 menu_category__menu_name=item_slug,
                                 category_name=category_slug)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.article_user = get_object_or_404(Profile, user=request.user)
        instance.article_category = category
        instance.save()
        messages.success(request,
                         _("Ура, стаття сворена!"),
                         extra_tags='success')
        return HttpResponseRedirect(instance.get_absolute_url()
                                    )  # you can use return redirect(instance)
    title = _('Форма для створення статті')
    button_create = _('створити статтю')
    button_cancel = _('відміна')
    return_path = category.get_absolute_url()
    context = {
        'title': title,
        'button_create': button_create,
        'button_cancel': button_cancel,
        'form': form,
        'return_path': return_path,
    }
    return render(request, 'article_form.html', context)
Ejemplo n.º 5
0
def article_update(request, item_slug, category_slug, article_slug):
    if not request.user.is_staff or not request.user.is_superuser:
        # response = HttpResponse('<h1>Ти не маєш прав для оновлення статті!!!</h1')
        # response.status_code = 403
        # return response
        raise Http404
    title = _('Форма оновлення статті')
    button_create = _('змінити статтю')
    button_cancel = _('відміна')
    instance = get_object_or_404(Article, article_category__menu_category__menu_name=item_slug,
                                 article_category__category_name=category_slug, article_slug=article_slug)
    form = ArticleForm(request.POST or None, request.FILES or None, instance=instance)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.save()
        messages.success(request, _("Ура, стаття оновлена!"), extra_tags='success')
        return redirect(instance)
    return_path = instance.get_absolute_url()
    context = {
        'title': title,
        'button_create': button_create,
        'button_cancel': button_cancel,
        'return_path': return_path,
        'form': form,
        'article': instance,
        }
    return render(request, 'article_form.html', context)
Ejemplo n.º 6
0
def article_create(request, item_slug, category_slug=None):
    if not request.user.is_superuser:
        raise Http404
    form = ArticleForm(request.POST or None, request.FILES or None)
    category = get_object_or_404(Category,  menu_category__menu_name=item_slug, category_name=category_slug)
    if form.is_valid():
        instance = form.save(commit=False)
        instance.article_user = get_object_or_404(Profile, user=request.user)
        instance.article_category = category
        instance.save()
        messages.success(request, _("Ура, стаття сворена!"), extra_tags='success')
        return HttpResponseRedirect(instance.get_absolute_url())               # you can use return redirect(instance)
    title = _('Форма для створення статті')
    button_create = _('створити статтю')
    button_cancel = _('відміна')
    return_path = category.get_absolute_url()
    context = {
        'title': title,
        'button_create': button_create,
        'button_cancel': button_cancel,
        'form': form,
        'return_path': return_path,
        }
    return render(request, 'article_form.html', context)