本文整理汇总了Python中django.contrib.messages.error方法的典型用法代码示例。如果您正苦于以下问题:Python messages.error方法的具体用法?Python messages.error怎么用?Python messages.error使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类django.contrib.messages
的用法示例。
在下文中一共展示了messages.error方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: delete_product
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def delete_product(request, pk, group):
from django.db.models import ProtectedError
product = get_object_or_404(Product, pk=pk)
if request.method == 'POST':
try:
product.delete()
Inventory.objects.filter(product=product).delete()
messages.success(request, _("Product deleted"))
except ProtectedError:
messages.error(request, _('Cannot delete product'))
return redirect(list_products, group)
action = request.path
return render(request, 'products/remove.html', locals())
示例2: edit_group
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def edit_group(request, group='all'):
if group == 'all':
group = CustomerGroup()
else:
group = CustomerGroup.objects.get(slug=group)
title = group.name
form = GroupForm(instance=group)
if request.method == "POST":
form = GroupForm(request.POST, instance=group)
if form.is_valid():
group = form.save()
messages.success(request, _(u'%s saved') % group.name)
return redirect(index, group.slug)
messages.error(request, form.errors['name'][0])
return redirect(index)
return render(request, "customers/edit_group.html", locals())
示例3: delete_calendar
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def delete_calendar(request, pk):
calendar = get_object_or_404(Calendar, pk=pk)
if calendar.user != request.user:
messages.error(request, _("Users can only delete their own calendars!"))
return redirect(calendars)
if request.method == "POST":
calendar.delete()
messages.success(request, _('Calendar deleted'))
return redirect(calendars)
data = {'title': _("Really delete this calendar?")}
data['action'] = request.path
return render(request, "accounts/delete_calendar.html", data)
示例4: edit_calendar
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def edit_calendar(request, pk=None, view="week"):
from servo.models.calendar import CalendarForm
calendar = Calendar(user=request.user)
if pk:
calendar = get_object_or_404(Calendar, pk=pk)
if not calendar.user == request.user:
messages.error(request, _('You can only edit your own calendar'))
return redirect(calendars)
if request.method == "POST":
form = CalendarForm(request.POST, instance=calendar)
if form.is_valid():
calendar = form.save()
messages.success(request, _("Calendar saved"))
return redirect(view_calendar, calendar.pk, 'week')
form = CalendarForm(instance=calendar)
data = {'title': calendar.title}
data['form'] = form
data['action'] = request.path
return render(request, "accounts/calendar_form.html", data)
示例5: find_device
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def find_device(request):
device = Device(sn=request.GET['sn'])
device.description = _('Other Device')
device_form = forms.DeviceForm(instance=device)
try:
apple_sn_validator(device.sn)
except Exception as e: # not an Apple serial number
return render(request, "checkin/device_form.html", locals())
try:
device = get_device(request, device.sn)
device_form = forms.DeviceForm(instance=device)
except GsxError as e:
error = e
return render(request, "checkin/device_form.html", locals())
示例6: status
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def status(request):
"""Check service order status through the checkin."""
title = _('Repair Status')
if request.GET.get('code'):
timeline = []
form = forms.StatusCheckForm(request.GET)
if form.is_valid():
code = form.cleaned_data['code']
try:
order = Order.objects.get(code=code)
status_description = order.get_status_description()
if Configuration.conf('checkin_timeline'):
timeline = order.orderstatus_set.all()
if order.status is None:
order.status_name = _(u'Waiting to be processed')
except Order.DoesNotExist:
messages.error(request, _(u'Order %s not found') % code)
return render(request, "checkin/status-show.html", locals())
else:
form = forms.StatusCheckForm()
return render(request, "checkin/status.html", locals())
示例7: delete_device
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def delete_device(request, product_line, model, pk):
dev = get_object_or_404(Device, pk=pk)
if request.method == 'POST':
from django.db.models import ProtectedError
try:
dev.delete()
messages.success(request, _("Device deleted"))
except ProtectedError:
messages.error(request, _("Cannot delete device with GSX repairs"))
return redirect(dev)
return redirect(index)
data = {'action': request.path}
data['device'] = dev
return render(request, "devices/remove.html", data)
示例8: update_gsx_details
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def update_gsx_details(request, pk):
"""
Updates devices GSX warranty details
"""
device = get_object_or_404(Device, pk=pk)
try:
GsxAccount.default(request.user)
device.update_gsx_details()
messages.success(request, _("Warranty status updated successfully"))
except Exception as e:
messages.error(request, e)
if request.session.get('return_to'):
return redirect(request.session['return_to'])
return redirect(device)
示例9: close
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def close(request, pk):
"""Close this Service Order."""
order = get_object_or_404(Order, pk=pk)
if request.method == 'POST':
try:
order.close(request.user)
except Exception as e:
messages.error(request, e)
return redirect(order)
if request.session.get("current_order_id"):
del(request.session['current_order_id'])
del(request.session['current_order_code'])
del(request.session['current_order_customer'])
messages.success(request, _('Order %s closed') % order.code)
return redirect(order)
data = {'order': order, 'action': reverse(close, args=[pk])}
return render(request, "orders/close.html", data)
示例10: remove_user
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def remove_user(request, pk, user_id):
"""
Removes this user from the follower list, unsets assignee
"""
order = get_object_or_404(Order, pk=pk)
user = get_object_or_404(User, pk=user_id)
try:
order.remove_follower(user)
if user == order.user:
order.set_user(None, request.user)
msg = _('User %s removed from followers') % user
order.notify("unset_user", msg, request.user)
except Exception as e:
messages.error(request, e)
return redirect(order)
示例11: device_from_product
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def device_from_product(request, pk, item_id):
"""
Turns a SOI into a device and attaches it to this order
"""
order = get_object_or_404(Order, pk=pk)
soi = ServiceOrderItem.objects.get(pk=item_id)
try:
GsxAccount.default(request.user, order.queue)
device = Device.from_gsx(soi.sn, user=request.user)
device.save()
event = order.add_device(device, request.user)
messages.success(request, event)
except Exception as e:
messages.error(request, e)
return redirect(order)
示例12: remove_product
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [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())
示例13: import_repair
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def import_repair(request, order_pk, device_pk):
from servo.models import Device
order = get_object_or_404(Order, pk=order_pk)
device = get_object_or_404(Device, pk=device_pk)
action = request.path
form = ImportForm()
if request.method == 'POST':
form = ImportForm(request.POST)
if form.is_valid():
confirmation = form.cleaned_data['confirmation']
try:
repair = Repair.create_from_gsx(confirmation,
order,
device,
request.user)
messages.success(request, _('GSX repair %s imported successfully' % confirmation))
return redirect(repair)
except Exception as e:
messages.error(request, e)
return redirect(order)
return render(request, "repairs/import_repair.html", locals())
示例14: add_part
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def add_part(request, repair, part):
"""
Adds this part to this GSX repair
"""
rep = get_object_or_404(Repair, pk=repair)
soi = rep.order.serviceorderitem_set.get(pk=part)
if request.method == "POST":
try:
part = rep.add_part(soi, request.user)
data = {'part': part.part_number, 'repair': rep.confirmation}
msg = _("Part %(part)s added to repair %(repair)s") % data
messages.success(request, msg)
except gsxws.GsxError, e:
messages.error(request, e)
return redirect(rep.order)
示例15: remove_part
# 需要导入模块: from django.contrib import messages [as 别名]
# 或者: from django.contrib.messages import error [as 别名]
def remove_part(request, repair, part):
rep = get_object_or_404(Repair, pk=repair)
part = get_object_or_404(ServicePart, pk=part)
if request.method == "POST":
rep.connect_gsx(request.user)
gsx_rep = rep.get_gsx_repair()
orderline = part.get_repair_order_line()
orderline.toDelete = True
orderline.orderLineNumber = part.line_number
try:
gsx_rep.update({'orderLines': [orderline]})
data = {'part': part.code, 'repair': rep.confirmation}
msg = _(u"Part %(part)s removed from %(repair)s") % data
messages.success(request, msg)
except gsxws.GsxError, e:
messages.error(request, e)
return redirect(rep.order)