コード例 #1
0
ファイル: views.py プロジェクト: exploit97/SchooliEducation
def new_topic(request, forum_id):
    form = TopicForm()
    forum = get_object_or_404(Forum, pk=forum_id)

    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = form.cleaned_data['description']
            topic.forum = forum
            topic.creator = request.user

            topic.save()

            return HttpResponseRedirect(
                reverse('forum:forum-detail', args=(forum_id, )))

    return render(
        request,
        'forum/new-topic.html',
        {
            'form': form,
            'forum': forum,
        },
    )
コード例 #2
0
ファイル: views.py プロジェクト: pgwt/COC
def group(request, gurl_number):
    group = Group.objects(url_number=gurl_number).get()
    if request.method == "POST":
        form = NewTopicForm(request.POST)
        if form.is_valid():
            title = form.cleaned_data["title"]
            content = form.cleaned_data["content"]
            topic = Topic(title=title)
            turl_number = len(Topic.objects) + 1
            topic.url_number = turl_number
            topic.content = content
            topic.creat_time = datetime.datetime.now()
            topic.is_active = True
            topic.is_locked = False
            topic.is_top = False
            topic.clicks = 0
            topic.update_time = datetime.datetime.now()
            topic.update_author = request.user
            sgcard = S_G_Card.objects(user=request.user, group=group).get()
            topic.creator = sgcard
            topic.save()
            return HttpResponseRedirect("/group/" + str(gurl_number) + "/topic/" + str(turl_number) + "/")

    else:
        form = NewTopicForm()
        return render_to_response(
            "group/group.html",
            {"form": form, "group": group, "STATIC_URL": STATIC_URL, "current_user": request.user},
            context_instance=RequestContext(request),
        )
コード例 #3
0
ファイル: views.py プロジェクト: beadaut/daremo
def new_topic(request, slug):
    form = TopicForm()
    forum = get_object_or_404(Forum, slug=slug)

    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = ''
            topic.creator = request.user
            topic.save()

            topic.forums.add(forum)
            topic.save()

            post = Post()
            post.title = form.cleaned_data['title']
            post.body = form.cleaned_data['description']
            post.creator = request.user
            post.user_ip = request.META['REMOTE_ADDR']
            post.topic = topic
            post.save()
            return HttpResponseRedirect(reverse('topic-detail', args=(slug, topic.id, )))

    return render(request, 'forum/new-topic.html', {'form': form, 'forum': forum})
