def mobile_edit_category(request, company_id): try: c = Company.objects.get(id=company_id) except Company.DoesNotExist: return JsonError(_("Company does not exist")) if not has_permission(request.user, c, 'category', 'edit'): return JsonError(_("You have no permission to edit products")) data = JsonParse(request.POST['data']) try: category = Category.objects.get(id=int(data['id']), company=c) except Category.DoesNotExist: return JsonError(_("Category does not exsist")) # data['company'] = c valid = validate_category(request.user, c, data, category=category) if not valid.get('status'): return JsonError(valid['message']) form = valid['form'] category = form.save() return JsonOk(extra=category_to_dict(category, android=True))
def mobile_add_category(request, company_id): try: c = Company.objects.get(id=company_id) except Company.DoesNotExist: return JsonError(_("Company does not exist")) if not has_permission(request.user, c, 'category', 'edit'): return JsonError(_("You have no permission to edit products")) data = JsonParse(request.POST['data']) # data['company'] = c valid = validate_category(request.user, c, data) if not valid.get('status'): return JsonError(valid['message']) form = valid['form'] category = form.save(False) if 'created_by' not in form.cleaned_data: category.created_by = request.user if 'company_id' not in form.cleaned_data: category.company_id = c.id category = form.save() return JsonOk(extra=category_to_dict(category, android=True))