当前位置: 首页>>代码示例>>Python>>正文


Python models.Post类代码示例

本文整理汇总了Python中forum.models.Post的典型用法代码示例。如果您正苦于以下问题:Python Post类的具体用法?Python Post怎么用?Python Post使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了Post类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: _topic_create_POST

def _topic_create_POST(request):
    commit = True
    try:
        post = Post(author=request.forum_user)
        post_form = PostForm(request.POST, instance=post)
        if post_form.is_valid():
            post = post_form.save()
            topic = Topic(author=request.forum_user, first_post=post,
                    last_post=post)
            topic_form = TopicForm(request.POST, instance=topic)
            if topic_form.is_valid():
                topic = topic_form.save()
                post.topic = topic
                post.save()
                for category in topic.categories.all():
                    category.topic_count = category.topic_set.all().count()
                    category.post_count = Post.objects\
                            .filter(topic__in=category.topic_set.all()).count()
                    category.save()
                return redirect(post.get_absolute_url())
        else:
            post_form = PostForm(request.POST)
        ctx = {
            'forum_user': request.forum_user,
            'topic_form': topic_form,
            'post_form': post_form,
        }
        return render(request, 'forum/topic/create.html', ctx)

    finally:
        if commit:
            transaction.commit()
        else:
            transaction.rollback()
开发者ID:archlinuxpl,项目名称:2.archlinux.pl,代码行数:34,代码来源:views.py

示例2: addPost

def addPost(request):
	if request.user.is_authenticated():
		#Gets all the userinput data. And the hidden input fields that contains the ID's of the forum and thread the user is located in.
		postContent = request.GET['postContent']
		forum_key = request.GET['forum_key']
		thread_key = request.GET['thread_key']
		
		#A cleaner that scans trough the thread description the users typed in and replaces the \n line breakers with html linebreakers (<br>)
		cleanPost = ""
		for a in postContent:
			if a in '\n':
				a += r'<br>'
			cleanPost += a
		#Creates a instance of a user so the Thred is bound to a creator.
		user = User.objects.get(username__exact=request.user.username)	
		key_forum = Forum.objects.get(id=forum_key)
		key_thread = Thread.objects.get(id=thread_key, key_forum=forum_key)
		
		#creates a new insance of Post, inserts the values and finaly saves them.
		newPost = Post(content=cleanPost, displays=0, author= user, key_forum=key_forum, key_thread=key_thread )
		newPost.save()
		bool = True
		return HttpResponseRedirect(reverse('forum.views.viewPosts', args=(forum_key,thread_key)))	
	else:
		bool = False
		return HttpResponseRedirect(reverse('forum.views.viewForum'))
开发者ID:hellotheremike,项目名称:django-forum,代码行数:26,代码来源:add.py

示例3: reply

def reply(request, thread):
    """
    If a thread isn't closed, and the user is logged in, post a reply
    to a thread. Note we don't have "nested" replies at this stage.
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("%s?next=%s" % (LOGIN_URL, request.path))
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return HttpResponseServerError()
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            body = form.cleaned_data["body"]
            p = Post(thread=t, author=request.user, body=body, time=datetime.now())
            p.save()

            # Send notifications (if installed)
            if notification:
                notification.send(
                    User.objects.filter(forum_post_set__thread=t).distinct(),
                    "forum_new_reply",
                    {"post": p, "thread": t, "site": Site.objects.get_current()},
                )

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()

    return render_to_response(
        "forum/reply.html", RequestContext(request, {"form": form, "forum": t.forum, "thread": t})
    )
开发者ID:incuna,项目名称:django-forum-pinax,代码行数:35,代码来源:views.py

示例4: newthread

def newthread(request, forum):
    """
    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()
    f = get_object_or_404(Forum, slug=forum)
    t = Thread(
        forum=f,
        title=request.POST.get('title'),
    )
    t.save()
    p = Post(
        thread=t,
        author=request.user,
        body=request.POST.get('body'),
        time=datetime.now(),
    )
    p.save()
    if request.POST.get('subscribe',False):
        s = Subscription(
            author=request.user,
            thread=t
            )
        s.save()
    return HttpResponseRedirect(t.get_absolute_url())
开发者ID:tristan,项目名称:hydrant,代码行数:30,代码来源:views.py

示例5: newthread

