本文整理汇总了Python中treemap.models.Tree.visible_collection_udfs_audit_names方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.visible_collection_udfs_audit_names方法的具体用法?Python Tree.visible_collection_udfs_audit_names怎么用?Python Tree.visible_collection_udfs_audit_names使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Tree
的用法示例。
在下文中一共展示了Tree.visible_collection_udfs_audit_names方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: _plot_audits
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import visible_collection_udfs_audit_names [as 别名]
def _plot_audits(user, instance, plot):
fake_tree = Tree(instance=instance)
tree_visible_fields = fake_tree.visible_fields(user)
# Get a history of trees that were on this plot
tree_history = plot.get_tree_history()
tree_filter = Q(model='Tree',
field__in=tree_visible_fields,
model_id__in=tree_history)
tree_delete_filter = Q(model='Tree',
action=Audit.Type.Delete,
model_id__in=tree_history)
tree_collection_udfs_audit_names =\
fake_tree.visible_collection_udfs_audit_names(user)
tree_collection_udfs_filter = Q(
model__in=tree_collection_udfs_audit_names,
model_id__in=Tree.static_collection_udfs_audit_ids(
(instance,), tree_history, tree_collection_udfs_audit_names))
filters = [tree_filter, tree_delete_filter]
cudf_filters = [tree_collection_udfs_filter]
audits = _map_feature_audits(user, instance, plot, filters, cudf_filters)
return audits
示例2: _plot_audits
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import visible_collection_udfs_audit_names [as 别名]
def _plot_audits(user, instance, plot):
readable_plot_fields = plot.visible_fields(user)
plot_filter = Q(model='Plot', model_id=plot.pk,
field__in=readable_plot_fields)
plot_collection_udfs_filter = Q(
model__in=plot.visible_collection_udfs_audit_names(user),
model_id__in=plot.collection_udfs_audit_ids())
fake_tree = Tree(instance=instance)
tree_visible_fields = fake_tree.visible_fields(user)
# Get a history of trees that were on this plot
tree_history = plot.get_tree_history()
tree_filter = Q(model='Tree',
field__in=tree_visible_fields,
model_id__in=tree_history)
tree_delete_filter = Q(model='Tree',
action=Audit.Type.Delete,
model_id__in=tree_history)
tree_collection_udfs_audit_names =\
fake_tree.visible_collection_udfs_audit_names(user)
tree_collection_udfs_filter = Q(
model__in=tree_collection_udfs_audit_names,
model_id__in=Tree.static_collection_udfs_audit_ids(
(instance,), tree_history, tree_collection_udfs_audit_names))
# Seems to be much faster to do three smaller
# queries here instead of ORing them together
# (about a 50% inprovement!)
# TODO: Verify this is still the case now that we are also getting
# collection udf audits
iaudit = Audit.objects.filter(instance=instance)
audits = []
for afilter in [tree_filter, tree_delete_filter, plot_filter]:
audits += list(iaudit.filter(afilter).order_by('-updated')[:5])
# UDF collection audits have some fields which aren't very useful to show
udf_collection_exclude_filter = Q(
field__in=['model_id', 'field_definition'])
for afilter in [plot_collection_udfs_filter, tree_collection_udfs_filter]:
audits += list(iaudit.filter(afilter)
.exclude(udf_collection_exclude_filter)
.order_by('-updated')[:5])
audits = sorted(audits, key=lambda audit: audit.updated, reverse=True)[:5]
return audits
示例3: get_audits
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import visible_collection_udfs_audit_names [as 别名]
def get_audits(logged_in_user, instance, query_vars, user, models,
model_id, page=0, page_size=20, exclude_pending=True,
should_count=False):
start_pos = page * page_size
end_pos = start_pos + page_size
model_filter = Q(model__in=models)
# We only want to show the TreePhoto's image, not other fields
# and we want to do it automatically if 'Tree' was specified as
# a model
# FIXME: This should also show MapFeaturePhoto if any map feature
# models are in the filter
if 'Tree' in models:
model_filter = model_filter | Q(model='TreePhoto', field='image')
if instance:
if instance.is_accessible_by(logged_in_user):
instance_filter = Q(pk=instance.pk)
else:
# Force no results
return {'audits': [],
'next_page': None,
'prev_page': None}
# If we didn't specify an instance we only want to
# show audits where the user has permission
else:
instance_filter = _user_accessible_instance_filter(logged_in_user)
instances = Instance.objects.filter(instance_filter)
# We need a filter per-instance in order to only show UDF collection
# visible to the user
for inst in Instance.objects.filter(instance_filter):
# Only add UDF collections if their parent models are being shown
for model in models:
if model == 'Tree':
fake_model = Tree(instance=inst)
elif model == 'Plot':
fake_model = Plot(instance=inst)
else:
continue
model_collection_udfs_audit_names =\
fake_model.visible_collection_udfs_audit_names(logged_in_user)
# Don't show the fields that every collection UDF has, because they
# are not very interesting
model_filter = model_filter |\
(Q(model__in=model_collection_udfs_audit_names) &
~Q(field__in=('id', 'model_id', 'field_definition')))
audits = Audit.objects.filter(model_filter)\
.filter(instance__in=instances)\
.order_by('-created', 'id')
if user:
audits = audits.filter(user=user)
if model_id:
audits = audits.filter(model_id=model_id)
if exclude_pending:
audits = audits.exclude(requires_auth=True, ref__isnull=True)
total_count = audits.count() if should_count else 0
audits = audits[start_pos:end_pos]
query_vars = {k: v for (k, v) in query_vars.iteritems() if k != 'page'}
next_page = None
prev_page = None
if len(audits) == page_size:
query_vars['page'] = page + 1
next_page = "?" + urllib.urlencode(query_vars)
if page > 0:
query_vars['page'] = page - 1
prev_page = "?" + urllib.urlencode(query_vars)
return {'audits': audits,
'total_count': total_count,
'next_page': next_page,
'prev_page': prev_page}