예제 #1
0
파일: views.py 프로젝트: pgwt/COC
def showtopic(request, gurl_number, turl_number):
    group = Group.objects(url_number=gurl_number).get()
    topic = Topic.objects(url_number=turl_number).get()
    topic.clicks += 1
    topic.save()
    if request.method == "POST":
        form = NewPostForm(request.POST)
        if form.is_valid():
            content = form.cleaned_data["content"]
            post = Post(content=content)
            post.author = request.user
            post.creat_time = datetime.datetime.now()
            post.floor = Post.objects(topic=topic).count() + 1
            post.topic = topic
            post.is_active = True
            post.save()
            topic.update_author = request.user
            topic.update_time = datetime.datetime.now()
            topic.save()
            return HttpResponseRedirect("/group/" + str(gurl_number) + "/topic/" + str(turl_number) + "/")

    else:
        form = NewPostForm()
        return render_to_response(
            "group/group_topic.html",
            {"group": group, "current_user": request.user, "form": form, "topic": topic, "STATIC_URL": STATIC_URL},
            context_instance=RequestContext(request),
        )
예제 #2
0
def PostCreate(request):
    author = User.objects.get(pk=request.user.id)
    if request.method == 'POST':
        column_id = request.POST.get("column", "")
        column = get_object_or_404(Column, pk=int(column_id))
        title = request.POST.get("title", "")
        content = request.POST.get("content", "")
        form = PostForm(request.POST)
        errors = []
        if form.is_valid():
            post = Post()
            post.title = title
            post.content = content
            post.author = author
            post.column = column
            post.save()
            #request.POST.get_absolute_url()
            return HttpResponseRedirect(reverse_lazy('forum:index'))
        else:
            #如果表单不正确,保存错误到errors列表中
            for k, v in form.errors.items():
                #v.as_text() 详见django.forms.util.ErrorList 中
                errors.append(v.as_text())
            if errors:
                return render(request, 'user_fail.html', {"errors": errors})
    else:
        form = PostForm()
        #next = request.GET.get('next',None)
        #if next is None:
        #next = reverse_lazy('index')
        columns_list = Column.objects.all()
        return render(request, 'AddPost.html', {
            "form": form,
            "columns_list": columns_list
        })
예제 #3
0
    def save(self, request):
        post = Post()
        post.title = self.cleaned_data['title']
        post.text = self.cleaned_data['text']
        post.author = get_object_or_404(Profile, user=request.user)
        post.pub_date = timezone.now()
        tag = self.cleaned_data['tag']
        post.save()
        list_of_tags(post, tag)
        post.save()

        return post
예제 #4
0
def mkpost(content="Test post.", creation_date=datetime.datetime.now()):
    """Helper function for making posts."""
    p = Post()

    # _plain == _html, since the conversion happens in views.py,
    # which the object creation is not run through
    p.content_plain, p.content_html = content, content
    p.creation_date = creation_date
    p.author = mkuser()
    p.thread = mkthread()
    p.save()

    return p
예제 #5
0
def mkpost(content="Test post.",
           creation_date=datetime.datetime.now()):
    """Helper function for making posts."""
    p = Post()

    # _plain == _html, since the conversion happens in views.py,
    # which the object creation is not run through
    p.content_plain, p.content_html = content, content
    p.creation_date = creation_date
    p.author = mkuser()
    p.thread = mkthread()
    p.save()

    return p
예제 #6
0
    def post(self, request, *args, **kwargs):
        form = PostForm(request.POST or None)
        print('test2')
        print(request.POST)

        if form.is_valid():
            print('test3')
            post_data = Post()
            post_data.author = request.user
            post_data.title = form.cleaned_data['title']
            post_data.text = form.cleaned_data['text']
            category = form.cleaned_data['category']
            category_data = Category.objects.filter(name=category)[0]
            post_data.category = category_data
            post_data.save()
            print('test')
            return redirect('forum:post_detail', post_data.id)

        return render(request, 'forum/post_form.html', {'form': form})