本文整理汇总了Python中treemap.models.Tree.last_updated方法的典型用法代码示例。如果您正苦于以下问题:Python Tree.last_updated方法的具体用法?Python Tree.last_updated怎么用?Python Tree.last_updated使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类treemap.models.Tree
的用法示例。
在下文中一共展示了Tree.last_updated方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_result_map
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import last_updated [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)
示例2: update_plot_and_tree
# 需要导入模块: from treemap.models import Tree [as 别名]
# 或者: from treemap.models.Tree import last_updated [as 别名]
def update_plot_and_tree(request, plot_id):
response = HttpResponse()
try:
plot = Plot.objects.get(pk=plot_id)
except Plot.DoesNotExist:
response.status_code = 400
response.content = simplejson.dumps({"error": "No plot with id %s" % plot_id})
return response
request_dict = json_from_request(request)
flatten_plot_dict_with_tree_and_geometry(request_dict)
plot_field_whitelist = ['plot_width','plot_length','type','geocoded_address','edit_address_street', 'address_city', 'address_street', 'address_zip', 'power_lines', 'sidewalk_damage']
# The Django form that creates new plots expects a 'plot_width' parameter but the
# Plot model has a 'width' parameter so this dict acts as a translator between request
# keys and model field names
plot_field_property_name_dict = {'plot_width': 'width', 'plot_length': 'length', 'power_lines': 'powerline_conflict_potential'}
# The 'auth.change_user' permission is a proxy for 'is the user a manager'
user_is_not_a_manager = not request.user.has_perm('auth.change_user')
should_create_plot_pends = settings.PENDING_ON and plot.was_created_by_a_manager and user_is_not_a_manager
plot_was_edited = False
for plot_field_name in request_dict.keys():
if plot_field_name in plot_field_whitelist:
if plot_field_name in plot_field_property_name_dict:
new_name = plot_field_property_name_dict[plot_field_name]
else:
new_name = plot_field_name
new_value = request_dict[plot_field_name]
if not compare_fields(getattr(plot, new_name), new_value):
if should_create_plot_pends:
plot_pend = PlotPending(plot=plot)
plot_pend.set_create_attributes(request.user, new_name, new_value)
plot_pend.save()
else:
setattr(plot, new_name, new_value)
plot_was_edited = True
# TODO: Standardize on lon or lng
if 'lat' in request_dict or 'lon' in request_dict or 'lng' in request_dict:
new_geometry = Point(x=plot.geometry.x, y=plot.geometry.y)
if 'lat' in request_dict:
new_geometry.y = request_dict['lat']
if 'lng' in request_dict:
new_geometry.x = request_dict['lng']
if 'lon' in request_dict:
new_geometry.x = request_dict['lon']
if plot.geometry.x != new_geometry.x or plot.geometry.y != new_geometry.y:
if should_create_plot_pends:
plot_pend = PlotPending(plot=plot)
plot_pend.set_create_attributes(request.user, 'geometry', new_geometry)
plot_pend.save()
else:
plot.geometry = new_geometry
plot_was_edited = True
if plot_was_edited:
plot.last_updated = datetime.datetime.now()
plot.last_updated_by = request.user
plot.save()
change_reputation_for_user(request.user, 'edit plot', plot)
tree_was_edited = False
tree_was_added = False
tree = plot.current_tree()
tree_field_whitelist = ['species','dbh','height','canopy_height', 'canopy_condition', 'condition']
if tree is None:
should_create_tree_pends = False
else:
should_create_tree_pends = settings.PENDING_ON and tree.was_created_by_a_manager and user_is_not_a_manager
for tree_field in Tree._meta.fields:
if tree_field.name in request_dict and tree_field.name in tree_field_whitelist:
if tree is None:
import_event, created = ImportEvent.objects.get_or_create(file_name='site_add',)
tree = Tree(plot=plot, last_updated_by=request.user, import_event=import_event)
tree.plot = plot
tree.last_updated_by = request.user
tree.save()
tree_was_added = True
if tree_field.name == 'species':
try:
if (tree.species and tree.species.pk != request_dict[tree_field.name]) \
or (not tree.species and request_dict[tree_field.name]):
if should_create_tree_pends:
tree_pend = TreePending(tree=tree)
tree_pend.set_create_attributes(request.user, 'species_id', request_dict[tree_field.name])
tree_pend.save()
else:
tree.species = Species.objects.get(pk=request_dict[tree_field.name])
tree_was_edited = True
except Exception:
response.status_code = 400
response.content = simplejson.dumps({"error": "No species with id %s" % request_dict[tree_field.name]})
return response
else: # tree_field.name != 'species'
#.........这里部分代码省略.........