本文整理汇总了Python中forum.models.Post.get_absolute_url方法的典型用法代码示例。如果您正苦于以下问题:Python Post.get_absolute_url方法的具体用法?Python Post.get_absolute_url怎么用?Python Post.get_absolute_url使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类forum.models.Post
的用法示例。
在下文中一共展示了Post.get_absolute_url方法的11个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
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,
}))
示例2: _topic_create_POST
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
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()
示例3: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
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})
)
示例4: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
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:
raise HttpResponseServerError
t = get_object_or_404(Thread, pk=thread)
if t.closed:
raise HttpResponseServerError
body = request.POST.get('body', False)
p = Post(
thread=t,
author=request.user,
body=body,
time=datetime.now(),
)
p.save()
return HttpResponseRedirect(p.get_absolute_url())
示例5: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
def reply(request, thread, extra_context=None):
"""
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.
"""
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()
preview = False
p = None
if request.method == "POST":
form = ReplyForm(request.POST)
preview = request.POST.get('preview')
p = Post(
thread=t,
author=request.user,
time=datetime.now(),
)
if form.is_valid():
p.body = form.cleaned_data['body']
if not preview:
p.save()
if not preview:
return HttpResponseRedirect(p.get_absolute_url())
else:
form = ReplyForm()
return render_to_response('forum/reply.html',
RequestContext(request, {
'form': form,
'forum': t.forum,
'post': p,
'preview': preview,
'thread': t,
}))
示例6: post_create
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
def post_create(request, topic_id, slug=None):
topic = get_object_or_404(Topic, id=topic_id, is_closed=False)
is_xhr = bool(request.REQUEST.get('xhr'))
post = Post(topic=topic, author=request.forum_user)
if request.method == 'POST':
form = PostForm(request.POST, instance=post)
if form.is_valid():
post = form.save()
# update counters
topic.post_count = topic.post_set.all().count()
topic.updated = post.created
topic.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()
if is_xhr:
return {
'status': 'ok',
'saved': True,
'url': post.get_absolute_url()
}
return _redirect_next(request, post)
if is_xhr:
return {
'status': 'ok',
'saved': False,
'errors': form.errors(),
}
else:
form = PostForm()
ctx = {'post_form': form, 'topic': topic}
return render(request, 'forum/post/create.html', ctx)
示例7: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
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 HttpResponseServerError()
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()
sub = Subscription.objects.filter(thread=t, author=request.user)
if form.cleaned_data.get('subscribe',False):
if not sub:
s = Subscription(
author=request.user,
thread=t
)
s.save()
else:
if sub:
sub.delete()
# Subscriptions are updated now send mail to all the authors subscribed in
# this thread.
mail_subject = ''
try:
mail_subject = settings.FORUM_MAIL_PREFIX
except AttributeError:
mail_subject = '[Forum]'
mail_from = ''
try:
mail_from = settings.FORUM_MAIL_FROM
except AttributeError:
mail_from = settings.DEFAULT_FROM_EMAIL
mail_tpl = loader.get_template('forum/notify.txt')
c = Context({
'body': wordwrap(striptags(body), 72),
'site' : Site.objects.get_current(),
'thread': t,
})
email = EmailMessage(
subject=mail_subject+' '+striptags(t.title),
body= mail_tpl.render(c),
from_email=mail_from,
to=[mail_from],
bcc=[s.author.email for s in t.subscription_set.all()],)
email.send(fail_silently=True)
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,
}))
示例8: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
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 HttpResponseServerError()
t = get_object_or_404(Thread, pk=thread)
if t.closed:
return HttpResponseServerError()
body = request.POST.get('body', False)
p = Post(
thread=t,
author=request.user,
body=body,
time=datetime.now(),
)
p.save()
sub = Subscription.objects.filter(thread=t, author=request.user)
if request.POST.get('subscribe',False):
if not sub:
s = Subscription(
author=request.user,
thread=t
)
s.save()
else:
if sub:
sub.delete()
# Subscriptions are updated now send mail to all the authors subscribed in
# this thread.
mail_subject = ''
try:
mail_subject = settings.FORUM_MAIL_PREFIX
except AttributeError:
mail_subject = '[Forum]'
mail_from = ''
try:
mail_from = settings.FORUM_MAIL_FROM
except AttributeError:
mail_from = settings.DEFAULT_FROM_EMAIL
mail_tpl = loader.get_template('forum/notify.txt')
c = Context({
'body': wordwrap(striptags(body), 72),
'site' : Site.objects.get_current(),
'thread': t,
})
#email = EmailMessage('Hello', 'Body goes here', '[email protected]',
# ['[email protected]', '[email protected]'], ['[email protected]'],
# headers = {'Reply-To': '[email protected]'})
email = EmailMessage(
subject=mail_subject+' '+striptags(t.title),
body= mail_tpl.render(c),
from_email=mail_from,
to=[mail_from],
bcc=[s.author.email for s in t.subscription_set.all()],)
email.send(fail_silently=True)
return HttpResponseRedirect(p.get_absolute_url())
示例9: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
def reply(request, thread):
"""Post a reply.
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.
@param thread: thread id to reply to
@type thread: integer
@return: a view to post a reply
@rtype: Django response
"""
if not request.user.is_authenticated():
return HttpResponseRedirect("%s?next=%s" % (reverse("user_signin"), 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():
if request.POST.has_key("preview"):
preview = {"body": form.cleaned_data["body"]}
else:
body = form.cleaned_data["body"]
p = Post(thread=t, author=request.user, body=body, time=datetime.now())
p.save()
sub = Subscription.objects.filter(thread=t, author=request.user)
if form.cleaned_data.get("subscribe", False):
if not sub:
s = Subscription(author=request.user, thread=t)
s.save()
else:
if sub:
sub.delete()
if t.subscription_set.count() > 0:
# Subscriptions are updated now send mail to all the authors subscribed in
# this thread.
mail_subject = ""
try:
mail_subject = settings.FORUM_MAIL_PREFIX
except AttributeError:
mail_subject = "[Forum]"
mail_from = ""
try:
mail_from = settings.FORUM_MAIL_FROM
except AttributeError:
mail_from = settings.DEFAULT_FROM_EMAIL
mail_tpl = loader.get_template("forum/notify.txt")
c = RequestContext(
{"body": wordwrap(striptags(body), 72), "site": Site.objects.get_current(), "thread": t}
)
email = EmailMessage(
subject=mail_subject + " " + striptags(t.title),
body=mail_tpl.render(c),
from_email=mail_from,
bcc=[s.author.email for s in t.subscription_set.all()],
)
email.send(fail_silently=True)
return HttpResponseRedirect(p.get_absolute_url())
else:
preview = False
form = ReplyForm()
return render_to_response(
"forum/reply.html",
RequestContext(request, {"form": form, "forum": t.forum, "thread": t, "preview": preview, "section": "forum"}),
)
示例10: edit
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
def edit(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 HttpResponseServerError()
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(data=request.POST, files=request.FILES)
if form.is_valid():
body = form.cleaned_data['body']
p = Post(
thread=t,
author=request.user,
body=body,
time=datetime.now(),
)
p.save()
sub = Subscription.objects.filter(thread=t, author=request.user)
if form.cleaned_data.get('subscribe',False):
if not sub:
s = Subscription(
author=request.user,
thread=t
)
s.save()
else:
if sub:
sub.delete()
# Subscriptions are updated now send mail to all the authors subscribed in
# this thread.
mail_subject = ''
try:
mail_subject = settings.FORUM_MAIL_PREFIX
except AttributeError:
mail_subject = '[Forum]'
mail_from = ''
try:
mail_from = settings.FORUM_MAIL_FROM
except AttributeError:
mail_from = settings.DEFAULT_FROM_EMAIL
mail_tpl = loader.get_template('forum/notify.txt')
c = Context({
'body': wordwrap(striptags(body), 72),
'site' : Site.objects.get_current(),
'thread': t,
})
email = EmailMessage(
subject=mail_subject+' '+striptags(t.title),
body= mail_tpl.render(c),
from_email=mail_from,
to=[mail_from],
bcc=[s.author.email for s in t.subscription_set.all()],)
email.send(fail_silently=True)
for attachedfilefield in form.files:
#file_path = '%s%s' % (settings.MEDIA_ROOT, form.files[attachedfilefield])
attachment_file = form.files[attachedfilefield]
attach=Attachment()
attach.handle_uploaded_attachment(p,
attachment_file,
request.user,
attachment_file.name,
t.title
)
return HttpResponseRedirect(p.get_absolute_url())
else:
post_id = request.GET.get('pid', 0)
if post_id ==0:
return HttpResponseServerError(_("The Post Do Not Exist"))
try:
p = Post.objects.all().get(id=post_id)
except Post.DoesNotExist:
raise Http404(_("Not Found"))
body=p.body
initial = {'subscribe': True,
'body':body}
form = ReplyForm(initial=initial)
return render_to_response('forum/edit.html',
RequestContext(request, {
'form': form,
'post': p
}))
示例11: reply
# 需要导入模块: from forum.models import Post [as 别名]
# 或者: from forum.models.Post import get_absolute_url [as 别名]
#.........这里部分代码省略.........
if form.cleaned_data.get('subscribe',False):
if not sub:
s = Subscription(
author=request.user,
thread=t
)
s.save()
else:
if sub:
sub.delete()
# Subscriptions are updated now send mail to all the authors subscribed in
# this thread.
mail_subject = ''
try:
mail_subject = settings.FORUM_MAIL_PREFIX
except AttributeError:
mail_subject = '[Forum]'
mail_from = ''
try:
mail_from = settings.FORUM_MAIL_FROM
except AttributeError:
mail_from = settings.DEFAULT_FROM_EMAIL
mail_tpl = loader.get_template('forum/notify.txt')
c = Context({
'body': wordwrap(striptags(body), 72),
'site' : Site.objects.get_current(),
'thread': t,
})
email = EmailMessage(
subject=mail_subject+' '+striptags(t.title),
body= mail_tpl.render(c),
from_email=mail_from,
to=[mail_from],
bcc=[s.author.email for s in t.subscription_set.all()],)
email.send(fail_silently=True)
## data={'title': t.title,
## 'summary': t.title,
## 'attached_timestamp':datetime.now()
## }
## attachment_form=AttachmentForm(data=data,files=form.files)
## a=attachment_form.errors
## content_type =ContentType.objects.get_for_model(Post)
## object_id = p.id
## ffs=form.files
## debug()
## if attachment_form.is_valid():
## attachment = attachment_form.save(commit=False)
## attachment.content_type = content_type
## attachment.object_id = object_id
## attachment.attached_by = request.user
## attachment.save()
# for attachedfilefield in form.files:
# #file_path = '%s%s' % (settings.MEDIA_ROOT, form.files[attachedfilefield])
# attachment_file = form.files[attachedfilefield]
# file_path =os.path.join(ATTACHMENT_DIR, randomfilename(attachment_file.name))
# (mimetype, encoding) = mimetypes.guess_type(file_path)
#
# try:
# mime_type = mimetype
# except:
# mime_type = 'text/plain'
#
# attach=Attachment(
# content_type =ContentType.objects.get_for_model(Post),
# object_id = p.id,
# title = attachment_file.name,
# summary = t.title,
# attached_by = request.user,
# )
# attach.save_uploaded_file(attachment_file)
# attach.save()
for attachedfilefield in form.files:
#file_path = '%s%s' % (settings.MEDIA_ROOT, form.files[attachedfilefield])
attachment_file = form.files[attachedfilefield]
attach=Attachment()
attach.handle_uploaded_attachment(p,
attachment_file,
request.user,
attachment_file.name,
t.title
)
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,
}))