Python django.utils.translation.ugettext() Examples

The following are 30 code examples of django.utils.translation.ugettext(). 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 also want to check out all available functions/classes of the module django.utils.translation , or try the search function .
Example #1
Source File: order.py    From Servo with BSD 2-Clause "Simplified" License 7 votes vote down vote up
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()) 
Example #2
Source File: product.py    From Servo with 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 #3
Source File: search.py    From Servo with BSD 2-Clause "Simplified" License 7 votes vote down vote up
def products(request):
    """
    Searches our local inventory
    """
    query = request.GET.get("q")
    request.session['search_query'] = query

    results = Product.objects.filter(
        Q(code__icontains=query) | Q(title__icontains=query) | Q(eee_code__icontains=query)
    )

    page = request.GET.get("page")
    products = paginate(results, page, 50)

    title = _(u'Search results for "%s"') % query
    group = ProductCategory(title=_('All'), slug='all')

    return render(request, 'products/search.html', locals()) 
Example #4
Source File: views.py    From django-classified with MIT License 7 votes vote down vote up
def dispatch(self, *args, **kwargs):
        profile = Profile.get_or_create_for_user(self.request.user)
        if not profile.allow_add_item():
            messages.error(self.request, _('You have reached the limit!'))
            return redirect(reverse('django_classified:user-items'))

        return super(ItemCreateView, self).dispatch(*args, **kwargs) 
Example #5
Source File: account.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example #6
Source File: gsx.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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()) 
Example #7
Source File: device.py    From Servo with 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 #8
Source File: customer.py    From Servo with 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 #9
Source File: search.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def customers(request):
    """
    Searches for customers from "spotlight"
    """
    query = request.GET.get("q")
    kind = request.GET.get('kind')
    request.session['search_query'] = query

    customers = Customer.objects.filter(
        Q(fullname__icontains=query) | Q(email__icontains=query) | Q(phone__contains=query)
    )

    if kind == 'company':
        customers = customers.filter(is_company=True)

    if kind == 'contact':
        customers = customers.filter(is_company=False)

    title = _('%d results for "%s"') % (customers.count(), query)

    return render(request, "customers/search.html", locals()) 
Example #10
Source File: order.py    From Servo with 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 #11
Source File: gsx.py    From Servo with 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 #12
Source File: gsx.py    From Servo with 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 #13
Source File: product.py    From Servo with 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 #14
Source File: gsx.py    From Servo with 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 #15
Source File: device.py    From Servo with 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 #16
Source File: search.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def devices(request):
    """
    Searching for devices from the main navbar
    """
    query = request.GET.get("q", '').strip()
    request.session['search_query'] = query

    query = query.upper()
    valid_arg = gsxws.validate(query)

    if valid_arg in ('serialNumber', 'alternateDeviceId',):
        return redirect(search_gsx, "warranty", valid_arg, query)

    devices = Device.objects.filter(
        Q(sn__icontains=query) | Q(description__icontains=query)
    )

    title = _(u'Devices matching "%s"') % query

    return render(request, "devices/search.html", locals()) 
Example #17
Source File: customer.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def move(request, pk, new_parent=None):
    """
    Moves a customer under another customer
    """
    customer = get_object_or_404(Customer, pk=pk)

    if new_parent is not None:
        if int(new_parent) == 0:
            new_parent = None
            msg = _(u"Customer %s moved to top level") % customer
        else:
            new_parent = Customer.objects.get(pk=new_parent)
            d = {'customer': customer, 'target': new_parent}
            msg = _(u"Customer %(customer)s moved to %(target)s") % d

        try:
            customer.move_to(new_parent)
            customer.save() # To update fullname
            messages.success(request, msg)
        except Exception as e:
            messages.error(request, e)

        return redirect(customer)

    return render(request, "customers/move.html", locals()) 
