Esempio n. 1
0
def remove(request):
    me = get_my_account(request)
    if is_authenticated(request) and is_staff(request):
        supplier_id = request.POST.get('id')
        try:
            s = Supplier(id=supplier_id)
            s.delete()
            return STATUS_GOOD
        except Exception:
            return JsonResponse({'status': 'bad', 'message': 'Could not remove supplier'})
    else:
        return JsonResponse({'status': 'bad', 'message': 'User not authorized staff member'})
Esempio n. 2
0
def add(request):
    me = get_my_account(request)
    if is_authenticated(request) and is_staff(request):
        supplier_name = request.POST.get('name')
        try:
            s = Supplier(name=supplier_name)
            s.save()
            s = Supplier.objects.get(name=supplier_name)
            return JsonResponse({'status': 'good', 'data': {
                'id': s.id,
                'name': s.name
            }})
        except Exception:
            return JsonResponse({'status': 'bad', 'message': 'Could not add supplier'})
    else:
        return JsonResponse({'status': 'bad', 'message': 'User not authorized staff member'})