Exemplo n.º 1
0
def _get_storage_units(category_name, value_name):
    # We may specify a storage unit separately from display units
    # We do this for area, since GEOS returns m² but we want to display ft²
    # If there are no storage units specified, use the display units
    storage_defaults = DotDict(settings.STORAGE_UNITS)
    return storage_defaults.get(category_name + '.' + value_name,
                                default=_get_display_default(
                                    category_name, value_name, 'units'))
Exemplo n.º 2
0
def _get_storage_units(category_name, value_name):
    # We may specify a storage unit separately from display units
    # We do this for area, since GEOS returns m² but we want to display ft²
    # If there are no storage units specified, use the display units
    storage_defaults = DotDict(settings.STORAGE_UNITS)
    return storage_defaults.get(
        category_name + '.' + value_name,
        default=_get_display_default(category_name, value_name, 'units'))
Exemplo n.º 3
0
def add_to_config(config, *categories):
    config = DotDict(deepcopy(config or {}))
    for category in categories:
        lookup = '.'.join(['search_config', category])
        specs = config.setdefault(lookup, [])
        if 0 == len([v for s in specs for v in s.values() if v == identifier]):
            # mutates config[lookup]
            specs.append({u'identifier': identifier})

    return config
Exemplo n.º 4
0
def add_to_config(config, *categories):
    config = DotDict(deepcopy(config or {}))
    for category in categories:
        lookup = '.'.join(['search_config', category])
        specs = config.setdefault(lookup, [])
        if 0 == len([v for s in specs for v in s.values() if v == identifier]):
            # mutates config[lookup]
            specs.append({u'identifier': identifier})

    return config
Exemplo n.º 5
0
def remove_from_config(config, *categories):
    config = DotDict(deepcopy(config or {}))
    for category in categories:
        lookup = '.'.join(['search_config', category])
        specs = config.get(lookup)
        if specs:
            find_index = [i for i, s in enumerate(specs)
                          if identifier in s.values()]
            if 0 < len(find_index):
                specs.pop(find_index[0])

    return config
Exemplo n.º 6
0
def remove_from_config(config, *categories):
    config = DotDict(deepcopy(config or {}))
    for category in categories:
        lookup = '.'.join(['search_config', category])
        specs = config.get(lookup)
        if specs:
            find_index = [
                i for i, s in enumerate(specs) if identifier in s.values()
            ]
            if 0 < len(find_index):
                specs.pop(find_index[0])

    return config
def add_to_config(config, *categories):
    config = deepcopy(config or DotDict({}))
    for category in categories:
        lookup = '.'.join(['search_config', category])
        specs = config.setdefault(lookup, [])
        if True not in [identifier in v for s in specs for v in s.values()]:
            # mutates config[lookup]
            specs.append({u'identifier': identifier})

    return config
def remove_from_config(config, *categories):
    config = deepcopy(config or DotDict({}))
    for category in categories:
        lookup = '.'.join(['search_config', category])
        specs = config.get(lookup)
        if specs:
            for index, spec in enumerate(specs):
                if identifier in spec.values():
                    break
            if index < len(specs):
                specs.pop(index)

    return config
Exemplo n.º 9
0
def get_udfc_search_fields(instance, user):
    from treemap.models import InstanceUser
    from treemap.udf import UDFModel
    from treemap.util import to_object_name, leaf_models_of_class
    from treemap.lib.perms import udf_write_level, READ, WRITE

    try:
        iu = instance.instanceuser_set.get(user__pk=user.pk)
    except InstanceUser.DoesNotExist:
        iu = None

    data = DotDict({'models': set(), 'udfc': {}})
    for clz in leaf_models_of_class(UDFModel):
        model_name = clz.__name__
        if model_name not in ['Tree'] + instance.map_feature_types:
            continue
        for k, v in clz.collection_udf_settings.items():
            udfds = (u for u in udf_defs(instance, model_name) if u.name == k)
            for udfd in udfds:
                if udf_write_level(iu, udfd) in (READ, WRITE):
                    _base_nest_path = 'udfc.%s.' % (to_object_name(k))
                    ids_nest_path = (
                        '%sids.%s' %
                        (_base_nest_path, to_object_name(model_name)))
                    models_nest_path = (
                        '%smodels.%s' %
                        (_base_nest_path, to_object_name(model_name)))
                    data[ids_nest_path] = udfd.pk
                    data[models_nest_path] = {
                        'udfd': udfd,
                        'fields': udfd.datatype_dict[0]['choices']
                    }
                    p = 'udfc.%s.' % to_object_name(k)
                    data[p + 'action_verb'] = v['action_verb']
                    data[p + 'range_field_key'] = v['range_field_key']
                    data[p + 'action_field_key'] = v['action_field_key']
                    data['models'] |= {clz}

    return data
Exemplo n.º 10
0
 def to_python(self, value):
     if isinstance(value, basestring):
         obj = json.loads(value or "{}")
         return DotDict(obj) if isinstance(obj, dict) else obj
     else:
         return value
Exemplo n.º 11
0
from django.utils.translation import ugettext_noop

import copy
import re

from treemap.DotDict import DotDict
from treemap.lib.object_caches import udf_defs

DEFAULT_MOBILE_SEARCH_FIELDS = DotDict({
    'standard': [{
        'identifier': 'species.id'
    }, {
        'identifier': 'tree.diameter'
    }, {
        'identifier': 'tree.height'
    }],
    'missing': [{
        'identifier': 'species.id'
    }, {
        'identifier': 'tree.diameter'
    }, {
        'identifier': 'mapFeaturePhoto.id'
    }]
})

DEFAULT_SEARCH_FIELDS = DotDict({
    'general': [{
        'identifier': 'mapFeature.updated_at'
    }, {
        'identifier': 'mapFeature.updated_by'
    }],
    'missing': [{