本文整理汇总了Python中treemap.models.Tree.save_with_user方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.save_with_user方法的具体用法?Python Tree.save_with_user怎么用?Python Tree.save_with_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Tree
的用法示例。
在下文中一共展示了Tree.save_with_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def handle(self, *args, **options):
""" Create some seed data """
instance, user = self.setup_env(*args, **options)
species_qs = instance.scope_model(Species)
n = options['n']
self.stdout.write("Will create %s plots" % n)
get_prob = lambda option: float(min(100, max(0, option))) / 100.0
tree_prob = get_prob(options['ptree'])
species_prob = get_prob(options['pspecies'])
diameter_prob = get_prob(options['pdiameter'])
max_radius = options['radius']
center_x = instance.center.x
center_y = instance.center.y
import_event = ImportEvent(imported_by=user)
import_event.save()
ct = 0
cp = 0
for i in xrange(0, n):
mktree = random.random() < tree_prob
radius = random.gauss(0.0, max_radius)
theta = random.random() * 2.0 * math.pi
x = math.cos(theta) * radius + center_x
y = math.sin(theta) * radius + center_y
plot = Plot(instance=instance,
geom=Point(x, y),
import_event=import_event)
plot.save_with_user(user)
cp += 1
if mktree:
add_species = random.random() < species_prob
if add_species:
species = random.choice(species_qs)
else:
species = None
add_diameter = random.random() < diameter_prob
if add_diameter:
diameter = 2 + random.random() * 18
else:
diameter = None
tree = Tree(plot=plot,
import_event=import_event,
species=species,
diameter=diameter,
instance=instance)
tree.save_with_user(user)
ct += 1
self.stdout.write("Created %s trees and %s plots" % (ct, cp))
示例2: setUp
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def setUp(self):
super(ExportTreeTaskTest, self).setUp()
set_write_permissions(self.instance, self.user,
'Plot', ['udf:Test choice'])
set_write_permissions(self.instance, self.user,
'Tree', ['udf:Test int'])
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type='Plot',
datatype=json.dumps({'type': 'choice',
'choices': ['a', 'b', 'c']}),
iscollection=False,
name='Test choice')
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type='Tree',
datatype=json.dumps({'type': 'int'}),
iscollection=False,
name='Test int')
p = Plot(geom=self.instance.center, instance=self.instance,
address_street="123 Main Street")
p.udfs['Test choice'] = 'a'
p.save_with_user(self.user)
t = Tree(plot=p, instance=self.instance, diameter=2)
t.udfs['Test int'] = 4
t.save_with_user(self.user)
示例3: WritableTest
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
class WritableTest(PermissionsTestCase):
def test_plot_is_writable_if_can_create_tree(self):
self.commander_user = make_commander_user(self.instance)
self.commander_role = \
self.commander_user.get_instance_user(self.instance).role
self.tree_only_user = make_user(self.instance)
self.tree_only_role = self.instance.default_role
content_type = ContentType.objects.get_for_model(Tree)
add_tree_perm = Permission.objects.get(content_type=content_type,
codename='add_tree')
self.tree_only_role.instance_permissions.add(add_tree_perm)
self.tree_only_role.save()
self.p = Point(-8515941.0, 4953519.0)
self.plot = Plot(instance=self.instance, width=12, geom=self.p)
self.plot.save_with_user(self.commander_user)
plot2 = Plot(instance=self.instance, width=12, geom=self.p)
self.assertRaises(AuthorizeException,
plot2.save_with_user,
self.tree_only_user)
self.tree = Tree(instance=self.instance, plot=self.plot)
self.tree.save_with_user(self.tree_only_user)
self.assertTrue(self.tree.user_can_create(self.tree_only_user))
# The plot should be writable if the user can create a tree
self.assertTrue(perms.map_feature_is_writable(
self.tree_only_role,
self.plot))
示例4: add_tree_photo_helper
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [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
示例5: test_within_radius_integration
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def test_within_radius_integration(self):
test_point = Point(0, 0)
near_point = Point(1, 1)
far_point = Point(250, 250)
near_plot = Plot(geom=near_point, instance=self.instance)
near_plot.save_with_user(self.commander)
near_tree = Tree(plot=near_plot, instance=self.instance)
near_tree.save_with_user(self.commander)
# just to make sure that the geospatial
# query actually filters by distance
far_plot = Plot(geom=far_point, instance=self.instance)
far_plot.save_with_user(self.commander)
far_tree = Tree(plot=far_plot, instance=self.instance)
far_tree.save_with_user(self.commander)
radius_filter = json.dumps(
{'plot.geom':
{
'WITHIN_RADIUS': {
'POINT': {'x': test_point.x, 'y': test_point.y},
'RADIUS': 10
}
}})
plots = search.Filter(radius_filter, '', self.instance)\
.get_objects(Plot)
ids = {p.pk for p in plots}
self.assertEqual(ids, {near_plot.pk})
示例6: UserCanDeleteTestCase
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
class UserCanDeleteTestCase(OTMTestCase):
def setUp(self):
instance = make_instance()
self.creator_user = make_officer_user(instance)
self.admin_user = make_admin_user(instance)
self.other_user = make_officer_user(instance, username='other')
self.plot = Plot(geom=instance.center, instance=instance)
self.plot.save_with_user(self.creator_user)
self.tree = Tree(plot=self.plot, instance=instance)
self.tree.save_with_user(self.creator_user)
self.rainBarrel = RainBarrel(geom=instance.center, instance=instance,
capacity=5)
self.rainBarrel.save_with_user(self.creator_user)
def assert_can_delete(self, user, deletable, should_be_able_to_delete):
can = deletable.user_can_delete(user)
self.assertEqual(can, should_be_able_to_delete)
def test_user_can_delete(self):
self.assert_can_delete(self.creator_user, self.plot, True)
self.assert_can_delete(self.admin_user, self.plot, True)
self.assert_can_delete(self.other_user, self.plot, False)
self.assert_can_delete(self.creator_user, self.rainBarrel, True)
self.assert_can_delete(self.admin_user, self.rainBarrel, True)
self.assert_can_delete(self.other_user, self.rainBarrel, False)
self.assert_can_delete(self.creator_user, self.tree, True)
self.assert_can_delete(self.admin_user, self.tree, True)
self.assert_can_delete(self.other_user, self.tree, False)
示例7: setUp
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def setUp(self):
super(ExportTreeTaskTest, self).setUp()
set_write_permissions(self.instance, self.user, "Plot", ["udf:Test choice"])
set_write_permissions(self.instance, self.user, "Tree", ["udf:Test int"])
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type="Plot",
datatype=json.dumps({"type": "choice", "choices": ["a", "b", "c"]}),
iscollection=False,
name="Test choice",
)
UserDefinedFieldDefinition.objects.create(
instance=self.instance,
model_type="Tree",
datatype=json.dumps({"type": "int"}),
iscollection=False,
name="Test int",
)
p = Plot(geom=self.instance.center, instance=self.instance, address_street="123 Main Street")
p.udfs["Test choice"] = "a"
p.save_with_user(self.user)
t = Tree(plot=p, instance=self.instance, diameter=2)
t.udfs["Test int"] = 4
t.save_with_user(self.user)
示例8: test_treephoto_overrides_tree_and_plot
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [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)
示例9: test_within_radius_integration
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def test_within_radius_integration(self):
test_point = Point(-7615443.0, 5953520.0)
near_point = Point(-7615444.0, 5953521.0)
far_point = Point(-9615444.0, 8953521.0)
near_plot = Plot(geom=near_point, instance=self.instance)
near_plot.save_with_user(self.commander)
near_tree = Tree(plot=near_plot, instance=self.instance)
near_tree.save_with_user(self.commander)
# just to make sure that the geospatial
# query actually filters by distance
far_plot = Plot(geom=far_point, instance=self.instance)
far_plot.save_with_user(self.commander)
far_tree = Tree(plot=far_plot, instance=self.instance)
far_tree.save_with_user(self.commander)
radius_filter = json.dumps(
{'plot.geom':
{
'WITHIN_RADIUS': {
'POINT': {'x': test_point.x, 'y': test_point.y},
'RADIUS': 10
}
}})
ids = {p.pk
for p
in _execute_filter(
self.instance, radius_filter)}
self.assertEqual(ids, {near_plot.pk})
示例10: test_treephoto_hash_to_model
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def test_treephoto_hash_to_model(self):
plot = Plot(geom=Point(0, 0), instance=self.instance)
plot.save_with_user(self.commander)
tree = Tree(plot=plot, instance=self.instance)
tree.save_with_user(self.commander)
ipath = self.resource_path('tree1.gif')
tp_dict = json.loads(self.photo_blob % ipath)
self.assertEqual(TreePhoto.objects.count(), 0)
save_treephoto_blank = partial(save_treephoto, MIGRATION_RULES, '')
hashes_to_saved_objects(
MIGRATION_RULES,
"treephoto", [tp_dict],
{'tree': {1: tree.pk},
'user': {1: self.commander.pk}},
save_treephoto_blank,
self.instance)
self.assertEqual(TreePhoto.objects.count(), 1)
photo = TreePhoto.objects.all()[0]
self.assertIsNotNone(photo.image)
self.assertIsNotNone(photo.thumbnail)
示例11: test_record_is_created_when_nullables_are_still_pending
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def test_record_is_created_when_nullables_are_still_pending(self):
new_plot = Plot(geom=self.p1, instance=self.instance)
new_plot.save_with_user(self.pending_user)
new_tree = Tree(plot=new_plot, instance=self.instance,
diameter=10, height=10, readonly=False)
new_tree.save_with_user(self.pending_user)
approve_or_reject_audits_and_apply(
new_plot.audits(),
self.commander_user, True)
insert_audit = Audit.objects.filter(model='Tree')\
.get(field='id')
field_audits = Audit.objects.filter(model='Tree')\
.filter(field__in=['readonly', 'diameter',
'plot'])
for audit in field_audits:
approve_or_reject_audit_and_apply(
audit, self.commander_user, approved=True)
approve_or_reject_audit_and_apply(insert_audit,
self.commander_user, True)
real_tree = Tree.objects.get(pk=new_tree.pk)
self.assertEqual(real_tree.plot_id, new_plot.pk)
self.assertEqual(real_tree.diameter, 10)
self.assertEqual(real_tree.height, None)
self.assertNotEqual(real_tree.readonly, True)
示例12: test_delete_tree
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def test_delete_tree(self):
plot = Plot(instance=self.instance,
geom=Point(0, 0))
plot.save_with_user(self.user)
tree = Tree(instance=self.instance,
plot=plot)
tree.save_with_user(self.user)
self.assertEqual(Plot.objects.count(), 1)
self.assertEqual(Tree.objects.count(), 1)
self._login_workflow()
self._go_to_plot_detail(plot.pk)
self.select_buttons()
self.assertCantClickDeleteOrCancel()
self.assertEqual(Plot.objects.count(), 1)
self.assertEqual(Tree.objects.count(), 1)
self.delete_begin.click()
self.delete_cancel.click()
self.assertCantClickDeleteOrCancel()
self.assertEqual(Plot.objects.count(), 1)
self.assertEqual(Tree.objects.count(), 1)
self.select_buttons()
self.delete_begin.click()
self.delete_confirm.click()
sleep(DATABASE_COMMIT_DELAY)
self.assertEqual(Plot.objects.count(), 1)
self.assertEqual(Tree.objects.count(), 0)
示例13: test_reputations_increase_for_direct_writes
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def test_reputations_increase_for_direct_writes(self):
self.assertEqual(self.privileged_user.get_reputation(self.instance), 0)
t = Tree(plot=self.plot, instance=self.instance,
readonly=True)
t.save_with_user(self.privileged_user)
user = User.objects.get(pk=self.privileged_user.id)
reputation = user.get_reputation(self.instance)
self.assertGreater(reputation, 0)
示例14: test_delete_tree_sets_updated
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def test_delete_tree_sets_updated(self):
tree = Tree(diameter=10, plot=self.plot, instance=self.instance)
tree.save_with_user(self.user)
self.plot = Plot.objects.get(pk=self.plot.pk)
self.inital_updated = self.plot.updated_at
tree.delete_with_user(self.user)
self.assertGreater(self.plot.updated_at, self.initial_updated)
示例15: setUp
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import save_with_user [as 别名]
def setUp(self):
super(ExportTreeTaskTest, self).setUp()
p = Plot(geom=Point(0, 0), instance=self.instance, address_street="123 Main Street")
p.save_with_user(self.user)
t = Tree(plot=p, instance=self.instance, diameter=2)
t.save_with_user(self.user)