コード例 #1
0
ファイル: instance.py プロジェクト: recklessromeo/otm-core
 def make_display_filter(feature_name):
     Feature = MapFeature.get_subclass(feature_name)
     if hasattr(Feature, "display_name_plural"):
         plural = Feature.display_name_plural
     else:
         plural = Feature.display_name + "s"
     return {"label": "Show %s" % plural.lower(), "model": feature_name}
コード例 #2
0
ファイル: instance.py プロジェクト: RickMohr/otm-core
    def add_map_feature_types(self, types):
        """
        add_map_feature_types(self, types)

        types is a list of map feature class names.

        Add these types to the instance config,
        save the instance!!!,
        and create udf rows for udfs that have settings defaults,
        if they don't already exist.
        """
        from treemap.models import MapFeature  # prevent circular import
        from treemap.audit import add_default_permissions

        classes = [MapFeature.get_subclass(type) for type in types]

        dups = set(types) & set(self.map_feature_types)
        if len(dups) > 0:
            raise ValidationError('Map feature types already added: %s' % dups)

        self._map_feature_types = list(self.map_feature_types) + list(types)
        self.save()

        for type, clz in zip(types, classes):
            settings = (getattr(clz, 'udf_settings', {}))
            for udfc_name, udfc_settings in settings.items():
                if udfc_settings.get('defaults'):
                    get_or_create_udf(self, type, udfc_name)

        add_default_permissions(self, models=classes)
コード例 #3
0
ファイル: instance.py プロジェクト: nvh3010/otm-core
 def make_display_filter(feature_name):
     Feature = MapFeature.get_subclass(feature_name)
     plural = Feature.terminology(self)['plural']
     return {
         'label': 'Show %s' % plural.lower(),
         'model': feature_name
     }
コード例 #4
0
ファイル: instance.py プロジェクト: briantanseng/otm-core
    def add_map_feature_types(self, types):
        """
        add_map_feature_types(self, types)

        types is a list of map feature class names.

        Add these types to the instance config,
        save the instance!!!,
        and create udf rows for udfs that have settings defaults,
        if they don't already exist.
        """
        from treemap.models import MapFeature  # prevent circular import
        from treemap.audit import add_default_permissions

        classes = [MapFeature.get_subclass(type) for type in types]

        dups = set(types) & set(self.map_feature_types)
        if len(dups) > 0:
            raise ValidationError('Map feature types already added: %s' % dups)

        self._map_feature_types = list(self.map_feature_types) + list(types)
        self.save()

        for type, clz in zip(types, classes):
            settings = (getattr(clz, 'udf_settings', {}))
            for udfc_name, udfc_settings in settings.items():
                if udfc_settings.get('defaults'):
                    get_or_create_udf(self, type, udfc_name)

        add_default_permissions(self, models=classes)
コード例 #5
0
ファイル: map_feature.py プロジェクト: jwalgran/otm-core
def render_map_feature_add(request, instance, type):
    if type in instance.map_feature_types[1:]:
        app = MapFeature.get_subclass(type).__module__.split(".")[0]
        template = "%s/%s_add.html" % (app, type)
        return render_to_response(template, None, RequestContext(request))
    else:
        raise Http404("Instance does not support feature type " + type)
コード例 #6
0
ファイル: instance.py プロジェクト: lorenanicole/OTM2
 def make_display_filter(feature_name):
     Feature = MapFeature.get_subclass(feature_name)
     if hasattr(Feature, 'display_name_plural'):
         plural = Feature.display_name_plural
     else:
         plural = Feature.display_name + 's'
     return {'label': 'Show %s' % plural.lower(), 'model': feature_name}
コード例 #7
0
ファイル: misc.py プロジェクト: lorenanicole/OTM2
def get_map_view_context(request, instance):
    resource_classes = [
        MapFeature.get_subclass(type) for type in instance.map_feature_types
    ]
    return {
        'fields_for_add_tree': [(trans('Tree Height'), 'Tree.height')],
        'resource_classes': resource_classes[1:]
    }
コード例 #8
0
ファイル: misc.py プロジェクト: summer-of-open-source/OTM2
def get_map_view_context(request, instance):
    resource_classes = [MapFeature.get_subclass(type)
                        for type in instance.map_feature_types]
    return {
        'fields_for_add_tree': [
            (trans('Tree Height'), 'Tree.height')
        ],
        'resource_classes': resource_classes[1:]
    }
コード例 #9
0
ファイル: map_feature.py プロジェクト: OpenTreeMap/otm-core
def render_map_feature_add(request, instance, type):
    if type in instance.map_feature_types[1:]:
        app = MapFeature.get_subclass(type).__module__.split('.')[0]
        try:
            template = '%s/%s_add.html' % (app, type)
        except:
            template = 'treemap/resource_add.html'
        return render(request, template, {'object_name': to_object_name(type)})
    else:
        raise_non_instance_404(type)
