<commit_before>import json
from arches.app.models import models

class BaseDataType(object):

    def __init__(self, model=None):
        self.datatype_model = model

    def validate(self, value, source=None):
        return []

    def append_to_document(self, document, nodevalue, nodeid, tile):
        """
        Assigns a given node value to the corresponding key in a document in
        in preparation to index the document
        """
        pass

    def after_update_all(self):
        """
        Refreshes mv_geojson_geoms materialized view after save.
        """
        pass

    def transform_import_values(self, value):
        """
        Transforms values from probably string/wkt representation to specified
        datatype in arches
        """
        return value

    def transform_export_values(self, value, *args, **kwargs):
        """
        Transforms values from probably string/wkt representation to specified
        datatype in arches
        """
        return value

    def get_bounds(self, tile, node):
        """
        Gets the bounds of a geometry if the datatype is spatial
        """
        return None

    def get_layer_config(self, node=None):
        """
        Gets the layer config to generate a map layer (use if spatial)
        """
        return None

    def should_cache(self, node=None):
        """
        Tells the system if the tileserver should cache for a given node
        """
        return False

    def should_manage_cache(self, node=None):
        """
        Tells the system if the tileserver should clear cache on edits for a
        given node
        """
        return False

    def get_map_layer(self, node=None):
        """
        Gets the array of map layers to add to the map for a given node
        should be a dictionary including (as in map_layers table):
        nodeid, name, layerdefinitions, isoverlay, icon
        """
        return None

    def convert_value(self, tile, nodeid):
        """
        Converts '' values to null when saving a tile.
        """
        if tile.data[nodeid] == '':
            tile.data[nodeid] = None

    def get_map_source(self, node=None, preview=False):
        """
        Gets the map source definition to add to the map for a given node
        should be a dictionary including (as in map_sources table):
        name, source (json)
        """
        if node is None:
            return None
        source_config = {
            "type": "vector",
            "tiles": ["/tileserver/%s/{z}/{x}/{y}.pbf" % node.nodeid]
        }
        count = models.TileModel.objects.filter(data__has_key=str(node.nodeid)).count()
        if preview and count == 0:
            source_config = {
                "type": "geojson",
                "data": {<commit_msg>removing hardcoded tileserver url<commit_after>import json
from django.core.urlresolvers import reverse
from arches.app.models import models

class BaseDataType(object):

    def __init__(self, model=None):
        self.datatype_model = model

    def validate(self, value, source=None):
        return []

    def append_to_document(self, document, nodevalue, nodeid, tile):
        """
        Assigns a given node value to the corresponding key in a document in
        in preparation to index the document
        """
        pass

    def after_update_all(self):
        """
        Refreshes mv_geojson_geoms materialized view after save.
        """
        pass

    def transform_import_values(self, value):
        """
        Transforms values from probably string/wkt representation to specified
        datatype in arches
        """
        return value

    def transform_export_values(self, value, *args, **kwargs):
        """
        Transforms values from probably string/wkt representation to specified
        datatype in arches
        """
        return value

    def get_bounds(self, tile, node):
        """
        Gets the bounds of a geometry if the datatype is spatial
        """
        return None

    def get_layer_config(self, node=None):
        """
        Gets the layer config to generate a map layer (use if spatial)
        """
        return None

    def should_cache(self, node=None):
        """
        Tells the system if the tileserver should cache for a given node
        """
        return False

    def should_manage_cache(self, node=None):
        """
        Tells the system if the tileserver should clear cache on edits for a
        given node
        """
        return False

    def get_map_layer(self, node=None):
        """
        Gets the array of map layers to add to the map for a given node
        should be a dictionary including (as in map_layers table):
        nodeid, name, layerdefinitions, isoverlay, icon
        """
        return None

    def convert_value(self, tile, nodeid):
        """
        Converts '' values to null when saving a tile.
        """
        if tile.data[nodeid] == '':
            tile.data[nodeid] = None

    def get_map_source(self, node=None, preview=False):
        """
        Gets the map source definition to add to the map for a given node
        should be a dictionary including (as in map_sources table):
        name, source (json)
        """
        tileserver_url = reverse('tileserver')
        if node is None:
            return None
        source_config = {
            "type": "vector",
            "tiles": ["%s/%s/{z}/{x}/{y}.pbf" % (tileserver_url, node.nodeid)]
        }
        count = models.TileModel.objects.filter(data__has_key=str(node.nodeid)).count()
        if preview and count == 0:
            source_config = {
                "type": "geojson",
                "data": {
{'fraction_non_alphanumeric': 0.08646945562751619, 'fraction_numerical': 0.00035007876772273763, 'mean_word_length': 2.0057864281956865, 'pattern_counts': {'":': 8, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2239589', 'n_tokens_mistral': 1543, 'n_tokens_neox': 1501, 'n_words': 532}