本文整理汇总了Python中treemap.models.Plot.save方法的典型用法代码示例。如果您正苦于以下问题:Python Plot.save方法的具体用法?Python Plot.save怎么用?Python Plot.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Plot
的用法示例。
在下文中一共展示了Plot.save方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: mkPlot
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save [as 别名]
def mkPlot(u, geom=Point(50, 50)):
p = Plot(
geometry=geom,
last_updated_by=u,
import_event=ImportEvent.objects.all()[0],
present=True,
data_owner=u)
p.save()
return p
示例2: setUp
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save [as 别名]
def setUp(self):
######
# Request/Render mock
######
def local_render_to_response(*args, **kwargs):
from django.template import loader, RequestContext
from django.http import HttpResponse
httpresponse_kwargs = {'mimetype': kwargs.pop('mimetype', None)}
hr = HttpResponse(
loader.render_to_string(*args, **kwargs), **httpresponse_kwargs)
if hasattr(args[1], 'dicts'):
hr.request_context = args[1].dicts
return hr
django.shortcuts.render_to_response = local_render_to_response
######
# Content types
######
r1 = ReputationAction(name="edit verified", description="blah")
r2 = ReputationAction(name="edit tree", description="blah")
r3 = ReputationAction(name="Administrative Action", description="blah")
r4 = ReputationAction(name="add tree", description="blah")
r5 = ReputationAction(name="edit plot", description="blah")
r6 = ReputationAction(name="add plot", description="blah")
r7 = ReputationAction(name="add stewardship", description="blah")
r8 = ReputationAction(name="remove stewardship", description="blah")
self.ra = [r1,r2,r3,r4,r5,r6,r7,r8]
for r in self.ra:
r.save()
######
# Set up benefit values
######
bv = BenefitValues(co2=0.02, pm10=9.41, area="InlandValleys",
electricity=0.1166,voc=4.69,ozone=5.0032,natural_gas=1.25278,
nox=12.79,stormwater=0.0078,sox=3.72,bvoc=4.96)
bv.save()
self.bv = bv
dbh = "[1.0, 2.0, 3.0]"
rsrc = Resource(meta_species="BDM_OTHER", electricity_dbh=dbh, co2_avoided_dbh=dbh,
aq_pm10_dep_dbh=dbh, region="Sim City", aq_voc_avoided_dbh=dbh,
aq_pm10_avoided_dbh=dbh, aq_ozone_dep_dbh=dbh, aq_nox_avoided_dbh=dbh,
co2_storage_dbh=dbh,aq_sox_avoided_dbh=dbh, aq_sox_dep_dbh=dbh,
bvoc_dbh=dbh, co2_sequestered_dbh=dbh, aq_nox_dep_dbh=dbh,
hydro_interception_dbh=dbh, natural_gas_dbh=dbh)
rsrc.save()
self.rsrc = rsrc
######
# Users
######
u = User.objects.filter(username="jim")
if u:
u = u[0]
else:
u = User.objects.create_user("jim","[email protected]","jim")
u.is_staff = True
u.is_superuser = True
u.save()
up = UserProfile(user=u)
u.reputation = Reputation(user=u)
u.reputation.save()
self.u = u
#######
# Setup geometries -> Two stacked 100x100 squares
#######
n1geom = MultiPolygon(Polygon(((0,0),(100,0),(100,100),(0,100),(0,0))))
n2geom = MultiPolygon(Polygon(((0,101),(101,101),(101,200),(0,200),(0,101))))
n1 = Neighborhood(name="n1", region_id=2, city="c1", state="PA", county="PAC", geometry=n1geom)
n2 = Neighborhood(name="n2", region_id=2, city="c2", state="NY", county="NYC", geometry=n2geom)
n1.save()
n2.save()
z1geom = MultiPolygon(Polygon(((0,0),(100,0),(100,100),(0,100),(0,0))))
z2geom = MultiPolygon(Polygon(((0,100),(100,100),(100,200),(0,200),(0,100))))
z1 = ZipCode(zip="19107",geometry=z1geom)
z2 = ZipCode(zip="10001",geometry=z2geom)
z1.save()
z2.save()
exgeom1 = MultiPolygon(Polygon(((0,0),(25,0),(25,25),(0,25),(0,0))))
ex1 = ExclusionMask(geometry=exgeom1, type="building")
#.........这里部分代码省略.........
示例3: test_result_map
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save [as 别名]
def test_result_map(self):
##################################################################
# Test main result map page
# Note -> This page does not depend at all on the request
#
p1 = Plot(geometry=Point(50,50), last_updated_by=self.u, import_event=self.ie,present=True, width=100, length=100, data_owner=self.u)
p2 = Plot(geometry=Point(60,50), last_updated_by=self.u, import_event=self.ie,present=True, width=90, length=110, data_owner=self.u)
p1.save()
p2.save()
# For max/min plot size
p3 = Plot(geometry=Point(50,50), last_updated_by=self.u, import_event=self.ie,present=True, width=80, length=120, data_owner=self.u)
p4 = Plot(geometry=Point(60,50), last_updated_by=self.u, import_event=self.ie,present=True, width=70, length=130, data_owner=self.u)
p5 = Plot(geometry=Point(60,50), last_updated_by=self.u, import_event=self.ie,present=True, width=60, length=70, data_owner=self.u)
p3.save()
p4.save()
p5.save()
t3 = Tree(plot=p3, species=None, last_updated_by=self.u, import_event=self.ie,present=True)
t3.save()
t4 = Tree(plot=p4, species=None, last_updated_by=self.u, import_event=self.ie,present=True)
t4.save()
t5 = Tree(plot=p5, species=None, last_updated_by=self.u, import_event=self.ie,present=True)
t5.save()
t1 = Tree(plot=p1, species=None, last_updated_by=self.u, import_event=self.ie)
t1.present = True
current_year = datetime.now().year
t1.date_planted = date(1999,9,9)
t2 = Tree(plot=p2, species=None, last_updated_by=self.u, import_event=self.ie)
t1.present = True
t1.save()
t2.save()
set_auto_now(t1, "last_updated", False)
t1.last_updated = date(1999,9,9)
t1.save()
response = self.client.get("/map/")
req = response.context
set_auto_now(t1, "last_updated", True)
# t1 and t2 should not be in the latest trees/plots because it excludes superuser edits
exp = set([])
got = set([t.pk for t in req['latest_trees']])
self.assertTrue(exp <= got)
got = set([t.pk for t in req['latest_plots']])
self.assertTrue(exp <= got)
# Check to verify platting dates
self.assertEquals(int(req['min_year']), 1999)
self.assertEquals(int(req['current_year']), current_year)
# Correct min/max plot sizes
self.assertEqual(int(req['min_plot']), 60)
self.assertEqual(int(req['max_plot']), 130)
min_updated = mktime(t1.last_updated.timetuple())
max_updated = mktime(t2.last_updated.timetuple())
self.assertEqual(req['min_updated'], min_updated)
self.assertEqual(req['max_updated'], max_updated)
示例4: commit_row
# 需要导入模块: from treemap.models import Plot [as 别名]
# 或者: from treemap.models.Plot import save [as 别名]
def commit_row(self):
# If this row was already commit... abort
if self.plot:
self.status = TreeImportRow.SUCCESS
self.save()
# First validate
if not self.validate_row():
return False
# Get our data
data = self.cleaned
self.convert_units(data, {
fields.trees.PLOT_WIDTH:
self.import_event.plot_width_conversion_factor,
fields.trees.PLOT_LENGTH:
self.import_event.plot_length_conversion_factor,
fields.trees.DIAMETER:
self.import_event.diameter_conversion_factor,
fields.trees.TREE_HEIGHT:
self.import_event.tree_height_conversion_factor,
fields.trees.CANOPY_HEIGHT:
self.import_event.canopy_height_conversion_factor
})
# We need the import event from treemap.models
# the names of things are a bit odd here but
# self.import_event ->
# TreeImportEvent (importer) ->
# ImportEvent (treemap)
#
base_treemap_import_event = self.import_event.base_import_event
plot_edited = False
tree_edited = False
# Initially grab plot from row if it exists
plot = self.plot
if plot is None:
plot = Plot(present=True)
# Event if TREE_PRESENT is None, a tree
# can still be spawned here if there is
# any tree data later
tree = plot.current_tree()
# Check for an existing tree:
if self.model_fields.OPENTREEMAP_ID_NUMBER in data:
plot = Plot.objects.get(
pk=data[self.model_fields.OPENTREEMAP_ID_NUMBER])
tree = plot.current_tree()
else:
if data.get(self.model_fields.TREE_PRESENT, False):
tree_edited = True
if tree is None:
tree = Tree(present=True)
data_owner = self.import_event.owner
for modelkey, importdatakey in TreeImportRow.PLOT_MAP.iteritems():
importdata = data.get(importdatakey, None)
if importdata:
plot_edited = True
setattr(plot, modelkey, importdata)
if plot_edited:
plot.last_updated_by = data_owner
plot.import_event = base_treemap_import_event
plot.save()
for modelkey, importdatakey in TreeImportRow.TREE_MAP.iteritems():
importdata = data.get(importdatakey, None)
if importdata:
tree_edited = True
if tree is None:
tree = Tree(present=True)
setattr(tree, modelkey, importdata)
if tree_edited:
tree.last_updated_by = data_owner
tree.import_event = base_treemap_import_event
tree.plot = plot
tree.save()
self.plot = plot
self.status = TreeImportRow.SUCCESS
self.save()
return True