コード例 #10
0
ファイル: views.py プロジェクト: heath/OTM2
def _get_map_view_context(request, instance):
    resource_types = [{'name': type,
                       'display': MapFeature.get_subclass(type).display_name}
                      for type in instance.map_feature_types]
    return {
        'fields_for_add_tree': [
            (trans('Tree Height'), 'Tree.height')
        ],
        'resource_types': resource_types[1:]
    }
コード例 #11
0
def render_map_feature_add(request, instance, type):
    if type in instance.map_feature_types[1:]:
        app = MapFeature.get_subclass(type).__module__.split('.')[0]
        try:
            template = '%s/%s_add.html' % (app, type)
        except:
            template = 'treemap/resource_add.html'
        return render(request, template, {'object_name': to_object_name(type)})
    else:
        raise_non_instance_404(type)
コード例 #12
0
ファイル: instance.py プロジェクト: cgarrard/OTM2
 def make_display_filter(feature_name):
     Feature = MapFeature.get_subclass(feature_name)
     if hasattr(Feature, 'display_name_plural'):
         plural = Feature.display_name_plural
     else:
         plural = Feature.display_name + 's'
     return {
         'label': 'Show %s' % plural.lower(),
         'model': feature_name
     }
コード例 #13
0
ファイル: perms.py プロジェクト: nvh3010/otm-core
def any_resource_is_creatable(role_related_obj):
    role = _get_role_from_related_object(role_related_obj)
    if role is None:
        return False

    map_features = {MapFeature.get_subclass(m)
                    for m in role.instance.map_feature_types}
    resources = map_features - {Plot}

    return any(map_feature_is_creatable(role, Model) for Model in resources)
コード例 #14
0
ファイル: misc.py プロジェクト: jwalgran/otm-core
def get_map_view_context(request, instance):
    resource_classes = [MapFeature.get_subclass(type)
                        for type in instance.map_feature_types]
    context = {
        'fields_for_add_tree': [
            (_('Tree Height'), 'Tree.height')
        ],
        'resource_classes': resource_classes[1:],
    }
    add_map_info_to_context(context, instance)
    return context
コード例 #15
0
def render_map_feature_add(request, instance, type):
    if type in instance.map_feature_types[1:]:
        app = MapFeature.get_subclass(type).__module__.split(".")[0]
        try:
            template = "%s/%s_add.html" % (app, type)
            get_template(template)
        except:
            template = "treemap/resource_add.html"
        return render_to_response(template, {"object_name": to_object_name(type)}, RequestContext(request))
    else:
        raise_non_instance_404(type)
コード例 #16
0
ファイル: perms.py プロジェクト: jjmata/otm-core
def any_resource_is_creatable(role_related_obj):
    role = _get_role_from_related_object(role_related_obj)
    if role is None:
        return False

    map_features = {
        MapFeature.get_subclass(m)
        for m in role.instance.map_feature_types
    }
    resources = map_features - {Plot}

    return any(map_feature_is_creatable(role, Model) for Model in resources)
コード例 #17
0
def get_map_feature_or_404(feature_id, instance, type=None):
    if type:
        MapFeatureSubclass = MapFeature.get_subclass(type)
        InstanceMapFeature = instance.scope_model(MapFeatureSubclass)
        return get_object_or_404(InstanceMapFeature, pk=feature_id)

    else:
        InstanceMapFeature = instance.scope_model(MapFeature)
        feature = get_object_or_404(InstanceMapFeature, pk=feature_id)

        # Return the concrete subtype (e.g. Plot), not a general MapFeature
        return feature.cast_to_subtype()
コード例 #18
0
ファイル: map_feature.py プロジェクト: recklessromeo/otm-core
def get_map_feature_or_404(feature_id, instance, type=None):
    if type:
        MapFeatureSubclass = MapFeature.get_subclass(type)
        InstanceMapFeature = instance.scope_model(MapFeatureSubclass)
        return get_object_or_404(InstanceMapFeature, pk=feature_id)

    else:
        InstanceMapFeature = instance.scope_model(MapFeature)
        feature = get_object_or_404(InstanceMapFeature, pk=feature_id)

        # Return the concrete subtype (e.g. Plot), not a general MapFeature
        return feature.cast_to_subtype()
コード例 #19
0
ファイル: map_feature.py プロジェクト: recklessromeo/otm-core
def render_map_feature_add(request, instance, type):
    if type in instance.map_feature_types[1:]:
        app = MapFeature.get_subclass(type).__module__.split('.')[0]
        try:
            template = '%s/%s_add.html' % (app, type)
            get_template(template)
        except:
            template = 'treemap/resource_add.html'
        return render_to_response(template,
                                  {'object_name': to_object_name(type)},
                                  RequestContext(request))
    else:
        raise Http404('Instance does not support feature type ' + type)
