def create_field_group(request, profile_uuid): """ Creates a field group for a given InputProfile """ ipt = InputProfileTemplating() exists = ipt.check_exists(profile_uuid) if exists: if request.method == 'POST': # now check to see if the we have edit permissions proj_inp = ProjectInputs(ipt.project_uuid, request) if proj_inp.edit_permitted or request.user.is_superuser: mifg = ManageInputFieldGroup() mifg.project_uuid = ipt.project_uuid mifg.profile_uuid = profile_uuid result = mifg.create_update_from_post(request.POST) json_output = json.dumps(result, indent=4, ensure_ascii=False) return HttpResponse( json_output, content_type='application/json; charset=utf8') else: json_output = json.dumps({'error': 'edit permission required'}, indent=4, ensure_ascii=False) return HttpResponse( json_output, content_type='application/json; charset=utf8', status=401) else: return HttpResponseForbidden else: raise Http404
def update_field(request, field_uuid): """ Updates a field group for a given InputProfile """ mifg = ManageInputFieldGroup() inp_obj = mifg.get_field_group(fgroup_uuid) if inp_obj is not False: if request.method == 'POST': # now check to see if the we have edit permissions proj_inp = ProjectInputs(inp_obj.project_uuid, request) if proj_inp.edit_permitted or request.user.is_superuser: result = mifg.create_update_from_post(request.POST, fgroup_uuid) json_output = json.dumps(result, indent=4, ensure_ascii=False) return HttpResponse( json_output, content_type='application/json; charset=utf8') else: json_output = json.dumps({'error': 'edit permission required'}, indent=4, ensure_ascii=False) return HttpResponse( json_output, content_type='application/json; charset=utf8', status=401) else: return HttpResponseForbidden else: raise Http404
def reorder_item(request, uuid): """ handles a request to reorder an item """ found = False fieldgroup_obj = False field_obj = False mifg = ManageInputFieldGroup() fieldgroup_obj = mifg.get_field_group(uuid) if fieldgroup_obj is not False: found = True project_uuid = fieldgroup_obj.project_uuid item_type = 'field-groups' else: mif = ManageInputField() field_obj = mif.get_field(uuid) if field_obj is not False: project_uuid = field_obj.project_uuid found = True item_type = 'fields' if found: if request.method == 'POST': proj_inp = ProjectInputs(project_uuid, request) if proj_inp.edit_permitted or request.user.is_superuser: # ok to reorder the item if 'sort_change' in request.POST: sort_change = request.POST['sort_change'] else: sort_change = 0 result = mifg.update_sort_field_group_or_field( sort_change, uuid, item_type) json_output = json.dumps(result, indent=4, ensure_ascii=False) return HttpResponse( json_output, content_type='application/json; charset=utf8') else: json_output = json.dumps({'error': 'edit permission required'}, indent=4, ensure_ascii=False) return HttpResponse( json_output, content_type='application/json; charset=utf8', status=401) else: return HttpResponseForbidden else: raise Http404