def test_update_species(self): with self._assert_updates_eco_rev(True): tree = Tree(instance=self.instance, plot=self.plot) tree.save_with_user(self.user) species = Species(common_name='foo', instance=self.instance) species.save_with_user(self.user) request_dict = {'tree.species': species.pk} update_map_feature(request_dict, self.user, self.plot)
def test_create_bioswale(self): self.instance.add_map_feature_types(['Bioswale']) with self._assert_updates_geo_and_eco_rev(): bioswale = Bioswale(instance=self.instance) request_dict = { 'plot.geom': {'x': 0, 'y': 0}, 'bioswale.polygon': {'polygon': [ [0, 0], [1, 0], [1, 1], [0, 1], [0, 0]]} } update_map_feature(request_dict, self.user, bioswale) with self._assert_updates_geo_and_eco_rev(): request_dict = { 'bioswale.polygon': {'polygon': [ [0, 0], [2, 0], [2, 2], [0, 2], [0, 0]]}} update_map_feature(request_dict, self.user, bioswale)
def test_create_bioswale(self): self.instance.add_map_feature_types(['Bioswale']) with self._assert_updates_geo_and_eco_rev(): bioswale = Bioswale(instance=self.instance) request_dict = { 'plot.geom': { 'x': 0, 'y': 0 }, 'bioswale.polygon': { 'polygon': [[0, 0], [1, 0], [1, 1], [0, 1], [0, 0]] } } update_map_feature(request_dict, self.user, bioswale) with self._assert_updates_geo_and_eco_rev(): request_dict = { 'bioswale.polygon': { 'polygon': [[0, 0], [2, 0], [2, 2], [0, 2], [0, 0]] } } update_map_feature(request_dict, self.user, bioswale)
def update_or_create_plot(request, instance, plot_id=None): # The API communicates via nested dictionaries but # our internal functions prefer dotted pairs (which # is what inline edit form users) request_dict = json.loads(request.body) data = {} for model in ["plot", "tree"]: if model in request_dict: for key, val in request_dict[model].iteritems(): data["%s.%s" % (model, key)] = val # We explicitly disallow setting a plot's tree id. # We ignore plot's updated at and by because # auditing sets them automatically. keys = ["tree.plot", "tree.udfs", "tree.instance", "plot.updated_at", "plot.updated_by", "plot.instance", "plot.udfs"] for key in keys: if key in data: del data[key] if "tree.species" in data: sp = data["tree.species"] if sp and "id" in sp: data["tree.species"] = sp['id'] else: data["tree.species"] = None if plot_id: plot = get_object_or_404(Plot, pk=plot_id, instance=instance) else: plot = Plot(instance=instance) plot, __ = update_map_feature(data, request.user, plot) context_dict = context_dict_for_plot(request, plot) # Add geo rev hash so clients will know if a tile refresh is required context_dict["geoRevHash"] = plot.instance.geo_rev_hash context_dict["universalRevHash"] = plot.instance.universal_rev_hash return context_dict
def update_or_create_plot(request, instance, plot_id=None): # The API communicates via nested dictionaries but # our internal functions prefer dotted pairs (which # is what inline edit form users) request_dict = json.loads(request.body) data = {} for model in ["plot", "tree"]: if model in request_dict: for key, val in request_dict[model].iteritems(): data["%s.%s" % (model, key)] = val # We explicitly disallow setting a plot's tree id. # We ignore plot's updated at and by because # auditing sets them automatically. keys = [ "tree.plot", "tree.udfs", "tree.instance", "plot.updated_at", "plot.updated_by", "plot.instance", "plot.udfs" ] for key in keys: if key in data: del data[key] if "tree.species" in data: sp = data["tree.species"] if sp and "id" in sp: data["tree.species"] = sp['id'] else: data["tree.species"] = None if plot_id: plot = get_object_or_404(Plot, pk=plot_id, instance=instance) else: plot = Plot(instance=instance) plot, __ = update_map_feature(data, request.user, plot) context_dict = context_dict_for_plot(request, plot) # Add geo rev hash so clients will know if a tile refresh is required context_dict["geoRevHash"] = plot.instance.geo_rev_hash context_dict["universalRevHash"] = plot.instance.universal_rev_hash return context_dict
def test_update_without_move(self): with self._assert_updates_geo_and_eco_rev(False): request_dict = {'plot.address_zip': '19119'} update_map_feature(request_dict, self.user, self.plot)
def test_move(self): with self._assert_updates_geo_and_eco_rev(): request_dict = {'plot.geom': {'x': 5, 'y': 5}} update_map_feature(request_dict, self.user, self.plot)
def test_create_plot(self): with self._assert_updates_geo_and_eco_rev(): plot = Plot(instance=self.instance) request_dict = {'plot.geom': {'x': 0, 'y': 0}} update_map_feature(request_dict, self.user, plot)
def test_update_diameter(self): with self._assert_updates_eco_rev(True): tree = Tree(instance=self.instance, plot=self.plot, diameter=3) tree.save_with_user(self.user) request_dict = {'tree.diameter': '5'} update_map_feature(request_dict, self.user, self.plot)
def test_update_without_move(self): with self._assert_updates_geo_rev(False): request_dict = {'plot.address_zip': '19119'} update_map_feature(request_dict, self.user, self.plot) self.plot.save_with_user(self.user)
def test_move(self): with self._assert_updates_geo_rev(): request_dict = {'plot.geom': {'x': 5, 'y': 5}} update_map_feature(request_dict, self.user, self.plot) self.plot.save_with_user(self.user)
def test_create(self): with self._assert_updates_geo_rev(): plot = Plot(instance=self.instance) request_dict = {'plot.geom': {'x': 0, 'y': 0}} update_map_feature(request_dict, self.user, plot) plot.save_with_user(self.user)