本文整理汇总了Python中misago.apps.errors.error404函数的典型用法代码示例。如果您正苦于以下问题:Python error404函数的具体用法?Python error404怎么用?Python error404使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。
在下文中一共展示了error404函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Python代码示例。
示例1: __call__
def __call__(self, request, **kwargs):
self.request = request
self.kwargs = kwargs
self.parents = []
self.ignored = False
self.watcher = False
self.message = request.messages.get_message("threads")
try:
self._type_available()
self.fetch_thread()
self.check_forum_type()
self._check_permissions()
response = self.fetch_posts()
if response:
return response
self.make_thread_form()
if self.thread_form:
response = self.handle_thread_form()
if response:
return response
self.make_posts_form()
if self.posts_form:
response = self.handle_posts_form()
if response:
return response
except (Forum.DoesNotExist, Thread.DoesNotExist):
return error404(request)
except ACLError403 as e:
return error403(request, unicode(e))
except ACLError404 as e:
return error404(request, unicode(e))
# Merge proxy into forum
self.forum.closed = self.proxy.closed
return render_to_response(
"%ss/thread.html" % self.type_prefix,
self._template_vars(
{
"message": self.message,
"forum": self.forum,
"parents": self.parents,
"thread": self.thread,
"is_read": self.tracker.is_read(self.thread),
"count": self.count,
"posts": self.posts,
"ignored_posts": self.ignored,
"watcher": self.watcher,
"pagination": self.pagination,
"emojis": emojis(),
"quick_reply": QuickReplyForm(request=request),
"thread_form": self.thread_form or None,
"posts_form": self.posts_form or None,
}
),
context_instance=RequestContext(request),
)
开发者ID:tanglu-org,项目名称:tgl-misago,代码行数:57,代码来源:views.py
示例2: view
def view(request):
if not self.post.reported:
return error404(request)
reports = Forum.objects.special_model("reports")
self.request.acl.forums.allow_forum_view(reports)
report = self.post.live_report()
if not report:
return error404(request)
return redirect(reverse("report", kwargs={"thread": report.pk, "slug": report.slug}))
开发者ID:nintendos,项目名称:Misago,代码行数:9,代码来源:jumps.py
示例3: __call__
def __call__(self, request, **kwargs):
self.request = request
self.kwargs = kwargs
self.parents = []
self.ignored = False
self.watcher = False
self.message = request.messages.get_message('threads')
try:
self._type_available()
self.fetch_thread()
self.check_forum_type()
self._check_permissions()
response = self.fetch_posts()
if response:
return response
self.make_thread_form()
if self.thread_form:
response = self.handle_thread_form()
if response:
return response
self.make_posts_form()
if self.posts_form:
response = self.handle_posts_form()
if response:
return response
except (Forum.DoesNotExist, Thread.DoesNotExist):
return error404(request)
except ACLError403 as e:
return error403(request, unicode(e))
except ACLError404 as e:
return error404(request, unicode(e))
# Merge proxy into forum
self.forum.closed = self.proxy.closed
return request.theme.render_to_response('%ss/thread.html' % self.type_prefix,
self.template_vars({
'type_prefix': self.type_prefix,
'message': self.message,
'forum': self.forum,
'parents': self.parents,
'thread': self.thread,
'is_read': self.tracker.is_read(self.thread),
'count': self.count,
'posts': self.posts,
'ignored_posts': self.ignored,
'watcher': self.watcher,
'pagination': self.pagination,
'emojis': emojis(),
'quick_reply': FormFields(QuickReplyForm(request=request)).fields,
'thread_form': FormFields(self.thread_form).fields if self.thread_form else None,
'posts_form': FormFields(self.posts_form).fields if self.posts_form else None,
}),
context_instance=RequestContext(request));
开发者ID:finid,项目名称:Misago,代码行数:54,代码来源:views.py
示例4: unignore
def unignore(request, user):
if request.user.pk == user.pk:
return error404(request)
if request.user.is_ignoring(user):
request.messages.set_flash(Message(_("You have stopped ignoring %(username)s") % {'username': user.username}))
request.user.ignores.remove(user)
return fallback(request)
开发者ID:Misago,项目名称:Misago,代码行数:7,代码来源:views.py
示例5: destroy_user
def destroy_user(request, user, username):
try:
user = User.objects.get(pk=user)
except User.DoesNotExist:
return error404(request)
if user.pk == request.user.pk:
return error403(request, _("You can't destroy your own account."))
try:
request.acl.destroy_users.allow_destroy_user(user)
except ACLError403 as e:
return error403(request, unicode(e))
forums_to_sync = []
for thread in user.thread_set.iterator():
if not thread.forum_id in forums_to_sync:
forums_to_sync.append(thread.forum_id)
thread.delete()
if forums_to_sync:
for forum in Forum.objects.filter(id__in=forums_to_sync).iterator():
forum.sync()
forum.save()
user.post_set.update(deleted=True)
user.delete()
messages.success(request, _('User Account "%(username)s" has been destroyed.') % {'username': user.username})
return redirect('users')
开发者ID:0x1330,项目名称:Misago,代码行数:31,代码来源:destroyuser.py
示例6: reset
def reset(request, username="", user="0", token=""):
user = int(user)
try:
user = User.objects.get(pk=user)
user_ban = Ban.objects.check_ban(username=user.username, email=user.email)
if user_ban:
return error_banned(request, user, user_ban)
if user.activation != User.ACTIVATION_NONE:
return redirect_message(request, messages.INFO, _("%(username)s, your account has to be activated in order for you to be able to request new password.") % {'username': user.username})
if not token or not user.token or user.token != token:
return redirect_message(request, messages.ERROR, _("%(username)s, request confirmation link is invalid. Please request new confirmation link.") % {'username': user.username})
new_password = random_string(6)
user.token = None
user.set_password(new_password)
user.save(force_update=True)
# Logout signed in and kill remember me tokens
Session.objects.filter(user=user).update(user=None)
Token.objects.filter(user=user).delete()
# Set flash and mail new password
user.email_user(
request,
'users/password/new',
_("Your New Password"),
{'password': new_password}
)
return redirect_message(request, messages.SUCCESS, _("%(username)s, your password has been changed with new one that was sent to %(email)s.") % {'username': user.username, 'email': user.email})
except User.DoesNotExist:
return error404(request)
开发者ID:0x1330,项目名称:Misago,代码行数:35,代码来源:views.py
示例7: ignore
def ignore(request, user):
if request.user.pk == user.pk:
return error404(request)
if not request.user.is_ignoring(user):
request.messages.set_flash(Message(_("You are now ignoring %(username)s") % {'username': user.username}), 'success')
request.user.ignores.add(user)
return fallback(request)
开发者ID:Misago,项目名称:Misago,代码行数:7,代码来源:views.py
示例8: redirect
def redirect(request, forum, slug):
if not request.acl.forums.can_see(forum):
return error404(request)
try:
forum = Forum.objects.get(pk=forum, type='redirect')
if not request.acl.forums.can_browse(forum):
return error403(request, _("You don't have permission to follow this redirect."))
redirects_tracker = request.session.get('redirects', [])
if forum.pk not in redirects_tracker:
redirects_tracker.append(forum.pk)
request.session['redirects'] = redirects_tracker
forum.redirects += 1
forum.save(force_update=True)
return django_redirect(forum.redirect)
except Forum.DoesNotExist:
return error404(request)
开发者ID:0x1330,项目名称:Misago,代码行数:16,代码来源:redirect.py
示例9: server
def server(request, attachment, thumb=False):
try:
attachment = Attachment.objects.select_related('forum', 'thread', 'post', 'user').get(hash_id=attachment)
if attachment.forum:
request.acl.forums.allow_forum_view(attachment.forum)
if attachment.thread:
request.acl.threads.allow_thread_view(request.user, attachment.thread)
if attachment.forum.special == 'private_threads':
if not request.user.is_authenticated():
raise ACLError404()
can_see_thread_because_reported = (
request.acl.private_threads.is_mod() and attachment.thread.replies_reported)
can_see_thread_because_participates = request.user in attachment.thread.participants.all()
if not (can_see_thread_because_reported or can_see_thread_because_participates):
raise ACLError404()
if attachment.post:
request.acl.threads.allow_post_view(request.user, attachment.thread, attachment.post)
request.acl.threads.allow_attachment_download(request.user, attachment.forum, attachment.post)
return serve_file(attachment, thumb)
except ACLError403:
if attachment.is_image:
return serve_403_image()
return error403(request, _("You don't have permission to download this file."))
except (Attachment.DoesNotExist, ACLError404):
if thumb:
return serve_404_image()
return error404(request, _("Requested file could not be found."))
开发者ID:0x1330,项目名称:Misago,代码行数:27,代码来源:attachments.py
示例10: activate
def activate(request, username="", user="0", token=""):
user = int(user)
try:
user = User.objects.get(pk=user)
current_activation = user.activation
# Run checks
user_ban = Ban.objects.check_ban(username=user.username, email=user.email)
if user_ban:
return error_banned(request, user, user_ban)
if user.activation == User.ACTIVATION_NONE:
return redirect_message(request, messages.INFO, _("%(username)s, your account is already active.") % {'username': user.username})
if user.activation == User.ACTIVATION_ADMIN:
return redirect_message(request, messages.INFO, _("%(username)s, only board administrator can activate your account.") % {'username': user.username})
if not token or not user.token or user.token != token:
return redirect_message(request, messages.ERROR, _("%(username)s, your activation link is invalid. Try again or request new activation e-mail.") % {'username': user.username})
# Activate and sign in our member
user.activation = User.ACTIVATION_NONE
sign_user_in(request, user)
# Update monitor
User.objects.resync_monitor()
if current_activation == User.ACTIVATION_CREDENTIALS:
return redirect_message(request, messages.SUCCESS, _("%(username)s, your account has been successfully reactivated after change of sign-in credentials.") % {'username': user.username})
else:
return redirect_message(request, messages.SUCCESS, _("%(username)s, your account has been successfully activated. Welcome aboard!") % {'username': user.username})
except User.DoesNotExist:
return error404(request)
开发者ID:0x1330,项目名称:Misago,代码行数:34,代码来源:views.py
示例11: call
def call(self, **kwargs):
result = self.request.session.get('search_results')
if not result:
return error404(self.request, _("No search results were found."))
items = result['search_results']
items_total = len(items);
try:
pagination = make_pagination(kwargs.get('page', 0), items_total, 12)
except Http404:
return redirect(reverse('search_results'))
return render_to_response('search/results.html',
{
'search_in': result.get('search_in'),
'search_route': result.get('search_route'),
'search_query': result['search_query'],
'search_author': result.get('search_author'),
'search_thread_titles': result.get('search_thread_titles'),
'search_thread': result.get('search_thread'),
'results': Post.objects.filter(id__in=items).select_related('forum', 'thread', 'user').order_by('-pk')[pagination['start']:pagination['stop']],
'items_total': items_total,
'pagination': pagination,
},
context_instance=RequestContext(self.request))
开发者ID:dopestz,项目名称:Misago-1,代码行数:25,代码来源:views.py
示例12: decorator
def decorator(*args, **kwargs):
try:
return f(*args, **kwargs)
except ACLError403 as e:
return error403(args[0], e)
except ACLError404 as e:
return error404(args[0], e)
开发者ID:0x1330,项目名称:Misago,代码行数:7,代码来源:decorators.py
示例13: activate
def activate(request, token):
new_credentials = request.session.get("new_credentials")
if not new_credentials or new_credentials["token"] != token:
return error404(request)
if new_credentials["new_email"]:
request.user.set_email(new_credentials["new_email"])
if new_credentials["new_password"]:
request.user.set_password(new_credentials["new_password"])
try:
request.user.full_clean()
request.user.save(force_update=True)
request.user.sessions.exclude(id=request.session.id).delete()
request.user.signin_tokens.all().delete()
messages.success(
request,
_("%(username)s, your Sign-In credentials have been changed.") % {"username": request.user.username},
"security",
)
request.session.sign_out(request)
del request.session["new_credentials"]
return redirect(reverse("sign_in"))
except ValidationError:
messages.error(
request, _("Your new credentials have been invalidated. Please try again."), "usercp_credentials"
)
return redirect(reverse("usercp_credentials"))
开发者ID:hopecream,项目名称:Misago,代码行数:28,代码来源:views.py
示例14: make_jump
def make_jump(self):
if not self.request.acl.threads.can_mod_posts(self.forum):
raise ACLError404()
try:
return self.redirect_to_post(self.thread.post_set.get(reported=True))
except Post.DoesNotExist:
return error404(self.request)
开发者ID:nintendos,项目名称:Misago,代码行数:7,代码来源:jumps.py
示例15: crop
def crop(request, upload=False):
if upload and (not request.user.avatar_temp or not 'upload' in settings.avatars_types):
return error404(request)
if not upload and request.user.avatar_type != 'upload':
messages.error(request, _("Crop Avatar option is avaiable only when you use uploaded image as your avatar."), 'usercp_avatar')
return redirect(reverse('usercp_avatar'))
message = request.messages.get_message('usercp_avatar')
if request.method == 'POST':
if request.csrf.request_secure(request):
try:
image_path = settings.MEDIA_ROOT + 'avatars/'
if upload:
source = Image.open(image_path + request.user.avatar_temp)
else:
source = Image.open(image_path + request.user.avatar_original)
width, height = source.size
aspect = float(width) / float(request.POST['crop_b'])
crop_x = int(aspect * float(request.POST['crop_x']))
crop_y = int(aspect * float(request.POST['crop_y']))
crop_w = int(aspect * float(request.POST['crop_w']))
crop = source.crop((crop_x, crop_y, crop_x + crop_w, crop_y + crop_w))
if upload:
image_name, image_extension = path(request.user.avatar_temp).splitext()
else:
image_name, image_extension = path(request.user.avatar_original).splitext()
image_name = '%s_%s%s' % (request.user.pk, random_string(8), image_extension)
resizeimage(crop, settings.AVATAR_SIZES[0], image_path + image_name, info=source.info, format=source.format)
for size in settings.AVATAR_SIZES[1:]:
resizeimage(crop, size, image_path + str(size) + '_' + image_name, info=source.info, format=source.format)
request.user.delete_avatar_image()
if upload:
request.user.delete_avatar_original()
request.user.avatar_type = 'upload'
request.user.avatar_original = '%s_org_%s%s' % (request.user.pk, random_string(8), image_extension)
source.save(image_path + request.user.avatar_original)
request.user.delete_avatar_temp()
request.user.avatar_image = image_name
request.user.avatar_crop = [str(float(request.POST[x])) for x in ('crop_x', 'crop_y', 'crop_w')]
request.user.save(force_update=True)
messages.success(request, _("Your avatar has been cropped."), 'usercp_avatar')
return redirect(reverse('usercp_avatar'))
except Exception:
message = Message(_("Form contains errors."), messages.ERROR)
else:
message = Message(_("Request authorisation is invalid."), messages.ERROR)
return render_to_response('usercp/avatar_crop.html',
context_instance=RequestContext(request, {
'message': message,
'after_upload': upload,
'avatar_size': settings.AVATAR_SIZES[0],
'avatar_crop': request.user.avatar_crop if not upload else None,
'source': 'avatars/%s' % (request.user.avatar_temp if upload else request.user.avatar_original),
'tab': 'avatar'}));
开发者ID:0x1330,项目名称:Misago,代码行数:60,代码来源:views.py
示例16: settings
def settings(request, group_id=None, group_slug=None):
# Load groups and find selected group
settings_groups = SettingsGroup.objects.all().order_by('key')
if not group_id:
active_group = settings_groups[0]
group_id = active_group.pk
else:
group_id = int(group_id)
for group in settings_groups:
if group.pk == group_id:
active_group = group
break
else:
return error404(request, _('Requested settings group could not be found.'))
# Load selected group settings and turn them into form
group_settings = Setting.objects.filter(group=active_group).order_by('position')
last_fieldset = (None, [])
group_form = {'fieldsets': []}
for setting in group_settings:
# New field subgroup?
if setting.separator and last_fieldset[0] != setting.separator:
if last_fieldset[0]:
group_form['fieldsets'].append(last_fieldset)
last_fieldset = (_(setting.separator), [])
last_fieldset[1].append(setting.pk)
group_form[setting.pk] = setting.get_field()
group_form['fieldsets'].append(last_fieldset)
SettingsGroupForm = type('SettingsGroupForm', (Form,), group_form)
#Submit form
message = messages.get_message(request, 'admin_settings')
if request.method == 'POST':
form = SettingsGroupForm(request.POST, request=request)
if form.is_valid():
for setting in form.cleaned_data.keys():
misago_settings[setting] = form.cleaned_data[setting]
cache.delete('settings')
messages.success(request, _('Configuration has been changed.'), 'admin_settings')
return redirect(reverse('admin_settings', kwargs={
'group_id': active_group.pk,
'group_slug': active_group.key,
}))
else:
message = Message(form.non_field_errors()[0], messages.ERROR)
else:
form = SettingsGroupForm(request=request)
# Display settings group form
return render_to_response('settings/settings.html',
{
'message': message,
'groups': settings_groups,
'active_group': active_group,
'search_form': SearchForm(request=request),
'form': FormIterator(form),
'raw_form': form,
},
context_instance=RequestContext(request));
开发者ID:0x1330,项目名称:Misago,代码行数:59,代码来源:views.py
示例17: inner_decorator
def inner_decorator(request, user, *args, **kwargs):
request = request
user_pk = int(user)
try:
user = User.objects.get(pk=user_pk)
return f(request, user, *args, **kwargs)
except User.DoesNotExist:
return error404(request)
开发者ID:0x1330,项目名称:Misago,代码行数:8,代码来源:decorators.py
示例18: make_jump
def make_jump(self):
if not self.request.acl.threads.can_approve(self.forum):
raise ACLError404()
try:
return self.redirect_to_post(
self.thread.post_set.filter(moderated=True)[:1][0])
except IndexError:
return error404(self.request)
开发者ID:0x1330,项目名称:Misago,代码行数:8,代码来源:jumps.py
示例19: category
def category(request, forum, slug):
if not request.acl.forums.can_see(forum):
return error404(request)
try:
forum = Forum.objects.get(pk=forum, type='category')
if not request.acl.forums.can_browse(forum):
return error403(request, _("You don't have permission to browse this category."))
except Forum.DoesNotExist:
return error404(request)
forum.subforums = Forum.objects.treelist(request.acl.forums, forum, tracker=ForumsTracker(request.user))
return render_to_response('category.html',
{
'category': forum,
'parents': Forum.objects.forum_parents(forum.pk),
},
context_instance=RequestContext(request));
开发者ID:0x1330,项目名称:Misago,代码行数:17,代码来源:category.py
示例20: __call__
def __call__(self, request, **kwargs):
self.request = request
self.kwargs = kwargs
self.parents = []
try:
self._type_available()
self._set_context()
self._check_permissions()
self.delete()
self.message()
return self.response()
except (Forum.DoesNotExist, Thread.DoesNotExist, Post.DoesNotExist, Checkpoint.DoesNotExist):
return error404(request)
except ACLError403 as e:
return error403(request, unicode(e))
except ACLError404 as e:
return error404(request, unicode(e))
开发者ID:dopestz,项目名称:Misago-1,代码行数:17,代码来源:delete.py
注:本文中的misago.apps.errors.error404函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论