Python django.contrib.messages.success() Examples

The following are 30 code examples for showing how to use django.contrib.messages.success(). These examples are extracted from open source projects. You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example.

You may check out the related API usage on the sidebar.

You may also want to check out all available functions/classes of the module django.contrib.messages , or try the search function .

Example 1
Project: Servo   Author: fpsw   File: product.py    License: BSD 2-Clause "Simplified" License 7 votes vote down vote up
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()) 
Example 2
Project: Servo   Author: fpsw   File: product.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def upload_gsx_parts(request, group=None):
    from servo.forms.product import PartsImportForm
    form = PartsImportForm()

    data = {'action': request.path}

    if request.method == "POST":

        form = PartsImportForm(request.POST, request.FILES)

        if form.is_valid():
            data = form.cleaned_data
            filename = "servo/uploads/products/partsdb.csv"
            destination = open(filename, "wb+")

            for chunk in data['partsdb'].chunks():
                destination.write(chunk)

            messages.success(request, _("Parts database uploaded for processing"))
            return redirect(list_products)

    data['form'] = form
    return render(request, "products/upload_gsx_parts.html", data) 
Example 3
Project: Servo   Author: fpsw   File: customer.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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()) 
Example 4
Project: Servo   Author: fpsw   File: account.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example 5
Project: Servo   Author: fpsw   File: account.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def register(request):
    """
    New user applying for access
    """
    form = RegistrationForm()
    data = {'title': _("Register")}

    if request.method == 'POST':

        form = RegistrationForm(request.POST)

        if form.is_valid():
            user = User(is_active=False)
            user.email = form.cleaned_data['email']
            user.last_name = form.cleaned_data['last_name']
            user.first_name = form.cleaned_data['first_name']
            user.set_password(form.cleaned_data['password'])
            user.save()

            messages.success(request, _(u'Your registration is now pending approval.'))

            return redirect(login)

    data['form'] = form
    return render(request, 'accounts/register.html', data) 
Example 6
Project: Servo   Author: fpsw   File: device.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example 7
Project: Servo   Author: fpsw   File: device.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example 8
Project: Servo   Author: fpsw   File: order.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example 9
Project: Servo   Author: fpsw   File: order.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def delete(request, pk):
    
    order = get_object_or_404(Order, pk=pk)

    if request.method == "POST":
        return_to = order.get_queue_url()
        try:
            order.delete()
            del(request.session['current_order_id'])
            del(request.session['current_order_code'])
            del(request.session['current_order_customer'])
            messages.success(request, _(u'Order %s deleted') % order.code)
            return redirect(return_to)
        except Exception as e:
            ed = {'order': order.code, 'error': e}
            msg = _(u'Cannot delete order %(order)s: %(error)s') % ed
            messages.error(request, msg)
            return redirect(order)

    action = request.path
    return render(request, "orders/delete_order.html", locals()) 
Example 10
Project: Servo   Author: fpsw   File: order.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example 11
Project: Servo   Author: fpsw   File: purchases.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def create_po(request, product_id=None, order_id=None):
    """
    Creates a new Purchase Order
    """
    po = PurchaseOrder(created_by=request.user)
    po.location = request.user.get_location()
    po.save()

    if order_id is not None:
        po.sales_order = get_object_or_404(Order, pk=order_id)
        po.save()
        for i in ServiceOrderItem.objects.filter(order_id=order_id):
            po.add_product(i, amount=1, user=request.user)

    if product_id is not None:
        product = get_object_or_404(Product, pk=product_id)
        po.add_product(product, amount=1, user=request.user)

    messages.success(request, _("Purchase Order %d created" % po.pk))

    return redirect(edit_po, po.pk) 
Example 12
Project: Servo   Author: fpsw   File: note.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def delete_note(request, pk):
    """
    Deletes a note
    """
    note = get_object_or_404(Note, pk=pk)

    if request.method == 'POST':
        note.delete()
        messages.success(request, _("Note deleted"))

        if request.session.get('return_to'):
            url = request.session.get('return_to')
            del(request.session['return_to'])
        elif note.order_id:
            url = note.order.get_absolute_url()

        return redirect(url)

    return render(request, 'notes/remove.html', {'note': note}) 
