Exemple #1
0
def TopicEdit(request, guid):
    topic = get_object_or_404(Topic, guid=guid, user=request.user)
    if request.method == "POST":
        f = TopicModelForm(request.POST or None, request.FILES, instance=topic)
        if f.is_valid():
            f.save()
            messages.add_message(request, messages.INFO, "Topic successfully changed.")
            return redirect("Replica:EditTopic", guid=topic.guid)
    else:
        f = TopicModelForm(instance=topic)
    ctx = {"form": f, "topic": topic, "adding": False}
    return render(request, "replica/dashboard/edit-topic.html", ctx)
Exemple #2
0
def TopicNew(request):
    instance = Topic(user=request.user)
    if request.method == "POST":
        f = TopicModelForm(request.POST or None, request.FILES, instance=instance)
        if f.is_valid():
            f.save()
            messages.add_message(request, messages.INFO, "New Topic.")
            return redirect("Replica:EditTopic", guid=instance.guid)
    else:
        f = TopicModelForm(instance=instance)
    ctx = {"form": f, "adding": True}
    return render(request, "replica/dashboard/edit-topic.html", ctx)