コード例 #20
0
def get_map_feature_or_404(feature_id, instance, type=None):
    if type:
        MapFeatureSubclass = MapFeature.get_subclass(type)
        InstanceMapFeature = instance.scope_model(MapFeatureSubclass)
        return get_object_or_404(InstanceMapFeature, pk=feature_id)

    else:
        InstanceMapFeature = instance.scope_model(MapFeature)
        feature = get_object_or_404(InstanceMapFeature, pk=feature_id)

        # Use feature_type to get the appropriate object, e.g. feature.plot
        feature = getattr(feature, feature.feature_type.lower())
        return feature
コード例 #21
0
ファイル: map_feature.py プロジェクト: atogle/OTM2
def get_map_feature_or_404(feature_id, instance, type=None):
    if type:
        MapFeatureSubclass = MapFeature.get_subclass(type)
        InstanceMapFeature = instance.scope_model(MapFeatureSubclass)
        return get_object_or_404(InstanceMapFeature, pk=feature_id)

    else:
        InstanceMapFeature = instance.scope_model(MapFeature)
        feature = get_object_or_404(InstanceMapFeature, pk=feature_id)

        # Use feature_type to get the appropriate object, e.g. feature.plot
        feature = getattr(feature, feature.feature_type.lower())
        return feature
コード例 #22
0
ファイル: map_feature.py プロジェクト: dkosmidis/BuzzTheTrees
def get_map_feature_or_404(feature_id, instance, type=None):
    if type:
        if type not in instance.map_feature_types:
            raise_non_instance_404(type)
        MapFeatureSubclass = MapFeature.get_subclass(type)
        InstanceMapFeature = instance.scope_model(MapFeatureSubclass)
        return get_object_or_404(InstanceMapFeature, pk=feature_id)

    else:
        InstanceMapFeature = instance.scope_model(MapFeature)
        feature = get_object_or_404(InstanceMapFeature, pk=feature_id)

        # Return the concrete subtype (e.g. Plot), not a general MapFeature
        typed_feature = feature.cast_to_subtype()
        class_name = typed_feature.__class__.__name__
        if class_name not in instance.map_feature_types:
            raise_non_instance_404(class_name)
        return typed_feature
コード例 #23
0
ファイル: map_feature.py プロジェクト: OpenTreeMap/otm-core
def get_map_feature_or_404(feature_id, instance, type=None):
    if type:
        if type not in instance.map_feature_types:
            raise_non_instance_404(type)
        MapFeatureSubclass = MapFeature.get_subclass(type)
        InstanceMapFeature = instance.scope_model(MapFeatureSubclass)
        return get_object_or_404(InstanceMapFeature, pk=feature_id)

    else:
        InstanceMapFeature = instance.scope_model(MapFeature)
        feature = get_object_or_404(InstanceMapFeature, pk=feature_id)

        # Return the concrete subtype (e.g. Plot), not a general MapFeature
        typed_feature = feature.cast_to_subtype()
        class_name = typed_feature.__class__.__name__
        if class_name not in instance.map_feature_types:
            raise_non_instance_404(class_name)
        return typed_feature
コード例 #24
0
ファイル: instance.py プロジェクト: cleberar38/otm-core
    def add_map_feature_types(self, types):
        from treemap.models import MapFeature  # prevent circular import
        from treemap.audit import add_default_permissions

        classes = [MapFeature.get_subclass(type) for type in types]

        dups = set(types) & set(self.map_feature_types)
        if len(dups) > 0:
            raise ValidationError('Map feature types already added: %s' % dups)

        self.map_feature_types = list(self.map_feature_types) + list(types)
        self.save()

        for type, clz in zip(types, classes):
            settings = (getattr(clz, 'udf_settings', {}))
            for udfc_name, udfc_settings in settings.items():
                if udfc_settings.get('defaults'):
                    get_or_create_udf(self, type, udfc_name)

        add_default_permissions(self, models=classes)
コード例 #25
0
    def add_map_feature_types(self, types):
        from treemap.models import MapFeature  # prevent circular import
        from treemap.audit import add_default_permissions

        classes = [MapFeature.get_subclass(type) for type in types]

        dups = set(types) & set(self.map_feature_types)
        if len(dups) > 0:
            raise ValidationError('Map feature types already added: %s' % dups)

        self.map_feature_types = list(self.map_feature_types) + list(types)
        self.save()

        for type, clz in zip(types, classes):
            settings = (getattr(clz, 'udf_settings', {}))
            for udfc_name, udfc_settings in settings.items():
                if udfc_settings.get('defaults'):
                    get_or_create_udf(self, type, udfc_name)

        add_default_permissions(self, models=classes)
