本文整理汇总了Python中django.contrib.messages.info方法的典型用法代码示例。如果您正苦于以下问题:Python messages.info方法的具体用法?Python messages.info怎么用?Python messages.info使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.messages
的用法示例。
在下文中一共展示了messages.info方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: remove_product
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def remove_product(request, pk, item_id):
order = get_object_or_404(Order, pk=pk)
# The following is to help those who hit Back after removing a product
try:
item = ServiceOrderItem.objects.get(pk=item_id)
except ServiceOrderItem.DoesNotExist:
messages.error(request, _("Order item does not exist"))
return redirect(order)
if request.method == 'POST':
msg = order.remove_product(item, request.user)
messages.info(request, msg)
return redirect(order)
return render(request, 'orders/remove_product.html', locals())
示例2: edit_faculty_member_info
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def edit_faculty_member_info(request, userid):
person, _ = _get_faculty_or_404(request.units, userid)
info = (FacultyMemberInfo.objects.filter(person=person).first()
or FacultyMemberInfo(person=person))
if request.POST:
form = FacultyMemberInfoForm(request.POST, instance=info)
if form.is_valid():
new_info = form.save()
person.set_title(new_info.title)
person.save()
messages.success(request, 'Contact information was saved successfully.')
return HttpResponseRedirect(new_info.get_absolute_url())
else:
form = FacultyMemberInfoForm(instance=info)
context = {
'person': person,
'form': form,
}
return render(request, 'faculty/edit_faculty_member_info.html', context)
示例3: get_context_data
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def get_context_data(self, **kwargs):
context = super(BaseRequiredMixin, self).get_context_data(**kwargs)
self.meta = {}
try:
self.meta['logo'] = self.request.user.onidc.name
self.meta['icon'] = self.opts.icon
self.meta['model_name'] = self.model_name
self.meta['verbose_name'] = self.verbose_name
self.meta['title'] = "{} {}".format(self.verbose_name, self.title)
except BaseException:
self.meta['title'] = self.title
context['meta'] = self.meta
context['menus'] = system_menus
# construct_menus()
# from django import db
# logger.info('queries count: {}'.format(len(db.connection.queries)))
return context
示例4: form_valid
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def form_valid(self, form):
data = form.cleaned_data
domain = data['domain_base']
domain_is_whitelisted = check_valid_tld(domain)
if not domain_is_whitelisted:
messages.info(
self.request,
"Sorry, but to limit the cost of running this service, we have not enabled searching this domain name (%s)." % domain
)
return HttpResponseRedirect(resolve_url('home'))
search_done = search_bing(domain)
if not search_done:
messages.info(
self.request,
"This domain has already been requested today! Here is what we've gathered."
)
else:
messages.info(
self.request,
"Gathering results now. They will be displayed shortly."
)
return HttpResponseRedirect(
resolve_url('domain_result', domain)
)
示例5: get_context_data
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def get_context_data(self, **kwargs):
context = super(SearchResultView, self).get_context_data(**kwargs)
domain_name = self.kwargs['domain']
context['domain_name'] = domain_name
context['format'] = self.kwargs.get('fmt')
self.kwargs['fmt'] = None # clear the format
# so that we get a list of all of the formats for the domain
qs = set(self.get_queryset().values_list('fmt', flat=True))
context['file_formats'] = list(qs)
domain = Domain.objects.filter(name=domain_name)
search_being_performed = len(DomainSearch.objects.filter(domain=domain, completed_at=None)) > 0
if search_being_performed:
messages.info(
self.request,
"We're gathering more results right now. This page will refresh in 10 seconds."
)
context['refresh_counter'] = 10
return context
示例6: add_sub_stage
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def add_sub_stage(request, pk=None):
stage = get_object_or_404(
Stage, pk=pk)
if request.method == 'POST':
form = AddSubSTageForm(data=request.POST, request=request)
if form.is_valid():
child_stage = form.save(commit=False)
child_stage.stage = stage
child_stage.project = stage.project
child_stage.site = stage.site
child_stage.group = stage.group
child_stage.save()
form = int(form.cleaned_data.get('form',0))
if form:
if stage.site:
FieldSightXF.objects.create(xf_id=form, is_staged=True, stage=child_stage,site=stage.site)
else:
FieldSightXF.objects.create(xf_id=form, is_staged=True, stage=child_stage,project=stage.project)
messages.info(request, 'Sub Stage {} Saved.'.format(child_stage.name))
return HttpResponseRedirect(reverse("forms:stages-detail", kwargs={'pk': stage.id}))
order = Stage.objects.filter(stage=stage).count() + 1
instance = Stage(name="Sub Stage"+str(order), order=order)
form = AddSubSTageForm(instance=instance, request=request)
return render(request, "fsforms/add_sub_stage.html", {'form': form, 'obj': stage})
示例7: project_edit_schedule
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def project_edit_schedule(request, id):
schedule = get_object_or_404(
Schedule, pk=id)
if request.method == 'POST':
form = ScheduleForm(data=request.POST, instance=schedule, request=request)
if form.is_valid():
form.save()
xf = int(form.cleaned_data.get('form', 0))
if xf:
if FieldSightXF.objects.filter(project=schedule.project, schedule=schedule, is_scheduled=True).exists():
fs_xform = FieldSightXF.objects.get(project=schedule.project, schedule=schedule, is_scheduled=True)
if fs_xform.xf.id != xf:
fs_xform.xf_id = xf
fs_xform.save()
else:
FieldSightXF.objects.create(
xf_id=xf, is_scheduled=True,schedule=schedule,project=schedule.project, is_deployed=True)
messages.info(request, 'Schedule {} Saved.'.format(schedule.name))
return HttpResponseRedirect(reverse("forms:project-survey", kwargs={'project_id': schedule.project.id}))
form = ScheduleForm(instance=schedule, request=request)
if FieldSightXF.objects.filter(schedule=schedule).exists():
if FieldSightXF.objects.get(schedule=schedule).xf:
form.fields['form'].initial= FieldSightXF.objects.get(schedule=schedule).xf.id
return render(request, "fsforms/schedule_form.html",
{'form': form, 'obj': schedule.project, 'is_project':True, 'is_general':False, 'is_edit':True})
示例8: deploy_stages
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def deploy_stages(request, id):
project = Project(pk=id)
sites = project.sites.all()
main_stages = project.stages.filter(stage__isnull=True)
with transaction.atomic():
Stage.objects.filter(site__project=project).delete()
FieldSightXF.objects.filter(is_staged=True, site__project=project).delete()
for main_stage in main_stages:
for site in sites:
send_message_stages(site)
site_main_stage = Stage(name=main_stage.name, order=main_stage.order, site=site,
description=main_stage.description)
site_main_stage.save()
project_sub_stages = Stage.objects.filter(stage__id=main_stage.pk)
for project_sub_stage in project_sub_stages:
site_sub_stage = Stage(name=project_sub_stage.name, order=project_sub_stage.order, site=site,
description=project_sub_stage.description, stage=site_main_stage)
site_sub_stage.save()
if FieldSightXF.objects.filter(stage=project_sub_stage).exists():
fsxf = FieldSightXF.objects.filter(stage=project_sub_stage)[0]
FieldSightXF.objects.get_or_create(is_staged=True, xf=fsxf.xf, site=site,
fsform=fsxf, stage=site_sub_stage, is_deployed=True)
messages.info(request, 'Stages Form Deployed to Sites')
return HttpResponseRedirect(reverse("forms:setup-project-stages", kwargs={'id': id}))
示例9: fill_form_type
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def fill_form_type(request, pk=None):
field_sight_form = get_object_or_404(
FieldSightXF, pk=pk)
if request.method == 'POST':
form = FormTypeForm(request.POST)
if form.is_valid():
form_type = form.cleaned_data.get('form_type', '3')
form_type = int(form_type)
messages.info(request, 'Form Type Saved.')
if form_type == 3:
return HttpResponseRedirect(reverse("forms:library-forms-list"))
elif form_type == 2:
field_sight_form.is_scheduled = True
field_sight_form.save()
return HttpResponseRedirect(reverse("forms:fill_details_schedule", kwargs={'pk': field_sight_form.id}))
else:
field_sight_form.is_staged = True
field_sight_form.save()
return HttpResponseRedirect(reverse("forms:fill_details_stage", kwargs={'pk': field_sight_form.id}))
else:
form = FormTypeForm()
return render(request, "fsforms/stage_or_schedule.html", {'form': form, 'obj': field_sight_form})
示例10: get
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def get(self, request, slug):
internet_exchange = get_object_or_404(InternetExchange, slug=slug)
# Check if the PeeringDB ID is valid
if not internet_exchange.is_peeringdb_valid():
# If not, try to fix it automatically
peeringdb_id = internet_exchange.get_peeringdb_id()
if peeringdb_id != 0:
internet_exchange.peeringdb_id = peeringdb_id
internet_exchange.save()
messages.info(
request,
"The PeeringDB record reference for this IX was invalid, it has been fixed.",
)
context = {"internet_exchange": internet_exchange}
return render(request, "peering/ix/details.html", context)
示例11: set_default_view
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def set_default_view(request, release_id):
"""
:param release_id: The release
:param request: Django Request
:return: Redirect Response
"""
release_instance = Release.objects.get(id=release_id)
messages.info(request, mark_safe(_(
"Active release \"<a href=\"%(release_url)s\">%(release)s</a>\" has been set.").format(
release_url=release_instance.get_admin_url(),
release=str(release_instance)
)
))
setting_instance = Setting.objects.get()
setting_instance.active_release = release_instance
setting_instance.save()
return redirect(setting_instance.get_admin_url())
示例12: profile
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def profile(request):
user = get_object_or_404(User, username=request.user)
if request.method == 'POST':
form = UserProfileForm(data=request.POST, instance=user)
if form.is_valid():
form.save(commit=False)
user.save()
messages.info(request, _("Information updated."))
form = UserProfileForm(instance=user)
else:
form = UserProfileForm(instance=user)
return render(request, "userApp/profile.html", {'user': user, 'form': form})
示例13: profile_delete
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def profile_delete(request, profile_id):
# TODO - Add user permissioning
# if not request.user.has_perm('app.edit_fermentation_profile'):
# messages.error(request, 'Your account is not permissioned to edit fermentation profiles. Please contact an admin')
# return redirect("/")
try:
this_profile = FermentationProfile.objects.get(id=profile_id)
except:
# The URL contained an invalid profile ID. Redirect to the profile
# list.
messages.error(request, 'Invalid profile selected for deletion')
return redirect('profile_list')
if not this_profile.is_editable():
# Due to the way we're implementing fermentation profiles, we don't want any edits to a profile that is
# currently in use.
this_profile.status = FermentationProfile.STATUS_PENDING_DELETE
this_profile.save()
messages.info(request,
'Profile \'{}\' is currently in use but has been queued for deletion.'.format(this_profile.name))
else:
this_profile.delete()
messages.success(request, 'Profile \'{}\' was not in use, and has been deleted.'.format(this_profile.name))
return redirect('profile_list')
示例14: profile_undelete
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def profile_undelete(request, profile_id):
# TODO - Add user permissioning
# if not request.user.has_perm('app.edit_fermentation_profile'):
# messages.error(request, 'Your account is not permissioned to edit fermentation profiles. Please contact an admin')
# return redirect("/")
try:
this_profile = FermentationProfile.objects.get(id=profile_id)
except:
# The URL contained an invalid profile ID. Redirect to the profile
# list.
messages.error(request, 'Invalid profile selected to save from deletion')
return redirect('profile_list')
if this_profile.status == FermentationProfile.STATUS_PENDING_DELETE:
this_profile.status = FermentationProfile.STATUS_ACTIVE
this_profile.save()
messages.success(request,
'Profile \'{}\' has been removed from the queue for deletion.'.format(this_profile.name))
else:
messages.info(request, 'Profile \'{}\' was not previously queued for deletion and has not been updated.'.format(this_profile.name))
return redirect('profile_list')
示例15: form_valid
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import info [as 别名]
def form_valid(self, form):
"""
Runs after form validation. Creates the ``Target``, and creates any ``TargetName`` or ``TargetExtra`` objects,
then runs the ``target_post_save`` hook and redirects to the success URL.
:param form: Form data for target creation
:type form: subclass of TargetCreateForm
"""
super().form_valid(form)
extra = TargetExtraFormset(self.request.POST)
names = TargetNamesFormset(self.request.POST)
if extra.is_valid() and names.is_valid():
extra.instance = self.object
extra.save()
names.instance = self.object
names.save()
else:
form.add_error(None, extra.errors)
form.add_error(None, extra.non_form_errors())
form.add_error(None, names.errors)
form.add_error(None, names.non_form_errors())
return super().form_invalid(form)
logger.info('Target post save hook: %s created: %s', self.object, True)
run_hook('target_post_save', target=self.object, created=True)
return redirect(self.get_success_url())