def newthread(request, forum):
    """
    新建帖子
    """
    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
        return Http404

    if request.method == 'POST':
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            t = Thread(
                forum=f,
                title=form.cleaned_data['title'],
            )
            t.save()

            p = Post(
                thread=t,
                author=request.user,
                body=form.cleaned_data['body'],
                time=datetime.now(),
            )
            p.save()

            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response('forum/newthread.html',
                              RequestContext(request, {'form': form,
                                                       'forum': f,
                                                       }))
开发者ID:lty1,项目名称:platform_django,代码行数:34,代码来源:views.py

示例6: new_topic

def new_topic(request):
    user = request.user
    if request.method == 'POST':
        form = NewTopicForm(request.POST)

        if form.is_valid():
            category = form.cleaned_data['category']
            topic = Topic(title=form.cleaned_data['title'],
                          author=user,
                          category=category
            )
            topic.save()

            first_post = Post(topic=topic,
                              author=user,
                              date_published=topic.date_published,
                              content=form.cleaned_data['content'])
            first_post.save()
            return HttpResponseRedirect(topic.get_absolute_url())
    else:
        form = NewTopicForm()

    return render(request, 'xadmin/new_topic.html', {
        'form': form
    })
开发者ID:csimstu,项目名称:cornucopia,代码行数:25,代码来源:views.py

示例7: reply

def reply(request, thread):
    """
    回复帖子子
    条件:
    1、帖子允许回复,没有关闭
    2、当前用户登录
    """
    t = get_object_or_404(Thread, pk=thread)
    if t.closed:
        return Http404
    if not Forum.objects.has_access(t.forum, request.user.groups.all()):
        return Http404

    if request.method == "POST":
        form = ReplyForm(request.POST)
        if form.is_valid():
            body = form.cleaned_data['body']
            p = Post(
                thread=t, 
                author=request.user,
                body=body,
                time=datetime.now(),
                )
            p.save()

            return HttpResponseRedirect(p.get_absolute_url())
    else:
        form = ReplyForm()

    return render_to_response('forum/reply.html',
                              RequestContext(request, {'form': form,
                                                       'forum': t.forum,
                                                       'thread': t,
                                                       }))
开发者ID:lty1,项目名称:platform_django,代码行数:34,代码来源:views.py

示例8: save

    def save(self, commit=True):
        if not self.topic:
            # if this post create new topic, create this corresponding topic
            topic = Topic(forum=self.forum,
                          title=escape(self.cleaned_data['title']),
                          created_by=self.user,
                          updated_by=self.user)
            topic.save()
            self.topic = topic
            topic_post = True
        else:
            topic = self.topic
            topic_post = False

        post = Post(topic=topic,
                    created_by=self.user,
                    updated_by=self.user,
                    topic_post=topic_post,
                    content=self.cleaned_data['content'],
                    reply_on=self.parent)
        post.topic = topic
        if commit:
            post.save()
            if topic_post:
                topic.post = post
                topic.content = post.content
                topic.save()

        return post
开发者ID:chequochuu,项目名称:vnoiwebsite,代码行数:29,代码来源:forms.py

示例9: newthread

