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


Python Topic.get_absolute_url方法代码示例

本文整理汇总了Python中models.Topic.get_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:Python Topic.get_absolute_url方法的具体用法?Python Topic.get_absolute_url怎么用?Python Topic.get_absolute_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Topic的用法示例。


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

示例1: topic_new

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_absolute_url [as 别名]
def topic_new(request, template_name='private_messages/topic_new.html'):
    if request.method == 'POST':
        form = NewTopicForm(data=request.POST)
        if form.is_valid():
            message = form.save(commit=False)

            topic = Topic(sender=request.user)
            topic.recipient = form.cleaned_data['recipient']
            topic.subject = form.cleaned_data['subject']
            topic.last_sent_at = datetime.now()
            topic.save()

            message.topic = topic
            message.sender = request.user
            message.save()

            return HttpResponseRedirect(topic.get_absolute_url())
    else:
        initial = {}
        if request.GET.has_key('recipient'):
            initial['recipient'] = request.GET['recipient']

        form = NewTopicForm(initial=initial)

    return TemplateResponse(request, template_name, {
        'pm_form': form,
    })
开发者ID:plazix,项目名称:django-private-messages,代码行数:29,代码来源:views.py

示例2: new_topic

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_absolute_url [as 别名]
def new_topic(request, forum_slug):
    forum = get_object_or_404(Forum, slug=forum_slug)
    if request.method == 'GET':
        topic_form = TopicForm()
    elif request.method == 'POST':
        topic_form = TopicForm(request.POST)
        if topic_form.is_valid():
            data = topic_form.cleaned_data
            new_topic = Topic(forum=forum, title=data['title'], user=request.user)
            new_topic.save()
            new_post = Post(topic=new_topic, body=data['body'], user=request.user, ip_address=request.META.get('REMOTE_ADDR'))
            new_post.save()
            return HttpResponseRedirect(new_topic.get_absolute_url())
    return render_to_response('forum/topic_new.html', {'forum':forum, 'form':topic_form}, RequestContext(request))
开发者ID:fdb,项目名称:projecthub,代码行数:16,代码来源:views.py

示例3: new

# 需要导入模块: from models import Topic [as 别名]
# 或者: from models.Topic import get_absolute_url [as 别名]
def new(request):
    """Creates a new topic in a forum."""

    try:
        forum_pk = request.GET["forum"]
    except KeyError:
        raise Http404
    forum = get_object_or_404(Forum, pk=forum_pk)
    if not forum.can_read(request.user):
        raise PermissionDenied
    if request.method == "POST":

        # If the client is using the "preview" button

        if "preview" in request.POST:
            form = TopicForm(initial={"title": request.POST["title"],
                                      "subtitle": request.POST["subtitle"],
                                      "text": request.POST["text"]})
            return render_template("forum/topic/new.html",
                                   {"forum": forum,
                                    "form": form,
                                    "text": request.POST["text"]})
        form = TopicForm(request.POST)
        data = form.data
        if form.is_valid():

            # Treat title

            (tags, title) = get_tag_by_title(data["title"])

            # Creating the thread
            n_topic = Topic()
            n_topic.forum = forum
            n_topic.title = title
            n_topic.subtitle = data["subtitle"]
            n_topic.pubdate = datetime.now()
            n_topic.author = request.user
            n_topic.save()
            # add tags

            n_topic.add_tags(tags)
            n_topic.save()
            # Adding the first message

            post = Post()
            post.topic = n_topic
            post.author = request.user
            post.text = data["text"]
            post.text_html = emarkdown(request.POST["text"])
            post.pubdate = datetime.now()
            post.position = 1
            post.ip_address = get_client_ip(request)
            post.save()
            n_topic.last_message = post
            n_topic.save()

            # Follow the topic

            follow(n_topic)
            return redirect(n_topic.get_absolute_url())
    else:
        form = TopicForm()

    return render_template("forum/topic/new.html", {"forum": forum, "form": form})
开发者ID:Aer-o,项目名称:zds-site,代码行数:66,代码来源:views.py


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