def page_create(request, slug, template_name='groups/pages/page_form.html'): """ Creates a group page. Templates: ``groups/pages/page_form.html`` Context: group Group object form PageForm object """ group = get_object_or_404(Group, slug=slug) form = GroupPageForm(initial={'group': group}) if request.method == 'POST': form = GroupPageForm(request.POST) if form.is_valid(): page = form.save(commit=False) page.group = group page.save() return redirect(request, page) return render(request, template_name, { 'group': group, 'form': form })
def message_edit(request, slug, topic_id, message_id, template_name='groups/messages/message_form.html'): """ Returns a group message edit form. Templates: ``groups/messages/message_form.html`` Context: group Group object topic GroupTopic object message GroupMessage object form GroupMessageForm object """ message = get_object_or_404(GroupMessage, pk=message_id, is_active=True) if request.method == 'POST': form = GroupMessageForm(request.POST, instance=message) if form.is_valid(): form.save() return redirect(request, message.topic) else: form = GroupMessageForm(instance=message) return render(request, template_name, { 'group': message.topic.group, 'topic': message.topic, 'message': message, 'form': form, })
def message_create(request, slug, topic_id, template_name='groups/messages/message_form.html'): """ Returns a group message form. Templates: ``groups/messages/message_form.html`` Context: group Group object topic GroupTopic object form GroupMessageForm object """ group = get_object_or_404(Group, slug=slug) topic = get_object_or_404(GroupTopic, pk=topic_id, group=group) if request.method == 'POST': form = GroupMessageForm(request.POST) if form.is_valid(): message = form.save(commit=False) message.user = request.user message.topic = topic message.save() return redirect(request, topic) else: form = GroupMessageForm() return render(request, template_name, { 'group': group, 'topic': topic, 'form': form, })
def topic_edit(request, slug, topic_id, template_name='groups/topics/topic_form.html'): """ Returns a group topic form page. Templates: ``groups/topics/topic_form.html`` Context: form GroupTopicForm object topic GroupTopic object """ group = get_object_or_404(Group, slug=slug) topic = get_object_or_404(GroupTopic, pk=topic_id, group=group, user=request.user) if request.method == 'POST': form = GroupTopicForm(request.POST, instance=topic) if form.is_valid(): form.save() return redirect(request, topic) else: form = GroupTopicForm(instance=topic) return render(request, template_name, { 'form': form, 'group': group, 'topic': topic })
def comment_remove(request, object_id, template_name='comments/delete.html'): comment = get_object_or_404(Comment, pk=object_id, user=request.user) if DELTA > comment.submit_date: return comment_error(request) if request.method == 'POST': comment.delete() return redirect(request, comment.content_object) return render(request, template_name, {'comment': comment})
def page_remove(request, slug, page_slug, template_name='groups/pages/page_remove_confirm.html'): group = get_object_or_404(Group, slug=slug) page = get_object_or_404(GroupPage, group=group, slug=page_slug) if request.method == 'POST': page.delete() return redirect(request, group) return render(request, template_name, {'group': group, 'page': page})
def page_remove(request, slug, page_slug, template_name='groups/pages/page_remove_confirm.html'): group = get_object_or_404(Group, slug=slug) page = get_object_or_404(GroupPage, group=group, slug=page_slug) if request.method == 'POST': page.delete() return redirect(request, group) return render(request, template_name, { 'group': group, 'page': page })
def group_join(request, slug, template_name='groups/group_join_confirm.html'): """ Returns a group join confirmation page. Templates: ``groups/group_join_confirm.html`` Context: group Group object """ group = get_object_or_404(Group, slug=slug, is_active=True) if request.method == 'POST': membership = GroupMember(group=group, user=request.user) membership.save() return redirect(request, group) return render(request, template_name, {'group': group})
def group_remove(request, slug, template_name='groups/group_remove_confirm.html'): """ Returns a group delete confirmation page. Templates: ``groups/group_remove_confirm.html`` Context: group Group object """ group = get_object_or_404(Group, slug=slug, creator=request.user) if request.method == 'POST': group.is_active = False group.save() return redirect(request, reverse('groups:groups')) return render(request, template_name, {'group': group})
def group_detail(request, slug, template_name='groups/group_detail.html'): """ Returns a group detail page. Templates: ``groups/group_detail.html`` Context: group Group object """ group = get_object_or_404(Group, slug=slug, is_active=True) if group.invite_only and not GroupMember.objects.is_member(group, request.user): return redirect(request, reverse('groups:join', kwargs={'slug': group.slug})) return render(request, template_name, { 'group': group, 'topic_list': group.topics.all(), })
def page_edit(request, slug, page_slug, template_name='groups/pages/page_form.html'): group = get_object_or_404(Group, slug=slug) page = get_object_or_404(GroupPage, group=group, slug=page_slug) form = GroupPageForm(instance=page) if request.method == 'POST': form = GroupPageForm(request.POST, instance=page) if form.is_valid(): page = form.save() return redirect(request, page) return render(request, template_name, { 'group': group, 'page': page, 'form': form })
def comment_edit(request, object_id, template_name='comments/edit.html'): comment = get_object_or_404(Comment, pk=object_id, user=request.user) if DELTA > comment.submit_date: return comment_error(request) if request.method == 'POST': form = CommentForm(request.POST, instance=comment) if form.is_valid(): form.save() return redirect(request, comment.content_object) else: form = CommentForm(instance=comment) return render(request, template_name, { 'form': form, 'comment': comment, })
def topic_remove(request, slug, topic_id, template_name='groups/topics/topic_remove_confirm.html'): """ Returns a group topic delete confirmation page. Templates: ``groups/topics/topic_remove_confirm.html`` Context: topic GroupTopic object """ group = get_object_or_404(Group, slug=slug) topic = get_object_or_404(GroupTopic, pk=topic_id, group=group, user=request.user) if request.method == 'POST': topic.is_active = False topic.save() return redirect(request, group) return render(request, template_name, {'topic': topic})
def group_detail(request, slug, template_name='groups/group_detail.html'): """ Returns a group detail page. Templates: ``groups/group_detail.html`` Context: group Group object """ group = get_object_or_404(Group, slug=slug, is_active=True) if group.invite_only and not GroupMember.objects.is_member( group, request.user): return redirect(request, reverse('groups:join', kwargs={'slug': group.slug})) return render(request, template_name, { 'group': group, 'topic_list': group.topics.all(), })
def group_create(request, template_name='groups/group_form.html'): """ Returns a group form page. Templates: ``groups/group_form.html`` Context: form GroupForm object """ if request.method == 'POST': form = GroupForm(request.POST, request.FILES) if form.is_valid(): group = form.save(commit=False) group.creator = request.user group.save() creator = GroupMember.objects.create(user=request.user, group=group, status=0) return redirect(request, group) else: form = GroupForm() return render(request, template_name, {'form': form})
def group_edit(request, slug, template_name='groups/group_form.html'): """ Returns a group form page. Templates: ``groups/group_form.html`` Context: form GroupForm object group Group object """ group = get_object_or_404(Group, slug=slug, creator=request.user) form = GroupForm(instance=group) if request.method == 'POST': form = GroupForm(request.POST, request.FILES, instance=group) if form.is_valid(): form.save() return redirect(request, group) return render(request, template_name, {'form': form, 'group': group})
def group_edit(request, slug, template_name='groups/group_form.html'): """ Returns a group form page. Templates: ``groups/group_form.html`` Context: form GroupForm object group Group object """ group = get_object_or_404(Group, slug=slug, creator=request.user) form = GroupForm(instance=group) if request.method == 'POST': form = GroupForm(request.POST, request.FILES, instance=group) if form.is_valid(): form.save() return redirect(request, group) return render(request, template_name, { 'form': form, 'group': group })
def page_create(request, slug, template_name='groups/pages/page_form.html'): """ Creates a group page. Templates: ``groups/pages/page_form.html`` Context: group Group object form PageForm object """ group = get_object_or_404(Group, slug=slug) form = GroupPageForm(initial={'group': group}) if request.method == 'POST': form = GroupPageForm(request.POST) if form.is_valid(): page = form.save(commit=False) page.group = group page.save() return redirect(request, page) return render(request, template_name, {'group': group, 'form': form})
def message_remove(request, slug, topic_id, message_id, template_name='groups/messages/message_remove_confirm.html'): """ Returns a message delete confirmation page. Templates: ``groups/messages/message_remove_confirm.html`` Context: group Group object topic GroupTopic object message GroupMessage object """ message = get_object_or_404(GroupMessage, pk=message_id, is_active=True) if request.method == 'POST': message.is_active = False message.save() return redirect(request, message.topic) return render(request, template_name, { 'group': message.topic.group, 'topic': message.topic, 'message': message, })
def topic_create(request, slug, template_name='groups/topics/topic_form.html'): """ Returns a group topic form page. Templates: ``groups/topics/topic_form.html`` Context: form GroupTopicForm object """ group = get_object_or_404(Group, slug=slug) if request.method == 'POST': form = GroupTopicForm(request.POST) if form.is_valid(): topic = form.save(commit=False) topic.user = request.user topic.group = group topic.save() return redirect(request, topic) else: form = GroupTopicForm() return render(request, template_name, { 'form': form, 'group': group })