コード例 #26
0
ファイル: util.py プロジェクト: ctaylo37/OTM2
def safe_get_model_class(model_string):
    """
    In a couple of cases we want to be able to convert a string
    into a valid django model class. For instance, if we have
    'Plot' we want to get the actual class for 'treemap.models.Plot'
    in a safe way.

    This function returns the class represented by the given model
    if it exists in 'treemap.models'
    """
    from treemap.models import MapFeature

    # All of our models live in 'treemap.models', so
    # we can start with that namespace
    models_module = __import__('treemap.models')

    if hasattr(models_module.models, model_string):
        return getattr(models_module.models, model_string)
    elif MapFeature.has_subclass(model_string):
        return MapFeature.get_subclass(model_string)
    else:
        raise ValidationError(trans('invalid model type: "%s"') % model_string)
コード例 #27
0
ファイル: util.py プロジェクト: atogle/OTM2
def safe_get_model_class(model_string):
    """
    In a couple of cases we want to be able to convert a string
    into a valid django model class. For instance, if we have
    'Plot' we want to get the actual class for 'treemap.models.Plot'
    in a safe way.

    This function returns the class represented by the given model
    if it exists in 'treemap.models'
    """
    from treemap.models import MapFeature

    # All of our models live in 'treemap.models', so
    # we can start with that namespace
    models_module = __import__('treemap.models')

    if hasattr(models_module.models, model_string):
        return getattr(models_module.models, model_string)
    elif MapFeature.has_subclass(model_string):
        return MapFeature.get_subclass(model_string)
    else:
        raise ValidationError(trans('invalid model type'))
コード例 #28
0
ファイル: roles.py プロジェクト: dkosmidis/BuzzTheTrees
def model_perm_models(instance):
    return {Instance, Tree, TreePhoto, MapFeaturePhoto} | {
        MapFeature.get_subclass(m)
        for m in instance.map_feature_types
    }
コード例 #29
0
ファイル: roles.py プロジェクト: OpenTreeMap/otm-core
def model_perm_models(instance):
    return {Instance, Tree, TreePhoto, MapFeaturePhoto} | {
        MapFeature.get_subclass(m) for m in instance.map_feature_types}
コード例 #30
0
ファイル: roles.py プロジェクト: OpenTreeMap/otm-core
def field_perm_models(instance):
    return {Tree} | {MapFeature.get_subclass(m)
                     for m in instance.map_feature_types}
コード例 #31
0
ファイル: roles.py プロジェクト: dkosmidis/BuzzTheTrees
def field_perm_models(instance):
    return {Tree} | {
        MapFeature.get_subclass(m)
        for m in instance.map_feature_types
    }
コード例 #32
0
ファイル: search_fields.py プロジェクト: RickMohr/otm-core
 def get_plural_feature_name(feature_name):
     if feature_name == 'Tree':
         Feature = Tree
     else:
         Feature = MapFeature.get_subclass(feature_name)
     return Feature.terminology(instance)['plural']
コード例 #33
0
ファイル: map_feature.py プロジェクト: dank1/otm-core
def add_map_feature(request, instance, type='Plot'):
    if type not in instance.map_feature_types:
        raise_non_instance_404(type)
    feature = MapFeature.get_subclass(type)(instance=instance)
    return _request_to_update_map_feature(request, feature)
コード例 #34
0
ファイル: map_feature.py プロジェクト: RickMohr/otm-core
def add_map_feature(request, instance, type='Plot'):
    if type not in instance.map_feature_types:
        raise_non_instance_404(type)
    feature = MapFeature.get_subclass(type)(instance=instance)
    return _request_to_update_map_feature(request, feature)
コード例 #35
0
ファイル: instance.py プロジェクト: heath/OTM2
 def make_display_filter(feature_name):
     feature = MapFeature.get_subclass(feature_name)()
     return {
         'label': 'Show %ss' % feature.display_name,
         'in_value': feature_name
     }
コード例 #36
0
ファイル: instance.py プロジェクト: briantanseng/otm-core
 def map_feature_classes(self):
     from treemap.models import MapFeature
     classes = {MapFeature.get_subclass(m) for m in self.map_feature_types}
     return classes
コード例 #37
0
 def get_plural_feature_name(feature_name):
     if feature_name == 'Tree':
         Feature = Tree
     else:
         Feature = MapFeature.get_subclass(feature_name)
     return Feature.terminology(instance)['plural']
コード例 #38
0
 def map_feature_classes(self):
     from treemap.models import MapFeature
     classes = {MapFeature.get_subclass(m)
                for m in self.map_feature_types}
     return classes