login_required render_to discussion create html def topic_create reque

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
@login_required
@render_to('discussion/create.html')
def topic_create(request, group_slug):
group = get_object_or_404(UserGroup, slug=group_slug)
if not group.can_post(request.user):
raise Http403(_('You can\' post comments in this group!'))
if request.method == 'POST':
form = forms.TopicCreateForm(request.user, group, request.POST)
if form.is_valid():
topic = form.save()
return HttpResponseRedirect(topic.get_absolute_url())
else:
form = forms.TopicCreateForm(request.user, group)
return {'group': group, 'form': form}