Example 13
Project: Servo   Author: fpsw   File: gsx.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example 14
Project: Servo   Author: fpsw   File: gsx.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example 15
Project: Servo   Author: fpsw   File: gsx.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def delete_repair(request, pk):
    """Delete this unsubmitted GSX repair."""
    repair = get_object_or_404(Repair, pk=pk)

    if repair.is_submitted():
        messages.error(request, _('Submitted repairs cannot be deleted'))
        return redirect(repair.order)

    if request.method == 'POST':
        order = repair.order
        repair.delete()
        messages.success(request, _('GSX repair deleted'))
        return redirect(order)

    context = {'action': request.path}
    return render(request, 'repairs/delete_repair.html', context) 
Example 16
Project: Servo   Author: fpsw   File: shipments.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def add_to_return(request, pk, part=None):
    """
    Adds a part to a bulk return
    """
    data = {'action': request.path}

    if pk and part:
        shipment = get_object_or_404(Shipment, pk=pk)
        part = get_object_or_404(ServicePart, pk=part)
        shipment.servicepart_set.add(part)
        messages.success(request, _(u"Part %s added to return") % part.part_number)

        return redirect(edit_bulk_return)

    if request.method == "POST":
        query = request.POST.get('q')
        results = ServicePart.objects.filter(return_order=query)
        data = {'shipment': pk, 'results': results}

        return render(request, "shipments/add_to_return-results.html", data)

    return render(request, "shipments/add_to_return.html", data) 
Example 17
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def edit_tag(request, type, pk=None):
    if pk is None:
        tag = Tag(type=type)
    else:
        tag = get_object_or_404(Tag, pk=pk)

    TagForm = modelform_factory(Tag, exclude=[])
    form = TagForm(instance=tag)

    if request.method == 'POST':
        form = TagForm(request.POST, instance=tag)

        if form.is_valid():
            tag = form.save()
            messages.success(request, _(u'Tag %s saved') % tag.title)
            return redirect(edit_tag, tag.type, tag.pk)

    types = Tag.TYPES
    title = Tag._meta.verbose_name_plural
    object_list = Tag.objects.filter(type=type)
    return render(request, 'admin/tags/form.html', locals()) 
Example 18
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def edit_status(request, pk=None):
    if pk is None:
        status = Status()
    else:
        status = get_object_or_404(Status, pk=pk)

    header = _(u'Statuses')
    object_list = Status.objects.all()
    form = StatusForm(instance=status)
    title = Status._meta.verbose_name_plural

    if request.method == 'POST':
        form = StatusForm(request.POST, instance=status)
        if form.is_valid():
            status = form.save()
            messages.success(request, _(u'%s saved') % status.title)
            return redirect(edit_status, status.pk)

    return render(request, 'admin/statuses/form.html', locals()) 
Example 19
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def edit_field(request, type, pk=None):
    if pk is None:
        field = Property(type=type)
    else:
        field = Property.objects.get(pk=pk)

    FieldForm = modelform_factory(Property, exclude=[])

    types = Property.TYPES
    title = Property._meta.verbose_name_plural
    object_list = Property.objects.filter(type=type)
    form = FieldForm(instance=field)

    if request.method == 'POST':
        form = FieldForm(request.POST, instance=field)

        if form.is_valid():
            field = form.save()
            messages.success(request, _(u'Field saved'))
            return redirect(field.get_admin_url())

    return render(request, 'admin/fields/form.html', locals()) 
Example 20
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def edit_template(request, pk=None):

    if pk is None:
        template = Template()
    else:
        template = get_object_or_404(Template, pk=pk)

    form = TemplateForm(instance=template)

    if request.method == 'POST':
        form = TemplateForm(request.POST, instance=template)

        if form.is_valid():
            template = form.save()
            messages.success(request, _(u'Template %s saved') % template.title)
            # generic view...
            return redirect(template.get_admin_url())

    form = form
    object_list = Template.objects.all()
    title = Template._meta.verbose_name_plural
    return render(request, 'admin/templates/form.html', locals()) 
Example 21
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def edit_group(request, pk=None):
    title = _(u'Edit Group')
    object_list = Group.objects.all()

    if pk is None:
        group = Group()
        form = GroupForm(instance=group)
    else:
        group = Group.objects.get(pk=pk)
        title = group.name
        form = GroupForm(instance=group)

    if request.method == 'POST':
        form = GroupForm(request.POST, instance=group)
        if form.is_valid():
            form.save()
            messages.success(request, _(u'Group saved'))
            return redirect(list_groups)

    return render(request, 'admin/users/group_form.html', locals()) 
