Exemplo n.º 1
0
 def delete(self, fgroup_uuid):
     """ Deletes a field group, including
         the fields it contains
     """
     mif = ManageInputField()
     gfields = InputField.objects\
                         .filter(fgroup_uuid=fgroup_uuid)
     for gfield in gfields:
         # use the manage input field object delete method
         mif.delete(gfield.uuid)
     # now finally delete the fields in this field group
     gfields = InputField.objects\
                         .filter(fgroup_uuid=fgroup_uuid)\
                         .delete()
     # now delete the field group itself
     inp_obj = self.get_field_group(fgroup_uuid)
     if inp_obj is not False:
         ok = True
         label = inp_obj.label
         note = 'Deleted Field Group: "' + label + '" (' + fgroup_uuid + ')'
         inp_obj.delete()
     else:
         ok = False
         label = fgroup_uuid + ' not found'
         note = label
     self.response = {'action': 'delete-input-field-group',
                      'ok': ok,
                      'change': {'uuid': fgroup_uuid,
                                 'label': label,
                                 'note': note}}
     return self.response
Exemplo n.º 2
0
def create_field(request, fgroup_uuid):
    """ Creates a field group for a given InputProfile
    """
    mifg = ManageInputFieldGroup()
    inp_obj = mifg.get_field_group(fgroup_uuid)
    if inp_obj is not False:
        mif = ManageInputField()
        mif.fgroup_uuid = fgroup_uuid
        mif.profile_uuid = inp_obj.profile_uuid
        mif.project_uuid = inp_obj.project_uuid
        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:
                # now finally try to create the Field
                result = mif.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
Exemplo n.º 3
0
def delete_field(request, field_uuid):
    """ Delete a field group for a given InputProfile
    """
    mif = ManageInputField()
    inp_obj = mif.get_field(field_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 = mif.delete(field_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
Exemplo n.º 4
0
def delete_field(request, field_uuid):
    """ Delete a field group for a given InputProfile
    """
    mif = ManageInputField()
    inp_obj = mif.get_field(field_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 = mif.delete(field_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
Exemplo n.º 5
0
 def delete(self, fgroup_uuid):
     """ Deletes a field group, including
         the fields it contains
     """
     mif = ManageInputField()
     gfields = InputField.objects\
                         .filter(fgroup_uuid=fgroup_uuid)
     for gfield in gfields:
         # use the manage input field object delete method
         mif.delete(gfield.uuid)
     # now finally delete the fields in this field group
     gfields = InputField.objects\
                         .filter(fgroup_uuid=fgroup_uuid)\
                         .delete()
     # now delete the field group itself
     inp_obj = self.get_field_group(fgroup_uuid)
     if inp_obj is not False:
         ok = True
         label = inp_obj.label
         note = 'Deleted Field Group: "' + label + '" (' + fgroup_uuid + ')'
         inp_obj.delete()
     else:
         ok = False
         label = fgroup_uuid + ' not found'
         note = label
     self.response = {
         'action': 'delete-input-field-group',
         'ok': ok,
         'change': {
             'uuid': fgroup_uuid,
             'label': label,
             'note': note
         }
     }
     return self.response
Exemplo n.º 6
0
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
Exemplo n.º 7
0
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
Exemplo n.º 8
0
def create_field(request, fgroup_uuid):
    """ Creates a field group for a given InputProfile
    """
    mifg = ManageInputFieldGroup()
    inp_obj = mifg.get_field_group(fgroup_uuid)
    if inp_obj is not False:
        mif = ManageInputField()
        mif.fgroup_uuid = fgroup_uuid
        mif.profile_uuid = inp_obj.profile_uuid
        mif.project_uuid = inp_obj.project_uuid
        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:
                # now finally try to create the Field
                result = mif.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