Пример #1
0
def index(request):
    queryset = Idea.objects.all().order_by("pk")
    if not request.user.is_staff:
        queryset = queryset.exclude(is_draft=True)
    form = IdeaForm()

    if request.method == "POST":
        next = request.POST["next"]
        form = IdeaForm(request.POST)

        if form.is_valid():
            idea = form.save()
            messages.success(request, u"Mensaje publicado con exito.")
            return redirect(next)
        else:
            return idea_new(request, form_instance=form)
    return render(request, "master.html", {"idea_form": form, "object_list": queryset})
Пример #2
0
def idea_detail(request, tag_name, object_id):
    queryset = Idea.objects.all()
    form = IdeaForm(initial={"tags": tag_name})
    idea = get_object_or_404(Idea, pk=object_id)

    if request.method == "POST":
        next = request.POST["next"]
        form = IdeaForm(request.POST, instance=idea)
        if form.is_valid():
            idea = form.save()
            messages.success(request, "Actualizaste el #%s" % (object_id))
            return redirect(next)
        else:
            return idea_new(request, tag_name=tag_name, object_id=object_id, form_instance=form)
    return render(
        request,
        "detail.html",
        {"idea_form": form, "tag": tag_name, "object": idea, "object_list": queryset.filter(tags__icontains=tag_name)},
    )
Пример #3
0
def index(request):
    queryset = Idea.objects.all().order_by('pk')
    if not request.user.is_staff:
        queryset = queryset.exclude(is_draft=True)
    form = IdeaForm()

    if request.method == 'POST':
        next = request.POST['next']
        form = IdeaForm(request.POST)

        if form.is_valid():
            idea = form.save()
            messages.success(request, u'Mensaje publicado con exito.')
            return redirect(next)
        else:
            return idea_new(request, form_instance=form)
    return render(request, 'master.html', {
        'idea_form': form,
        'object_list': queryset,
    })
Пример #4
0
def idea_detail(request, tag_name, object_id):
    queryset = Idea.objects.all()
    form = IdeaForm(initial={'tags': tag_name})
    idea = get_object_or_404(Idea, pk=object_id)

    if request.method == 'POST':
        next = request.POST['next']
        form = IdeaForm(request.POST, instance=idea)
        if form.is_valid():
            idea = form.save()
            messages.success(request, 'Actualizaste el #%s' % (object_id))
            return redirect(next)
        else:
            return idea_new(request,
                            tag_name=tag_name,
                            object_id=object_id,
                            form_instance=form)
    return render(
        request, 'detail.html', {
            'idea_form': form,
            'tag': tag_name,
            'object': idea,
            'object_list': queryset.filter(tags__icontains=tag_name),
        })