Example 22
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def delete_user(request, user_id):
    user = get_object_or_404(User, pk=user_id)

    if request.method == "POST":
        if user == request.user:
            messages.error(request, _('Deleting yourself is not allowed'))
            return redirect(list_users)
        try:
            user.delete()
            messages.success(request, _("User deleted"))
        except Exception as e:
            messages.error(request, e)

        return redirect(list_users)

    return render(request, "admin/users/remove.html", locals()) 
Example 23
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def edit_location(request, pk=None):
    header = _('Locations')
    object_list = Location.objects.all()
    title = Location._meta.verbose_name_plural

    if pk is None:
        location = Location()
        location.timezone = request.user.timezone
    else:
        location = Location.objects.get(pk=pk)

    form = LocationForm(instance=location)

    if request.method == 'POST':
        form = LocationForm(request.POST, request.FILES, instance=location)
        if form.is_valid():
            try:
                location = form.save()
                messages.success(request, _(u'Location %s saved') % location.title)
                return redirect(location.get_admin_url())
            except Exception:
                pass # just show the form with the error

    return render(request, 'admin/locations/form.html', locals()) 
Example 24
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def delete_location(request, pk):
    location = get_object_or_404(Location, pk=pk)

    if request.method == 'POST':
        try:
            location.delete()
            messages.success(request, _(u'%s deleted') % location.title)
        except Exception as e:
            messages.error(request, e)

        return redirect(locations)

    title = _(u'Really delete this location?')
    explanation = _(u'This will not delete the orders at this location')

    return render(request, 'generic/delete.html', locals()) 
Example 25
Project: Servo   Author: fpsw   File: admin.py    License: BSD 2-Clause "Simplified" License 6 votes vote down vote up
def upload_users(request):
    """
    """
    action = request.path
    form = UserUploadForm()
    title = _('Upload Users')

    if request.method == 'POST':
        form = UserUploadForm(request.POST, request.FILES)
        if form.is_valid():
            try:
                users = form.save()
                messages.success(request, _('%d users imported') % len(users))
            except Exception as e:
                messages.error(request, e)
        else:
            messages.error(request, form.errors)

        return redirect(list_users)

    return render(request, "admin/users/upload_users.html", locals()) 
Example 26
Project: djreservation   Author: luisza   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
def finish_reservation(request):
    if not hasattr(request, 'reservation'):
        raise Http404(_("No reservation object started"))

    if request.method == "GET":
        response = render(
            request,
            'djreservation/reservation_confirm.html',
            {"reservation": request.reservation})
    elif request.method == "POST":
        reservation = request.reservation
        reservation.status = reservation.REQUESTED
        reservation.save()
        request.reservation = None
        send_reservation_email(reservation, request.user)
        response = render(
            request, 'djreservation/reservation_finished.html')
        response.set_cookie("reservation", "0")
        messages.success(request, _('Reservation finised'))
    return response 
Example 27
Project: djreservation   Author: luisza   File: views.py    License: GNU General Public License v3.0 6 votes vote down vote up
def form_valid(self, form):
        if not self.product_form.is_valid():
            return self.form_invalid(form)

        reservation = form.save(commit=False)
        reservation.user = self.request.user
        reservation.status = Reservation.REQUESTED
        reservation.save()
        self.object = Product(
            amount=self.product_form.cleaned_data['amount'],
            amount_field=self.amount_field,
            reservation=reservation,
            content_object=self.base_instance
        )
        self.object.save()

        if TOKENIZE:
            ReservationToken.objects.create(
                reservation=reservation,
                base_url=get_base_url(self.request)
            )

        send_reservation_email(reservation, self.request.user)
        messages.success(self.request, _('Reservation created successful'))
        return self.get_success_view() 
Example 28
Project: django-classified   Author: slyapustin   File: views.py    License: MIT License 5 votes vote down vote up
def form_valid(self, form):
        messages.success(self.request, _('Your profile settings was updated!'))
        return super(ProfileView, self).form_valid(form) 
Example 29
Project: pinax-documents   Author: pinax   File: hooks.py    License: MIT License 5 votes vote down vote up
def storage_color(self, user_storage):
        """
        Return labels indicating amount of storage used.
        """
        p = user_storage.percentage
        if p >= 0 and p < 60:
            return "success"
        if p >= 60 and p < 90:
            return "warning"
        if p >= 90 and p <= 100:
            return "danger"
        raise ValueError("percentage out of range") 
Example 30
Project: pinax-documents   Author: pinax   File: hooks.py    License: MIT License 5 votes vote down vote up
def folder_created_message(self, request, folder):
        """
        Send messages.success message after successful folder creation.
        """
        messages.success(request, _(f"Folder {folder} was created"))