コード例 #4
0
ファイル: views.py プロジェクト: exploit97/SchooliEducation
def question_topic(request):
    form = TopicForm2()

    if request.method == 'POST':
        form = TopicForm2(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = form.cleaned_data['description']
            topic.forum = form.cleaned_data['forum']
            topic.creator = request.user

            topic.save()

            return HttpResponseRedirect(reverse('forum:forum-index'))

    return render(
        request,
        'forum/question-topic.html',
        {
            'form': form,
        },
    )
コード例 #5
0
ファイル: views.py プロジェクト: atirados/CS425-Final-Project
def new_topic(request, forum_id):
    form = TopicForm()
    forum = get_object_or_404(Forum, pk=forum_id)

    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = form.cleaned_data['description']
            topic.forum = forum
            topic.creator = request.user
            userToUpdate = UserProfile.objects.get(user=request.user)
            nCredits = userToUpdate.credits
            userToUpdate.credits = int(float(nCredits + 200))

            # TODO: Change status (if points+100>threshold -> status changes)
            # Alert? Maybe return to page with status update info for user.
            # Make Gold/Platinum distinction

            if nCredits + 200 >= GOLD_THRESHOLD:
                newStatus = "Gold"
                userToUpdate.status = newStatus
                userToUpdate.save()
                topic.save()
                return render_to_response(
                    "forum/status_change.html", {'status': newStatus},
                    context_instance=RequestContext(request))
            elif nCredits + 100 >= PLATINUM_THRESHOLD:
                newStatus = "Platinum"
                userToUpdate.status = newStatus
                userToUpdate.save()
                topic.save()
                return render_to_response(
                    "forum/status_change.html", {'status': newStatus},
                    context_instance=RequestContext(request))
            else:
                userToUpdate.save()
                topic.save()
                return HttpResponseRedirect(
                    reverse('forum-detail', args=(forum_id, )))

    return render_to_response('forum/new-topic.html', {
        'form': form,
        'forum': forum,
    },
                              context_instance=RequestContext(request))
コード例 #6
0
ファイル: views.py プロジェクト: atirados/CS425-Final-Project
def new_topic(request, forum_id):
    form = TopicForm()
    forum = get_object_or_404(Forum, pk=forum_id)

    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = form.cleaned_data['description']
            topic.forum = forum
            topic.creator = request.user
            userToUpdate = UserProfile.objects.get(user=request.user)
            nCredits = userToUpdate.credits
            userToUpdate.credits = int(float(nCredits + 200))

            # TODO: Change status (if points+100>threshold -> status changes)
            # Alert? Maybe return to page with status update info for user.
            # Make Gold/Platinum distinction

            if nCredits + 200 >= GOLD_THRESHOLD:
                newStatus = "Gold"
                userToUpdate.status = newStatus
                userToUpdate.save()
                topic.save()
                return render_to_response("forum/status_change.html", {'status':  newStatus}, context_instance=RequestContext(request))
            elif nCredits + 100 >= PLATINUM_THRESHOLD:
                newStatus = "Platinum"
                userToUpdate.status = newStatus
                userToUpdate.save()
                topic.save()
                return render_to_response("forum/status_change.html", {'status':  newStatus}, context_instance=RequestContext(request))
            else:
                userToUpdate.save()
                topic.save()
                return HttpResponseRedirect(reverse('forum-detail', args=(forum_id, )))

    return render_to_response('forum/new-topic.html', {
        'form': form,
        'forum': forum,
    }, context_instance=RequestContext(request))
コード例 #7
0
ファイル: views.py プロジェクト: LunaSquee/lunasqu.ee-django
def new_topic(request, forum_id):
    form = TopicForm()
    forum = get_object_or_404(Forum, pk=forum_id)
    user = request.user

    if forum.closed and not user.has_perm('forum.can_post_lock_forum'):
        return render(request, 'personal/basic.html',
                      {'content': ['This forum is locked.']})

    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = bleach_clean(form.cleaned_data['description'])
            topic.forum = forum
            topic.creator = user

            topic.save()

            tpkPost = Post()
            tpkPost.topic = topic
            tpkPost.title = topic.title
            tpkPost.body = bleach_clean(form.cleaned_data['description'])
            tpkPost.creator = user
            tpkPost.user_ip = get_client_ip(request)

            tpkPost.save()

            return HttpResponseRedirect(
                reverse('topic-detail', args=(
                    topic.id,
                    topic.slug,
                )))

    return render_to_response('forum/new-topic.html', {
        'form': form,
        'forum': forum,
    },
                              context_instance=RequestContext(request))
コード例 #8
0
ファイル: views.py プロジェクト: hydrospanner/DForurm
def new_topic(request, slug):
    form = TopicForm()
    forum = get_object_or_404(Forum, slug=slug)
    
    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():
            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = form.cleaned_data['description']
            topic.forum = forum
            topic.creator = request.user

            topic.save()

            return HttpResponseRedirect(reverse('forum:forum-detail', args=(forum.slug, )))

    context = get_base_context()
    context.update({'form': form, 'forum': forum})
    return render(request, 'forum/new-topic.html', context)
コード例 #9
0
ファイル: views.py プロジェクト: boyombo/pharmrep
def new_topic(request, forum_id):
    form = TopicForm()
    forum = get_object_or_404(Forum, pk=forum_id)

    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = form.cleaned_data['description']
            topic.forum = forum
            topic.creator = request.user

            topic.save()

            return HttpResponseRedirect(reverse('forum-detail', args=(forum_id, )))

    return render_to_response('django_simple_forum/new-topic.html', {
            'form': form,
            'forum': forum,
        }, context_instance=RequestContext(request))
コード例 #10
0
ファイル: views.py プロジェクト: LunaSquee/lunasqu.ee-django
def new_topic(request, forum_id):
    form = TopicForm()
    forum = get_object_or_404(Forum, pk=forum_id)
    user = request.user
    
    if forum.closed and not user.has_perm('forum.can_post_lock_forum'):
        return render(request, 'personal/basic.html', {'content':['This forum is locked.']})

    if request.method == 'POST':
        form = TopicForm(request.POST)

        if form.is_valid():

            topic = Topic()
            topic.title = form.cleaned_data['title']
            topic.description = bleach_clean(form.cleaned_data['description'])
            topic.forum = forum
            topic.creator = user

            topic.save()

            tpkPost = Post()
            tpkPost.topic = topic
            tpkPost.title = topic.title
            tpkPost.body = bleach_clean(form.cleaned_data['description'])
            tpkPost.creator = user
            tpkPost.user_ip = get_client_ip(request)

            tpkPost.save()

            return HttpResponseRedirect(reverse('topic-detail', args=(topic.id, topic.slug, )))

    return render_to_response('forum/new-topic.html', {
            'form': form,
            'forum': forum,
        }, context_instance=RequestContext(request))
コード例 #11
0
ファイル: views.py プロジェクト: mpate337/CourseWeb
def new_topic(request, forum_id):
    if 'userid' in request.session:
        form = TopicForm()
        forum = get_object_or_404(Forum, pk=forum_id)

        status = 'student'
        stud_obj = student.objects.get(pk=request.session['userid'])
        username = stud_obj.uname

        if request.method == 'POST':
            form = TopicForm(request.POST)

            if form.is_valid():
                topic = Topic()
                topic.title = form.cleaned_data['title']
                topic.description = form.cleaned_data['description']
                topic.forum = forum
                obj = student.objects.get(pk=request.session['userid'])
                topic.creator = obj

                topic.save()

                return HttpResponseRedirect(
                    reverse('forum-detail', args=(forum_id, )))

        return render(
            request,
            'forum/new-topic.html',
            {
                'form': form,
                'forum': forum,
                'username': username,
                'status': status
            },
        )
    elif 'instructorid' in request.session:
        form = TopicForm()
        forum = get_object_or_404(Forum, pk=forum_id)

        status = 'instructor'
        inst_obj = instructor.objects.get(pk=request.session['instructorid'])
        username = inst_obj.uname

        if request.method == 'POST':
            form = TopicForm(request.POST)

            if form.is_valid():
                topic = Topic()
                topic.title = form.cleaned_data['title']
                topic.description = form.cleaned_data['description']
                topic.forum = forum
                obj = instructor.objects.get(
                    pk=request.session['instructorid'])
                topic.by_instructor = obj

                topic.save()

                return HttpResponseRedirect(
                    reverse('forum-detail', args=(forum_id, )))

        return render(
            request,
            'forum/new-topic.html',
            {
                'form': form,
                'forum': forum,
                'username': username,
                'status': status
            },
        )
    else:
        return HttpResponseRedirect('/joinus/login/')