本文整理汇总了Python中treemap.models.Plot.save_with_user方法的典型用法代码示例。如果您正苦于以下问题:Python Plot.save_with_user方法的具体用法?Python Plot.save_with_user怎么用?Python Plot.save_with_user使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Plot
的用法示例。
在下文中一共展示了Plot.save_with_user方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: handle
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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: test_treephoto_hash_to_model
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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)
示例3: test_reject_insert_rejects_updates
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save_with_user [as 别名]
def test_reject_insert_rejects_updates(self):
new_plot = Plot(geom=self.p1, instance=self.instance)
new_plot.save_with_user(self.pending_user)
insert_audit = Audit.objects.filter(model='Plot')\
.get(field='id')
field_audits = Audit.objects.filter(model='Plot')\
.exclude(field='id')
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, False)
# need to refresh the field_audits collection from the db
# because references are broken
# why doesn't this work? why are there 5 values in field_audits_ids?
# field_audit_ids = field_audits.values_list('id', flat=True)
field_audit_ids = [field_audit.id for field_audit in field_audits]
field_audits = Audit.objects.filter(pk__in=field_audit_ids)
for field_audit in field_audits:
attached_review_audit = Audit.objects.get(pk=field_audit.ref.pk)
self.assertEqual(attached_review_audit.action,
Audit.Type.PendingReject)
self.assertNotEqual(None,
Audit.objects.get(
model=field_audit.model,
field=field_audit.field,
model_id=field_audit.model_id,
action=Audit.Type.PendingApprove))
示例4: test_delete_tree
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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)
示例5: WritableTest
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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))
示例6: test_within_radius_integration
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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})
示例7: test_within_radius_integration
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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})
示例8: test_tree_add_cancel
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save_with_user [as 别名]
def test_tree_add_cancel(self):
plot = Plot(instance=self.instance,
geom=Point(0, 0))
plot.save_with_user(self.user)
self._login_workflow()
self._go_to_plot_detail_edit(plot.pk)
add_tree_button = self.driver.find_element_by_id(
'add-tree')
add_tree_button.click()
cancel_edit_button = self.driver.find_element_by_id(
'cancel-edit-plot')
cancel_edit_button.click()
tree_details_div = self.driver.find_element_by_id(
'tree-details')
with self.assertRaises(ElementNotVisibleException):
tree_details_div.click()
self.assertFalse(Tree.objects.filter(plot=plot).exists())
示例9: UserCanDeleteTestCase
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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)
示例10: test_record_is_created_when_nullables_are_still_pending
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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)
示例11: test_plot_history_shows_all_trees
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save_with_user [as 别名]
def test_plot_history_shows_all_trees(self):
p = Plot(instance=self.instance, geom=self.p)
p.save_with_user(self.user)
self.assertEqual(len(p.get_tree_history()), 0)
t = Tree(plot=p, instance=self.instance)
t.save_with_user(self.user)
tpk = t.pk
self.assertEqual(list(p.get_tree_history()), [tpk])
t.delete_with_user(self.user)
self.assertEqual(list(p.get_tree_history()), [tpk])
t2 = Tree(plot=p, instance=self.instance)
t2.save_with_user(self.user)
self.assertEqual(list(p.get_tree_history()), [t2.pk, tpk])
t3 = Tree(plot=p, instance=self.instance)
t3.save_with_user(self.user)
self.assertEqual(list(p.get_tree_history()), [t3.pk, t2.pk, tpk])
示例12: setUp
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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)
示例13: UpdateTestCase
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save_with_user [as 别名]
class UpdateTestCase(LocalMediaTestCase):
def setUp(self):
super(UpdateTestCase, self).setUp()
self.image = self.load_resource('tree1.gif')
self.test_start = timezone.now()
self.point = Point(-8515941.0, 4953519.0)
self.instance = make_instance(point=self.point)
self.user = make_commander_user(self.instance)
self.plot = Plot(geom=self.point, instance=self.instance)
self.plot.save_with_user(self.user)
def max_audit_for_model_type(self, models):
if isinstance(models, basestring):
models = [models]
audits = Audit.objects.filter(model__in=models)\
.order_by('-created')
if audits:
return audits[0]
def clear_updated_at(self):
# to_timestamp(0) is the unix epoch 1970-1-1 00:00
execute_sql(
"UPDATE treemap_mapfeature SET updated_at = to_timestamp(0);")
def clear_and_set_and_reload(self):
self.clear_updated_at()
set_map_feature_updated_at()
self.plot.refresh_from_db()
示例14: setUp
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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)
示例15: setUp
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot 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)