示例#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)
示例#2
0
文件: manage.py 项目: octaflop/uttr
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)
示例#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)
示例#4
0
文件: views.py 项目: chi1/trinitee
def topic_new(request, forum_id):
	forum = get_object_or_404(Forum, pk=forum_id)
	if not can_post_topic(request.user, forum):
		messages.error(request, "You are not allowed to to post new topics \
			on this forum.")
		return redirect(forum.get_absolute_url())
	if request.method == 'POST':
		form = TopicForm(request.POST)
		if form.is_valid():
			title = form.cleaned_data['title']
			content = form.cleaned_data['content']
			topic = Topic(title=title, author=request.user, forum=forum)
			topic.save()
			post = Post(topic=topic, author=request.user,
				author_ip=request.META['REMOTE_ADDR'], content=content)
			post.save()
			messages.success(request, "Your topic has been saved.")
			return redirect(topic.get_absolute_url())
	else:
		form = TopicForm()
	return {'forum': forum, 'form': form}
示例#5
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)