(request, domain, data_type_id)
receives a JSON-update patch like following
    {
        "_id":"0920fe1c6d4c846e17ee33e2177b36d6",
        "tag":"growth",
        "view_link":"/a/gsid/fixtures/view_lookup_tables/?table_id:0920fe1c6d4c846e17ee33e2177b36d6",
        "is_global":false,
        "fields":{"genderr":{"update":"gender"},"grade":{}}
    }
receives a JSON-update patch like following
    {
        "_id":"0920fe1c6d4c846e17ee33e2177b36d6",
        "tag":"growth",
        "view_link":"/a/gsid/fixtures/view_lookup_tables/?table_id:0920fe1c6d4c846e17ee33e2177b36d6",
        "is_global":false,
        "fields":{"genderr":{"update":"gender"},"grade":{}}
    }
receives a JSON - update patch like following { _id : 0920fe1c6d4c846e17ee33e2177b36d6 tag : growth view_link : / a / gsid / fixtures / view_lookup_tables / ?table_id : 0920fe1c6d4c846e17ee33e2177b36d6 is_global : false fields : { genderr : { update : gender } grade : {} } }
def update_tables(request, domain, data_type_id):
    """
    receives a JSON-update patch like following
    {
        "_id":"0920fe1c6d4c846e17ee33e2177b36d6",
        "tag":"growth",
        "view_link":"/a/gsid/fixtures/view_lookup_tables/?table_id:0920fe1c6d4c846e17ee33e2177b36d6",
        "is_global":false,
        "fields":{"genderr":{"update":"gender"},"grade":{}}
    }
    """
    if data_type_id:
        try:
            data_type = FixtureDataType.get(data_type_id)
        except ResourceNotFound:
            raise Http404()

        if data_type.domain != domain:
            raise Http404()

        if request.method == 'GET':
            return json_response(strip_json(data_type))

        elif request.method == 'DELETE':
            with CouchTransaction() as transaction:
                data_type.recursive_delete(transaction)
            clear_fixture_cache(domain)
            return json_response({})
        elif not request.method == 'PUT':
            return HttpResponseBadRequest()

    if request.method == 'POST' or request.method == "PUT":
        fields_update = _to_kwargs(request)
        fields_patches = fields_update["fields"]
        data_tag = fields_update["tag"]
        is_global = fields_update["is_global"]
        description = fields_update["description"]

        # validate tag and fields
        validation_errors = []
        if is_identifier_invalid("{}_list".format(data_tag)):
            validation_errors.append(data_tag)
        for field_name, options in fields_update['fields'].items():
            method = list(options.keys())
            if 'update' in method:
                field_name = options['update']
            if is_identifier_invalid(field_name) and 'remove' not in method:
                validation_errors.append(field_name)
        validation_errors = [_(
            "\"%s\" cannot include special characters, begin or end with a space, "
            "or begin with \"xml\" or a number") % e for e in validation_errors
        ]
        if len(data_tag) < 1 or len(data_tag) > 31:
            validation_errors.append(_("Table ID must be between 1 and 31 characters."))

        if validation_errors:
            return json_response({
                'validation_errors': validation_errors,
                'error_msg': _(
                    "Could not update table because field names were not "
                    "correctly formatted"),
            })

        with CouchTransaction() as transaction:
            if data_type_id:
                data_type = _update_types(
                    fields_patches, domain, data_type_id, data_tag, is_global, description, transaction)
                _update_items(fields_patches, domain, data_type_id, transaction)
            else:
                if FixtureDataType.fixture_tag_exists(domain, data_tag):
                    return HttpResponseBadRequest("DuplicateFixture")
                else:
                    data_type = _create_types(
                        fields_patches, domain, data_tag, is_global, description, transaction)
        clear_fixture_cache(domain)
        return json_response(strip_json(data_type))
def update_tables ( request , domain , data_type_id ) : if data_type_id : try : data_type = FixtureDataType . get ( data_type_id ) except ResourceNotFound : raise Http404 ( ) if data_type . domain != domain : raise Http404 ( ) if request . method == 'GET' : return json_response ( strip_json ( data_type ) ) elif request . method == 'DELETE' : with CouchTransaction ( ) as transaction : data_type . recursive_delete ( transaction ) clear_fixture_cache ( domain ) return json_response ( { } ) elif not request . method == 'PUT' : return HttpResponseBadRequest ( ) if request . method == 'POST' or request . method == "PUT" : fields_update = _to_kwargs ( request ) fields_patches = fields_update [ "fields" ] data_tag = fields_update [ "tag" ] is_global = fields_update [ "is_global" ] description = fields_update [ "description" ] # validate tag and fields validation_errors = [ ] if is_identifier_invalid ( "{}_list" . format ( data_tag ) ) : validation_errors . append ( data_tag ) for field_name , options in fields_update [ 'fields' ] . items ( ) : method = list ( options . keys ( ) ) if 'update' in method : field_name = options [ 'update' ] if is_identifier_invalid ( field_name ) and 'remove' not in method : validation_errors . append ( field_name ) validation_errors = [ _ ( "\"%s\" cannot include special characters, begin or end with a space, " "or begin with \"xml\" or a number" ) % e for e in validation_errors ] if len ( data_tag ) < 1 or len ( data_tag ) > 31 : validation_errors . append ( _ ( "Table ID must be between 1 and 31 characters." ) ) if validation_errors : return json_response ( { 'validation_errors' : validation_errors , 'error_msg' : _ ( "Could not update table because field names were not " "correctly formatted" ) , } ) with CouchTransaction ( ) as transaction : if data_type_id : data_type = _update_types ( fields_patches , domain , data_type_id , data_tag , is_global , description , transaction ) _update_items ( fields_patches , domain , data_type_id , transaction ) else : if FixtureDataType . fixture_tag_exists ( domain , data_tag ) : return HttpResponseBadRequest ( "DuplicateFixture" ) else : data_type = _create_types ( fields_patches , domain , data_tag , is_global , description , transaction ) clear_fixture_cache ( domain ) return json_response ( strip_json ( data_type ) )