Example #18
Source File: checkin.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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()) 
Example #19
Source File: checkin.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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()) 
Example #20
Source File: note.py    From Servo with 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 #21
Source File: note.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
def prep_list_view(request, kind):
    """Prepare the view for listing notes/messages."""
    data = {'title': _("Messages")}
    all_notes = Note.objects.all().order_by("-created_at")

    if kind == "articles":
        all_notes = Article.objects.all().order_by('-date_created')
    if kind == "inbox":
        all_notes = all_notes.filter(order=None).order_by("is_read", "-created_at")
    if kind == "sent":
        all_notes = all_notes.filter(created_by=request.user)
    if kind == "flagged":
        all_notes = all_notes.filter(is_flagged=True)
    if kind == "escalations":
        all_notes = Note.objects.all().exclude(escalation=None)

    page = request.GET.get("page")
    notes = paginate(all_notes, page, 20)

    data['kind'] = kind
    data['notes'] = notes
    data['search_hint'] = "notes"
    data['inbox_count'] = Note.objects.filter(order=None).count()

    return data 
Example #22
Source File: order.py    From Servo with 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 #23
Source File: order.py    From Servo with BSD 2-Clause "Simplified" License 6 votes vote down vote up
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) 
Example #24
Source File: account.py    From Servo with 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 #25
Source File: account.py    From Servo with 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 #26
Source File: order.py    From Servo with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def add_product(request, pk, product_id):
    "Adds this product to this Sales Order"
    order = Order.objects.get(pk=pk)
    product = Product.objects.get(pk=product_id)
    order.add_product(product, 1, request.user)
    messages.success(request, _(u'Product %s added') % product.code)

    return redirect(order) 
Example #27
Source File: purchases.py    From Servo with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def delete_po(request, po_id):
    po = get_object_or_404(PurchaseOrder, pk=po_id)
    try:
        po.delete()
        messages.success(request, _("Purchase Order %s deleted" % po_id))
    except Exception as e:
        messages.error(request, e)
    return redirect(list_pos) 
Example #28
Source File: order.py    From Servo with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def prepare_detail_view(request, pk):
    """
    Prepares the view for whenever we're dealing with a specific order
    """
    order = get_object_or_404(Order, pk=pk)

    request.session['current_order_id'] = None
    request.session['current_order_code'] = None
    request.session['current_order_customer'] = None

    title = _(u'Order %s') % order.code
    priorities = Queue.PRIORITIES
    followers = order.followed_by.all()
    locations = Location.objects.filter(enabled=True)
    queues = request.user.queues.all()
    users = order.get_available_users(request.user)

    # wrap the customer in a list for easier recursetree
    if order.customer is not None:
        customer = order.customer.get_ancestors(include_self=True)
        title = u'%s | %s' % (title, order.customer.name)
    else:
        customer = []

    statuses = []
    checklists = []

    if order.queue is not None:
        checklists = Checklist.objects.filter(queues=order.queue)
        statuses = order.queue.queuestatus_set.all()

    if order.is_editable:
        request.session['current_order_id'] = order.pk
        request.session['current_order_code'] = order.code
        request.session['return_to'] = order.get_absolute_url()
        if order.customer:
            request.session['current_order_customer'] = order.customer.pk

    return locals() 
Example #29
Source File: order.py    From Servo with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def toggle_follow(request, order_id):
    order = get_object_or_404(Order, pk=order_id)
    data = {'icon': "open", 'action': _("Follow")}

    if request.user in order.followed_by.all():
        order.followed_by.remove(request.user)
    else:
        order.followed_by.add(request.user)
        data = {'icon': "close", 'action': _("Unfollow")}

    if request.is_ajax():
        return render(request, "orders/toggle_follow.html", data)

    return redirect(order) 
Example #30
Source File: order.py    From Servo with BSD 2-Clause "Simplified" License 5 votes vote down vote up
def reserve_products(request, pk):
    order = get_object_or_404(Order, pk=pk)

    if request.method == 'POST':
        for p in order.products.all():
            p.reserve_product()

        msg = _(u"Products of order %s reserved") % order.code
        order.notify("products_reserved", msg, request.user)
        messages.info(request, msg)

        return redirect(order)

    return render(request, "orders/reserve_products.html", locals())