Exemplo n.º 1
0
def topic_create(request, slug):
    template_name = 'topics/form.html'
    context = {}

    if slug is None or slug == '':
        return redirect('not-found')

    discussion = Discussion.objects.get(slug=slug)

    if discussion is None:
        return redirect('not-found')

    if request.method == "POST":
        form = TopicForm(request.POST or None)
        if form.is_valid():
            c = form.save(commit=False)
            c.discussion = discussion
            c.moderator = request.user.professional
            c.save()
            return redirect(c.get_absolute_url())
    form = TopicForm()

    context['discussion'] = discussion
    context['form'] = form

    return render(request, template_name, context)
Exemplo n.º 2
0
def topic_create(request):
    ctx = {}
    template_name = 'forums/topic_create.html'

    topics = Topic.objects.all()
    topic_form = TopicForm()
    if request.method == "POST":
        topic_form = TopicForm(request.POST)
        if topic_form.is_valid():
            topic = topic_form.save()
            messages.success(request, "Topic <strong>%s</strong> was created" % (topic.title))
            return redirect(topic.get_absolute_url())

    ctx['topic_form'] = topic_form
    return render(request, template_name, ctx)
Exemplo n.º 3
0
def topic_create(request, category_slug):
    category = get_object_or_404(Category, slug=category_slug)
    if request.method == 'POST':
        form = TopicForm(request.POST, request.FILES)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.slug = slugify(f'{obj.subject} {obj.created}')
            obj.author = request.user
            obj.category = category
            obj.save()
            return redirect('forums:topic_list', category_slug=category.slug)
    else:
        form = TopicForm()

    context = {
        'category': category,
        'form': form,
    }

    return render(request, 'forums/topic_create.html', context)
Exemplo n.º 4
0
def topic_edit(request, category_slug, slug):
    category = get_object_or_404(Category, slug=category_slug)
    topic = get_object_or_404(Topic, slug=slug)

    if request.method == 'POST':
        form = TopicForm(request.POST, request.FILES, instance=topic)
        if form.is_valid():
            obj = form.save(commit=False)
            obj.slug = slugify(f'{obj.subject} {obj.created}')
            obj.category = category
            obj.save()
            return redirect('forums:topic_list', category_slug=category.slug)
    else:
        form = TopicForm(instance=topic)

    context = {
        'category': category,
        'topic': topic,
        'form': form,
    }

    return render(request, 'forums/topic_edit.html', context)