本文整理汇总了Python中django.contrib.messages.warning方法的典型用法代码示例。如果您正苦于以下问题:Python messages.warning方法的具体用法?Python messages.warning怎么用?Python messages.warning使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.messages
的用法示例。
在下文中一共展示了messages.warning方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: calculate_all
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def calculate_all(request, course_slug, activity_slug):
course = get_object_or_404(CourseOffering, slug=course_slug)
activity = get_object_or_404(CalNumericActivity, slug=activity_slug, offering=course, deleted=False)
try:
ignored, hiding_info = calculate_numeric_grade(course,activity)
if hiding_info:
messages.warning(request, "This activity is released to students, but the calculation uses unreleased grades. Calculations done with unreleased activities as zero to prevent leaking hidden info to students.")
if ignored==1:
messages.warning(request, "Did not calculate grade for 1 manually-graded student.")
elif ignored>1:
messages.warning(request, "Did not calculate grade for %i manually-graded students." % (ignored))
except ValidationError as e:
messages.error(request, e.args[0])
except EvalException as e:
messages.error(request, e.args[0])
except NotImplementedError:
return NotFoundResponse(request)
return HttpResponseRedirect(activity.get_absolute_url())
示例2: calculate_all_lettergrades
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def calculate_all_lettergrades(request, course_slug, activity_slug):
course = get_object_or_404(CourseOffering, slug=course_slug)
activity = get_object_or_404(CalLetterActivity, slug=activity_slug, offering=course, deleted=False)
try:
ignored = calculate_letter_grade(course,activity)
if ignored==1:
messages.warning(request, "Did not calculate letter grade for 1 manually-graded student.")
elif ignored>1:
messages.warning(request, "Did not calculate letter grade for %i manually-graded students." % (ignored))
except ValidationError as e:
messages.error(request, e.args[0])
except NotImplementedError:
return NotFoundResponse(request)
return HttpResponseRedirect(activity.get_absolute_url())
示例3: get_response
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def get_response(self, response, context, *args, **kwargs):
has_view_perm = self.has_model_perm(self.model, 'view')
if not has_view_perm:
raise PermissionDenied
export_format = self.request.GET.get('file_format')
if not export_format:
messages.warning(self.request, _('You must select an export format.'))
else:
formats = self.get_export_formats()
file_format = formats[int(export_format)]()
queryset = self.get_export_queryset(self.request, context)
export_data = self.get_export_data(file_format, queryset, request=self.request)
content_type = file_format.get_content_type()
# Django 1.7 uses the content_type kwarg instead of mimetype
try:
response = HttpResponse(export_data, content_type=content_type)
except TypeError:
response = HttpResponse(export_data, mimetype=content_type)
response['Content-Disposition'] = 'attachment; filename=%s' % (
self.get_export_filename(file_format),
)
post_export.send(sender=None, model=self.model)
return response
示例4: scan_scan_list
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def scan_scan_list(request: HttpRequest, scan_list_id: int) -> HttpResponse:
"""Schedule the scan of a scan list."""
scan_list = get_object_or_404(
ScanList.objects.prefetch_related(Prefetch(
'sites',
queryset=Site.objects.select_related('last_scan') \
.annotate_most_recent_scan_start() \
.annotate_most_recent_scan_end_or_null())
), pk=scan_list_id)
was_any_site_scannable = scan_list.scan()
if was_any_site_scannable:
num_scanning_sites = Scan.objects.filter(end__isnull=True).count()
messages.success(request,
_("Scans for this list have been scheduled. "+ \
"The total number of sites in the scanning queue "+ \
"is %i (including yours)." % num_scanning_sites))
else:
messages.warning(request,
_('All sites have been scanned recently. Please wait 30 minutes and try again.'))
return redirect(reverse('frontend:view_scan_list', args=(scan_list_id,)))
示例5: post
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def post(self, request, pk=id):
obj = get_object_or_404(Project, pk=pk, is_active=True)
form = UploadFileForm(request.POST, request.FILES)
if form.is_valid():
try:
sitefile = request.FILES['file']
sites = sitefile.get_records()
user = request.user
task_obj = CeleryTaskProgress.objects.create(user=user, content_object = obj, task_type=0)
if task_obj:
# import ipdb
# ipdb.set_trace()
task = bulkuploadsites.delay(task_obj.pk, user, sites, pk)
task_obj.task_id = task.id
task_obj.save()
messages.success(request, 'Sites are being uploaded. You will be notified in notifications list as well.')
else:
messages.success(request, 'Sites cannot be updated a the moment.')
return HttpResponseRedirect(reverse('fieldsight:proj-site-list', kwargs={'pk': pk}))
except Exception as e:
form.full_clean()
form._errors[NON_FIELD_ERRORS] = form.error_class(['Sites Upload Failed, UnSupported Data', e])
messages.warning(request, 'Site Upload Failed, UnSupported Data ')
return render(request, 'fieldsight/upload_sites.html', {'obj': obj, 'form': form, 'project': pk})
示例6: scan
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def scan(self):
self.now = datetime.utcnow()
try:
self.init_browser()
self.scan_webdriver()
except Exception as e:
self.scan_requests()
messages.warning(
self.request,
_("WebDriver scan failed. Falling back to GET request method."),
)
messages.error(self.request, e)
messages.success(
self.request,
_(
"Created %d declaration(s) and updated %d declaration(s)."
% (self.created, self.updated)
),
)
示例7: delete
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def delete(request, slug):
page = get_object_or_404(Page, slug=slug)
data = request.POST if request.method == 'POST' else None
form = DeleteForm(data)
if form.is_valid():
if form.cleaned_data['what'] == 'this':
msg = _("The page %(slug)s was deleted") % {'slug': slug}
page.delete()
else:
Page.objects.filter(slug__startswith=slug).delete()
msg = _("The page %(slug)s and all its namespace was deleted") % {
'slug': slug}
messages.warning(request, msg)
if request.is_ajax():
return HttpResponse(json.dumps({'redirect': reverse('waliki_home')}), content_type="application/json")
return redirect('waliki_home')
if request.is_ajax():
data = render_to_string('waliki/delete.html', {'page': page, 'form': form},
request=request)
return HttpResponse(json.dumps({'data': data}), content_type="application/json")
return render(request, 'waliki/delete.html', {'page': page, 'form': form})
示例8: post
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def post(self, request):
"""
Handles the POST requests to this view. Creates a StringIO object and passes it to ``import_targets``.
:param request: the request object passed to this view
:type request: HTTPRequest
"""
csv_file = request.FILES['target_csv']
csv_stream = StringIO(csv_file.read().decode('utf-8'), newline=None)
result = import_targets(csv_stream)
messages.success(
request,
'Targets created: {}'.format(len(result['targets']))
)
for error in result['errors']:
messages.warning(request, error)
return redirect(reverse('tom_targets:list'))
示例9: validate_importers
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def validate_importers(_, request, importers):
when = datetime.now() - timedelta(days=30)
for importer in importers:
data = importer.updated_since(when)
try:
importer.validate(data)
except jsonschema.exceptions.ValidationError as err:
schema_path = "/".join(map(str, err.absolute_schema_path))
messages.warning(
request,
f"Validation error for {importer} "
f"at {schema_path}: {err.message}")
messages.warning(
request,
str(reduce(lambda d, k: d[k], err.absolute_path, data)),
)
else:
messages.info(request, f"{importer} successfully validated!")
示例10: test_func
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def test_func(self):
# settting the login_url determines redirect if test returns false
if self.request.user.accepted_terms():
self.login_url = self.reverse_lazy_with_param('identity')
else:
self.login_url = self.reverse_lazy_with_param('terms')
return False
user_account = self.request.user.account()
try:
identity_verified = user_account.identity_verified()
except stripe.error.StripeError as e:
if "that account does not exist" in e.message:
messages.warning(self.request, 'stripe_account_error')
return None
return identity_verified
示例11: static
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def static(request):
User = get_user_model()
username_field = User.USERNAME_FIELD
log = None
username = request.GET.get('username')
if username:
try:
User.objects.get(**{username_field: username})
except User.DoesNotExist:
messages.error(request, _("User {} not found.").format(username))
else:
log = get_log(username)
if log:
messages.info(request, _("Logs found for {}.").format(username)) # noqa
else:
messages.warning(request, _("No logs for {}.").format(username)) # noqa
return render(request, 'userlog/static.html', {
'title': _("Static log"),
'log': log,
'fieldname': User._meta.get_field(username_field).verbose_name,
})
示例12: project_details
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def project_details(request, project_id):
proj = Project.objects.filter(
users_assigned=request.user.id,
pk=project_id)
if not proj:
messages.warning(
request,
'You are not authorized to view this project')
return redirect('/taskManager/dashboard')
else:
proj = Project.objects.get(pk=project_id)
user_can_edit = request.user.has_perm('project_edit')
return render(request, 'taskManager/project_details.html',
{'proj': proj, 'user_can_edit': user_can_edit})
# A4: Insecure Direct Object Reference (IDOR)
示例13: change_password
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def change_password(request):
if request.method == 'POST':
user = request.user
old_password = request.POST.get('old_password')
new_password = request.POST.get('new_password')
confirm_password = request.POST.get('confirm_password')
if authenticate(username=user.username, password=old_password):
if new_password == confirm_password:
user.set_password(new_password)
user.save()
messages.success(request, 'Password Updated')
else:
messages.warning(request, 'Passwords do not match')
else:
messages.warning(request, 'Invalid Password')
return render(request,
'taskManager/change_password.html',
{'user': request.user})
示例14: get
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def get(self, request, *args, **kwargs):
if request.user.is_authenticated:
self.object = self.get_object()
if self.object.state.initial and self.object.created_by != request.user:
return redirect('home')
if self.object.state.final:
messages.warning(request, 'Published content are not editable.')
return redirect('article_view',pk=self.object.pk)
community = self.get_community()
if self.is_communitymember(request, community):
role = self.get_communityrole(request, community)
if canEditResourceCommunity(self.object.state.name, role.name, self.object, request):
response=super(ArticleEditView, self).get(request, *args, **kwargs)
if settings.REALTIME_EDITOR:
sessionid = create_session_community(request, community.id)
response.set_cookie('sessionID', sessionid)
return response
return redirect('article_view',pk=self.object.pk)
return redirect('commnity_view',pk=community.pk)
return redirect('login')
示例15: get
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import warning [as 别名]
def get(self, request, *args, **kwargs):
if request.user.is_authenticated:
self.object = self.get_object()
if self.object.state.initial and self.object.created_by != request.user:
return redirect('home')
if self.object.state.final:
messages.warning(request, 'Published content are not editable.')
return redirect('media_view',pk=self.object.pk)
community = self.get_community()
if self.is_communitymember(request, community):
role = self.get_communityrole(request, community)
if canEditResourceCommunity(self.object.state.name, role.name, self.object, request):
response=super(MediaUpdateView, self).get(request, *args, **kwargs)
return response
return redirect('media_view',pk=self.object.pk)
return redirect('community_view',pk=community.pk)
return redirect('login')