Пример #1
0
def delete_item_assertion(request, uuid):
    """ Handles POST requests to DELETE an assertion for an item """
    item_edit = ItemBasicEdit(uuid, request)
    if item_edit.manifest is not False:
        if request.method == 'POST':
            if item_edit.edit_permitted or request.user.is_superuser:
                item_ass = ItemAssertion()
                item_ass.uuid = uuid
                item_ass.project_uuid = item_edit.manifest.project_uuid
                result = item_ass.delete_assertion(request.POST)
                result['errors'] = item_edit.errors
                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
Пример #2
0
    def profile_field_update(self, item_man, field_uuid, field_values):
        """ lookup the object for the profile's input field
            based on the field_uuid

            Only returns a field that is NOT
            required by open context,
            since those get special handling
        """
        item_ass = ItemAssertion()
        item_ass.source_id = item_man.source_id
        for fgroup in self.profile_obj['fgroups']:
            obs_num = fgroup['obs_num']
            for field in fgroup['fields']:
                if field['oc_required'] is False \
                   and field['id'] == field_uuid:
                    if 'obs_num' not in field:
                        field['obs_num'] = obs_num
                    # we've found the field!
                    # first delete existing uses of this field
                    Assertion.objects\
                             .filter(uuid=item_man.uuid,
                                     predicate_uuid=field['predicate_uuid'])\
                             .delete()
                    value_index = 0
                    for field_value in field_values:
                        item_ass.validate_save_field_value(
                            item_man, field, field_value, value_index)
                        value_index += 1
Пример #3
0
 def add_description_note(self, uuid, item_type, source_id, note):
     """ adds a descriptive note to a created item """
     item_assert = ItemAssertion()
     item_assert.project_uuid = self.project_uuid
     item_assert.source_id = source_id
     item_assert.uuid = uuid
     item_assert.item_type = item_type
     item_assert.add_description_note(note)
Пример #4
0
def add_edit_item_assertion(request, uuid):
    """ Handles POST requests to add an assertion for an item """
    item_edit = ItemBasicEdit(uuid, request)
    if item_edit.manifest is not False:
        if request.method == 'POST':
            if item_edit.edit_permitted or request.user.is_superuser:
                field_data = False
                if 'field_data' in request.POST:
                    field_data_json = request.POST['field_data']
                    try:
                        field_data = json.loads(field_data_json)
                    except:
                        field_data = False
                if field_data is False:
                    json_output = json.dumps(
                        {
                            'error':
                            'Need to POST "field_data" with JSON encoded text.'
                        },
                        indent=4,
                        ensure_ascii=False)
                    return HttpResponse(
                        json_output,
                        content_type='application/json; charset=utf8',
                        status=400)
                else:
                    item_ass = ItemAssertion()
                    item_ass.uuid = uuid
                    item_ass.project_uuid = item_edit.manifest.project_uuid
                    result = item_ass.add_edit_assertions(
                        field_data, item_edit.manifest)
                    result['errors'] = item_edit.errors
                    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
Пример #5
0
    def profile_field_update(self, item_man, sub_field_key, act_sub_field):
        """ lookup the object for the profile's input field
            based on the field_uuid

            Only returns a field that is NOT
            required by open context,
            since those get special handling
        """
        # field_uuid is the field identifier from the data
        # submitted by the user
        field_uuid = act_sub_field['field_uuid']
        for fgroup in self.profile_obj['fgroups']:
            obs_num = fgroup['obs_num']
            for field in fgroup['fields']:
                if field['oc_required'] is False \
                   and field['id'] == field_uuid:
                    if 'obs_num' not in act_sub_field:
                        act_sub_field['obs_num'] = obs_num
                    # we've found the field!
                    # first delete existing uses of this field
                    item_ass = ItemAssertion()
                    item_ass.source_id = item_man.source_id
                    add_edit_field_data = {sub_field_key: act_sub_field}
                    item_ass.add_edit_assertions(add_edit_field_data, item_man)