コード例 #1
0
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,
    })
コード例 #2
0
ファイル: messages.py プロジェクト: ppp0/openbroadcast
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,
    })
コード例 #3
0
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,
    })
コード例 #4
0
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
    })
コード例 #5
0
ファイル: topics.py プロジェクト: hzlf/openbroadcast
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
    })
コード例 #6
0
ファイル: messages.py プロジェクト: ppp0/openbroadcast
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,
    })
コード例 #7
0
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
    })
コード例 #8
0
ファイル: messages.py プロジェクト: ppp0/openbroadcast
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,
        })
コード例 #9
0
ファイル: views.py プロジェクト: ghy200692162/lab
def activity_create(request,template='activity_form.html'):
    if request.method == 'POST':
        form = ActivityForm(request.POST)
        if form.is_valid():
            activity = form.save(commit = False)
            activity.creator = User.objects.get(pk=1)#request.user
            activity.save()
            return redirect(request, activity)
    else:
        form = ActivityForm()
    return render(request,template,{'form':form})
コード例 #10
0
ファイル: views.py プロジェクト: mart-e/django-kopi
def comment_remove(request, object_id, template_name='comments/delete.html'):
    comment = get_object_or_404(KopiComment, pk=object_id)

    if MAX_SUBMIT_DATE > comment.submit_date:
        return comment_error(request, error_message=_('Too old comment'))

    if comment.session_id != request.session.session_key:
        return comment_error(request, error_message=_('You are not the author of the comment or your session has expired'))

    if request.method == 'POST':
        comment.delete()
        return redirect(request, comment.content_object)
    return render(request, template_name, {'comment': comment})
コード例 #11
0
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
    })
コード例 #12
0
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})
コード例 #13
0
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})
コード例 #14
0
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(),
    })
コード例 #15
0
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
    })
コード例 #16
0
ファイル: views.py プロジェクト: mart-e/django-kopi
def comment_edit(request, object_id, template_name='comments/edit.html'):
    """Edit the comment"""

    comment = get_object_or_404(KopiComment, pk=object_id)

    # check if can edit the comment
    if MAX_SUBMIT_DATE > comment.submit_date:
        return comment_error(request, error_message=_('Too old comment'))

    if comment.session_id != request.session.session_key:
        return comment_error(request, error_message=_('You are not the author of the comment or your session has expired'))

    # is the user submiting the form
    if request.method == 'POST':
        form = KopiCommentForm(comment, data=request.POST)
        if form.is_valid():
            # get the data in a processable form
            data = form.get_comment_create_data()
            comment.user_email = data['user_email']
            comment.user_name = data['user_name']
            comment.user_url = data['user_url']
            comment.comment = data['comment']
            comment.identifier = data['identifier']
            comment.save()
            return redirect(request, comment.content_object)
        else:
            pass
            #print(form.errors)

    else:
        comment_dic = model_to_dict(comment)
        comment_dic['name'] = comment.user_name
        comment_dic['email'] = comment.user_email
        comment_dic['url'] = comment.user_url
        form = KopiCommentForm(comment, data=comment_dic, initial=None)  
        security_dict = form.generate_security_data()
        # recreate the security fields
        form.data['content_type'] = security_dict['content_type']
        form.data['object_pk'] = security_dict['object_pk']
        form.data['timestamp'] = security_dict['timestamp']
        form.data['security_hash'] = security_dict['security_hash']

    return render(request, template_name, {
        'form': form,
        'comment': comment,
    })
コード例 #17
0
ファイル: topics.py プロジェクト: hzlf/openbroadcast
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})
コード例 #18
0
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})
コード例 #19
0
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})
コード例 #20
0
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})
コード例 #21
0
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
    })
コード例 #22
0
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,
    })
コード例 #23
0
ファイル: topics.py プロジェクト: hzlf/openbroadcast
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
    })