本文整理汇总了Python中treemap.models.Tree.add_photo方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.add_photo方法的具体用法?Python Tree.add_photo怎么用?Python Tree.add_photo使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Tree
的用法示例。
在下文中一共展示了Tree.add_photo方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_treephoto_overrides_tree_and_plot
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import add_photo [as 别名]
def test_treephoto_overrides_tree_and_plot(self):
tree = Tree(diameter=10, plot=self.plot, instance=self.instance)
tree.save_with_user(self.user)
tree.add_photo(self.image, self.other)
self.clear_and_set_and_reload()
self.assertEqual(self.plot.updated_by_id, self.other.pk)
示例2: add_tree_photo_helper
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import add_photo [as 别名]
def add_tree_photo_helper(request, instance, feature_id, tree_id=None):
plot = get_map_feature_or_404(feature_id, instance, 'Plot')
tree_ids = [t.pk for t in plot.tree_set.all()]
if tree_id and int(tree_id) in tree_ids:
tree = Tree.objects.get(pk=tree_id)
elif tree_id is None:
# See if a tree already exists on this plot
tree = plot.current_tree()
if tree is None:
# A tree doesn't exist, create a new tree create a
# new tree, and attach it to this plot
tree = Tree(plot=plot, instance=instance)
# TODO: it is possible that a user has the ability to
# 'create tree photos' but not trees. In this case we
# raise an authorization exception here.
# It is, however, possible to have both a pending
# tree and a pending tree photo
# This will be added later, when auth/admin work
# correctly with this system
tree.save_with_user(request.user)
else:
# Tree id is invalid or not in this plot
raise Http404('Tree id %s not found on plot %s'
% (tree_id, feature_id))
#TODO: Auth Error
data = get_image_from_request(request)
treephoto = tree.add_photo(data, request.user)
return treephoto, tree
示例3: test_treephoto_overrides_tree_and_plot_updated
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import add_photo [as 别名]
def test_treephoto_overrides_tree_and_plot_updated(self):
tree = Tree(diameter=10, plot=self.plot, instance=self.instance)
tree.save_with_user(self.user)
tree.add_photo(self.image, self.user)
tree_audit = self.max_audit_for_model_type('Tree')
treephoto_audit = self.max_audit_for_model_type(['MapFeaturePhoto',
'TreePhoto'])
plot_audit = self.max_audit_for_model_type('Plot')
# Backdate the audits so photo it is definitely the newsest
plot_audit.created = treephoto_audit.created - timedelta(days=2)
plot_audit.save()
tree_audit.created = treephoto_audit.created - timedelta(days=1)
tree_audit.save()
self.clear_and_set_and_reload()
self.assertEqual(self.plot.updated_at, treephoto_audit.created)
示例4: add_tree_photo
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import add_photo [as 别名]
def add_tree_photo(request, instance, plot_id, tree_id=None):
plot = get_object_or_404(Plot, pk=plot_id, instance=instance)
tree_ids = [t.pk for t in plot.tree_set.all()]
if tree_id and int(tree_id) in tree_ids:
tree = Tree.objects.get(pk=tree_id)
elif tree_id is None:
# See if a tree already exists on this plot
tree = plot.current_tree()
if tree is None:
# A tree doesn't exist, create a new tree create a
# new tree, and attach it to this plot
tree = Tree(plot=plot, instance=instance)
# TODO: it is possible that a user has the ability to
# 'create tree photos' but not trees. In this case we
# raise an authorization exception here.
# It is, however, possible to have both a pending
# tree and a pending tree photo
# This will be added later, when auth/admin work
# correctly with this system
tree.save_with_user(request.user)
else:
# Tree id is invalid or not in this plot
raise Http404("Tree id %s not found on plot %s" % (tree_id, plot_id))
# TODO: Validation Error
# TODO: Auth Error
if "file" in request.FILES:
# TODO: Check size before reading
data = request.FILES["file"].file
else:
data = request.body
photo = tree.add_photo(data, request.user)
return photo