def newthread(request, forum):
    """
    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseRedirect("%s?next=%s" % (LOGIN_URL, request.path))

    f = get_object_or_404(Forum, slug=forum)

    if not Forum.objects.has_access(f, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == "POST":
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            t = Thread(forum=f, title=form.cleaned_data["title"])
            t.save()

            p = Post(thread=t, author=request.user, body=form.cleaned_data["body"], time=datetime.now())
            p.save()

            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response("forum/newthread.html", RequestContext(request, {"form": form, "forum": f}))
开发者ID:incuna,项目名称:django-forum-pinax,代码行数:30,代码来源:views.py

示例10: showtopic

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),
        )
开发者ID:pgwt,项目名称:COC,代码行数:28,代码来源:views.py

示例11: create_post

 def create_post(self, author, thread):
     new_post = Post(
         content = self.cleaned_data.get('content'),
         thread = thread,
         author = author,
         created = datetime.datetime.now(),
     )
     new_post.save()
     thread.most_recent_post = new_post
     thread.save()
     return new_post
开发者ID:Oscarchase,项目名称:Intra-Django,代码行数:11,代码来源:forms.py

示例12: create

def create(request, category_id):
    """Creation of a new thread from a category id.

    Shows a preview of the thread, if the user pressed
    the 'Preview' button instead of 'Reply'.
    """
    category       = get_object_or_404(Category, pk=category_id)
    preview_plain  = False
    preview_html   = False
    title_plain    = False

    if request.method == 'POST':  # Form has been submitted
        title_plain = request.POST['title']
        title_html  = prettify_title(title_plain)
        text_plain  = request.POST['content']
        if "submit" in request.POST:  # "submit" button pressed
            if len(title_plain) > MAX_THREAD_TITLE_LENGTH:
                messages.error(request, long_title_error % MAX_THREAD_TITLE_LENGTH)
                preview_plain = text_plain
                preview_html  = sanitized_smartdown(text_plain)
            else:
                user      = request.user
                now       = datetime.now()  # UTC?
                text_html = sanitized_smartdown(text_plain)
                try:
                    t = Thread(title_plain=title_plain, title_html=title_html,
                               author=user, category=category,
                               creation_date=now, latest_reply_date=now)
                    t.save()
                    p = Post(thread=t, creation_date=now, author=user,
                             content_plain=text_plain, content_html=text_html)
                    p.save()
                    t.subscriber.add(request.user)
                except OperationalError:  # Database interaction error
                    messages.error(request, "%s") % operational_error
                else:
                    # After successful submission
                    return HttpResponseRedirect(reverse('forum.views.thread',
                        args=(user.thread_set.all().order_by('-creation_date')[0].id,)))
        elif "preview" in request.POST:  # "preview" button pressed
            preview_plain = text_plain
            preview_html  = sanitized_smartdown(text_plain)

    return render(request, 'create.html',
                          {'full_url'     : request.build_absolute_uri(),
                           'current_site' : Site.objects.get_current(),
                           'category'     : category,
                           'title'        : title_plain,
                           'preview_plain': preview_plain,
                           'preview_html' : preview_html})
开发者ID:alrobeler,项目名称:dotcloud-django,代码行数:50,代码来源:views.py

示例13: post_reply

def post_reply(request, topic_id):
    form = PostForm()
    topic = Topic.objects.get(pk=topic_id)
    user = request.user

    if topic.closed:
        return render(request, 'personal/basic.html', {'content':['This topic is closed.']})

    if topic.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 = PostForm(request.POST)

        if form.is_valid():

            post = Post()
            post.topic = topic
            post.title = 'RE: '+topic.title
            post.body = bleach_clean(form.cleaned_data['body'])
            post.creator = request.user
            post.user_ip = get_client_ip(request)

            post.save()

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

    return render_to_response('forum/reply.html', {
            'form': form,
            'topic': topic,
            'forum': topic.forum,
            'editing': False,
        }, context_instance=RequestContext(request))
开发者ID:LunaSquee,项目名称:lunasqu.ee-django,代码行数:33,代码来源:views.py

示例14: newthread

def newthread(request, forum):
    """
    Rudimentary post function - this should probably use 
    newforms, although not sure how that goes when we're updating 
    two models.

    Only allows a user to post if they're logged in.
    """
    if not request.user.is_authenticated():
        return HttpResponseServerError()

    f = get_object_or_404(Forum, slug=forum)
    
    if not Forum.objects.has_access(f, request.user.groups.all()):
        return HttpResponseForbidden()

    if request.method == 'POST':
        form = CreateThreadForm(request.POST)
        if form.is_valid():
            t = Thread(
                forum=f,
                title=form.cleaned_data['title'],
            )
            t.save()

            p = Post(
                thread=t,
                author=request.user,
                body=form.cleaned_data['body'],
                time=datetime.now(),
            )
            p.save()
    
            if form.cleaned_data.get('subscribe', False):
                s = Subscription(
                    author=request.user,
                    thread=t
                    )
                s.save()
            return HttpResponseRedirect(t.get_absolute_url())
    else:
        form = CreateThreadForm()

    return render_to_response('forum/newthread.html',
        RequestContext(request, {
            'form': form,
            'forum': f,
        }))
开发者ID:RockHoward,项目名称:django-forum,代码行数:48,代码来源:views.py

示例15: save

 def save(self):
     topic_post = False
     if not self.topic:
         topic = Topic(forum=self.forum,
                       posted_by=self.user,
                       subject=self.cleaned_data['subject'])
         topic_post = True
         topic.save()
     else:
         topic = self.topic
     post = Post(topic=topic, posted_by=self.user, poster_ip=self.ip,
                 message=self.cleaned_data['message'], topic_post=topic_post)
     post.save()
     attachments = self.cleaned_data['attachments']
     post.update_attachments(attachments)
     return post
开发者ID:indexofire,项目名称:gravoicy,代码行数:16,代码来源:forms.py


注:本文中的forum.models.Post类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。