Пример #1
0
def field_meta_update(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                if 'label' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_label(request.POST['label'],
                                           request.POST['field_num'])
                elif 'value_prefix' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_value_prefix(request.POST['value_prefix'],
                                                  request.POST['field_num'])
                elif 'field_value_cat' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_value_cat(request.POST['field_value_cat'],
                                               request.POST['field_num'])
                ip.get_subject_type_fields()
                json_output = json.dumps(ip.jsonify_fields(),
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Пример #2
0
def finalize(request, source_id):
    """ Show HTML form to change relationships for entities
        to be created / or updated from an import table
    """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('finalize',
                                   ip.project_uuid,
                                   source_id)
            template = loader.get_template('imports/finalize.html')
            context = {
                'ip': ip,
                'base_url': base_url,
                'user': request.user
            }
            return HttpResponse(template.render(context, request))
        else:
            raise Http404
Пример #3
0
def field_types_more(request, source_id):
    """ Show HTML form further classifying subject fields """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_subject_type_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('field-types-more',
                                   ip.project_uuid,
                                   source_id)
            if len(ip.fields) > 0:
                template = loader.get_template('imports/field-types-more.html')
                context = {
                    'ip': ip,
                    'base_url': base_url,
                    'user': request.user
                }
                return HttpResponse(template.render(context, request))
            else:
                redirect = '../../imports/field-types/' + source_id
                return HttpResponseRedirect(redirect)
        else:
            raise Http404
Пример #4
0
def field_classify(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                ifd.project_uuid = ip.project_uuid
                if 'field_type' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_type(request.POST['field_type'],
                                          request.POST['field_num'])
                elif 'field_data_type' in request.POST and 'field_num' in request.POST:
                    ifd.update_field_data_type(request.POST['field_data_type'],
                                               request.POST['field_num'])
                elif 'match_all_unclasified' in request.POST:
                    ifd.match_all_unclassified()
                ip.get_fields(ifd.field_num_list)
                json_output = json.dumps(ip.jsonify_fields(),
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Пример #5
0
def create(request, source_id):
    """ Classifies one or more fields with posted data """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        if request.method == 'POST':
            ip = ImportProfile(source_id)
            if ip.project_uuid is not False:
                ifd = ImportFieldDescribe(source_id)
                ifd.project_uuid = ip.project_uuid
                if request.POST['predicate'] == Assertion.PREDICATES_CONTAINS:
                    ifd.update_field_contains(request.POST['field_num'],
                                              request.POST['object_field_num'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_CONTAINED_IN:
                    ifd.update_field_containedin_entity(request.POST['field_num'],
                                                        request.POST['object_uuid'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_MEDIA_PART_OF:
                    ifd.update_field_media_part_of_entity(request.POST['field_num'],
                                                          request.POST['object_field_num'])
                elif request.POST['predicate'] == Assertion.PREDICATES_LINK:
                    if 'object_field_num' in request.POST:
                        ifd.update_field_links(request.POST['field_num'],
                                               request.POST['object_field_num'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_DESCRIBES:
                    if 'object_field_num' in request.POST:
                        ifd.update_desciption(request.POST['field_num'],
                                              request.POST['object_field_num'])
                elif request.POST['predicate'] == ImportFieldAnnotation.PRED_VALUE_OF:
                    if 'object_field_num' in request.POST:
                        ifd.update_variable_value(request.POST['field_num'],
                                                  request.POST['object_field_num'])
                else:
                    if request.POST['predicate'] == '-1':
                        # the predicate is not yet reconciled
                        predicate_id = ifd.make_or_reconcile_link_predicate(request.POST['predicate_label'],
                                                                            ifd.project_uuid)
                    else:
                        predicate_id = request.POST['predicate']
                    ifd.update_field_custom_predicate(request.POST['field_num'],
                                                      request.POST['object_field_num'],
                                                      predicate_id,
                                                      request.POST['predicate_type'])
                ip.get_field_annotations()
                anno_list = ip.jsonify_field_annotations()
                json_output = json.dumps(anno_list,
                                         indent=4,
                                         ensure_ascii=False)
                return HttpResponse(json_output,
                                    content_type='application/json; charset=utf8')
            else:
                raise Http404
        else:
            return HttpResponseForbidden
Пример #6
0
def field_complex_descriptions(request, source_id):
    """ Show HTML form to change group descriptive
        properties together into groups of
        complex descriptions
    """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            if len(ip.fields) > 0:
                ip.get_field_annotations()
                ip.jsonify_field_annotations()
                imnav = ImportNavigation()
                ip.nav = imnav.set_nav('field-entity-relations',
                                       ip.project_uuid,
                                       source_id)
                template = loader.get_template('imports/field-entity-relations.html')
                context = {
                    'ip': ip,
                    'base_url': base_url,
                    'user': request.user
                }
                return HttpResponse(template.render(context, request))
            else:
                redirect = '../../imports/field-types/' + source_id
                return HttpResponseRedirect(redirect)
        else:
            raise Http404
Пример #7
0
def field_entity_relations(request, source_id):
    """ Show HTML form to change relationships for entities
        to be created / or updated from an import table
    """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        rp = RootPath()
        base_url = rp.get_baseurl()
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            if len(ip.fields) > 0:
                ip.get_field_annotations()
                ip.jsonify_field_annotations()
                imnav = ImportNavigation()
                ip.nav = imnav.set_nav('field-entity-relations',
                                       ip.project_uuid,
                                       source_id)
                template = loader.get_template('imports/field-entity-relations.html')
                context = RequestContext(request,
                                         {'ip': ip,
                                          'base_url': base_url})
                return HttpResponse(template.render(context))
            else:
                redirect = '../../imports/field-types/' + source_id
                return HttpResponseRedirect(redirect)
        else:
            raise Http404
Пример #8
0
def field_list(request, source_id):
    """ Gets list of fields with annotations from source table """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            json_output = json.dumps(ip.jsonify_fields(),
                                     indent=4,
                                     ensure_ascii=False)
            return HttpResponse(json_output,
                                content_type='application/json; charset=utf8')
        else:
            raise Http404
Пример #9
0
def view(request, source_id):
    """ Returns JSON data for an identifier in its hierarchy """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_field_annotations()
            anno_list = ip.jsonify_field_annotations()
            json_output = json.dumps(anno_list,
                                     indent=4,
                                     ensure_ascii=False)
            return HttpResponse(json_output,
                                content_type='application/json; charset=utf8')
        else:
            raise Http404
Пример #10
0
def field_types(request, source_id):
    """ Show HTML form listing fields classified by field type """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('field-types',
                                   ip.project_uuid,
                                   source_id)
            template = loader.get_template('imports/field-types.html')
            context = RequestContext(request,
                                     {'ip': ip})
            return HttpResponse(template.render(context))
        else:
            raise Http404
Пример #11
0
def field_descriptions(request, source_id):
    """ Show HTML form to change relationships for entities
        to be created / or updated from an import table
    """
    if not request.user.is_superuser:
        return HttpResponse('Unauthorized', status=401)
    else:
        ip = ImportProfile(source_id)
        if ip.project_uuid is not False:
            ip.get_fields()
            imnav = ImportNavigation()
            ip.nav = imnav.set_nav('field-descriptions',
                                   ip.project_uuid,
                                   source_id)
            template = loader.get_template('imports/field-descriptions.html')
            context = RequestContext(request,
                                     {'ip': ip})
            return HttpResponse(template.render(context))
        else:
            raise Http404