当前位置: 首页>>代码示例>>Python>>正文


Python models.MapFeature类代码示例

本文整理汇总了Python中treemap.models.MapFeature的典型用法代码示例。如果您正苦于以下问题:Python MapFeature类的具体用法?Python MapFeature怎么用?Python MapFeature使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


在下文中一共展示了MapFeature类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: make_display_filter

 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}
开发者ID:recklessromeo,项目名称:otm-core,代码行数:7,代码来源:instance.py

示例2: add_map_feature_types

    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)
开发者ID:RickMohr,项目名称:otm-core,代码行数:30,代码来源:instance.py

示例3: render_map_feature_add

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)
开发者ID:jwalgran,项目名称:otm-core,代码行数:7,代码来源:map_feature.py

示例4: make_display_filter

 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
     }
开发者ID:nvh3010,项目名称:otm-core,代码行数:7,代码来源:instance.py

示例5: get_map_view_context

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:]
    }
开发者ID:summer-of-open-source,项目名称:OTM2,代码行数:9,代码来源:misc.py

示例6: _get_map_view_context

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:]
    }
开发者ID:heath,项目名称:OTM2,代码行数:10,代码来源:views.py

示例7: make_display_filter

 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
     }
开发者ID:cgarrard,项目名称:OTM2,代码行数:10,代码来源:instance.py

示例8: any_resource_is_creatable

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)
开发者ID:nvh3010,项目名称:otm-core,代码行数:10,代码来源:perms.py

示例9: render_map_feature_add

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)
开发者ID:OpenTreeMap,项目名称:otm-core,代码行数:10,代码来源:map_feature.py

示例10: render_map_feature_add

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)
开发者ID:RobinIsTheBird,项目名称:otm-core,代码行数:11,代码来源:map_feature.py

示例11: get_map_view_context

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
开发者ID:jwalgran,项目名称:otm-core,代码行数:11,代码来源:misc.py

示例12: get_map_feature_or_404

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()
开发者ID:recklessromeo,项目名称:otm-core,代码行数:12,代码来源:map_feature.py

示例13: render_map_feature_add

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)
开发者ID:recklessromeo,项目名称:otm-core,代码行数:13,代码来源:map_feature.py

示例14: get_map_feature_or_404

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
开发者ID:atogle,项目名称:OTM2,代码行数:13,代码来源:map_feature.py

示例15: safe_get_model_class

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'))
开发者ID:atogle,项目名称:OTM2,代码行数:22,代码来源:util.py


注:本文中的treemap.models.MapFeature类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。