本文整理汇总了Python中treemap.models.MapFeature.get_subclass方法的典型用法代码示例。如果您正苦于以下问题:Python MapFeature.get_subclass方法的具体用法?Python MapFeature.get_subclass怎么用?Python MapFeature.get_subclass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.MapFeature
的用法示例。
在下文中一共展示了MapFeature.get_subclass方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: make_display_filter
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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: make_display_filter
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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
}
示例3: render_map_feature_add
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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)
示例4: add_map_feature_types
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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: get_map_view_context
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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:]
}
示例6: make_display_filter
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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: _get_map_view_context
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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:]
}
示例8: render_map_feature_add
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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)
示例9: any_resource_is_creatable
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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)
示例10: render_map_feature_add
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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)
示例11: get_map_view_context
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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
示例12: get_map_feature_or_404
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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()
示例13: get_map_feature_or_404
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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
示例14: render_map_feature_add
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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)
示例15: get_map_feature_or_404
# 需要导入模块: from treemap.models import MapFeature [as 别名]
# 或者: from treemap.models.MapFeature import get_subclass [as 别名]
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