Beispiel #1
0
def index(request, supplier_type):
    instance = SupplierFactory.create(supplier_type)
    suppliers = instance.objects.all()
    data = {
        'suppliers': suppliers,
    }

    return render_to_response(
        'suppliers/%s/index.html' % supplier_type,
        data,
        context_instance=RequestContext(request),
    )
Beispiel #2
0
def delete(request, supplier_type):
    supplier_id = int(request.POST.get('entry_id', 0))
    instance = SupplierFactory.create(supplier_type)
    label = capwords(supplier_type)

    try:
        supplier = instance.objects.get(pk=supplier_id)
        supplier.delete()
        messages.success(request, '%s Supplier deleted' % label)
    except instance.DoesNotExist:
        messages.error(request, '%s Supplier with id %i does not exist' % (label, supplier_id))

    if supplier_type == 'foreign':
        data = reverse('suppliers:index-foreign')
    else:
        data = reverse('suppliers:index-local')
    return HttpResponse(data, mimetype="application/javascript")
Beispiel #3
0
def supplier_number_ajax(request, supplier_type):
    company_name = request.GET.get('company_name', '')
    country_id = int(request.GET.get('country_id', 0))

    company_name_prefix = company_name[:3].upper()

    suppliers = SupplierFactory.create(supplier_type).objects.filter(
        country=country_id,
        company_name__istartswith=company_name_prefix,
    )

    try:
        country_name = Country.objects.get(pk=country_id).name
    except Country.DoesNotExist:
        country_name = ''

    country_name_prefix = country_name[:2].upper()
    max_id = suppliers.count() + 1
    value = '%s/%s/%03d' % (country_name_prefix, company_name_prefix, max_id)
    data = json.dumps(value)
    return HttpResponse(data, mimetype='application/javascript')