Exemplo n.º 1
0
 def test_add_photo_sets_updated(self):
     tree = Tree(diameter=10, plot=self.plot, instance=self.instance)
     tree.save_with_user(self.user)
     photo = TreePhoto(instance=self.instance,
                       map_feature=self.plot, tree=tree)
     photo.set_image(self.load_resource('tree1.gif'))
     photo.save_with_user(self.fellow)
     self.plot.refresh_from_db()
     self.assertGreater(self.plot.updated_at, self.initial_updated)
     self.assertEqual(self.plot.updated_by, self.fellow)
Exemplo n.º 2
0
 def test_user_can_create_tree_photo(self):
     self._add_builtin_permission(self.role_yes, TreePhoto, 'add_treephoto')
     commander = make_commander_user(self.instance)
     plot = Plot(instance=self.instance, geom=self.p)
     plot.save_with_user(commander)
     tree = Tree(plot=plot, instance=self.instance)
     tree.save_with_user(commander)
     user_yes = make_user(instance=self.instance,
                          make_role=lambda inst: self.role_yes)
     photo = TreePhoto(instance=self.instance, map_feature=plot, tree=tree)
     photo.set_image(self.load_resource('tree1.gif'))
     self.assertTrue(photo.user_can_create(user_yes))
Exemplo n.º 3
0
 def test_user_can_create_tree_photo(self):
     self._add_builtin_permission(self.role_yes, TreePhoto, 'add_treephoto')
     commander = make_commander_user(self.instance)
     plot = Plot(instance=self.instance, geom=self.p)
     plot.save_with_user(commander)
     tree = Tree(plot=plot, instance=self.instance)
     tree.save_with_user(commander)
     user_yes = make_user(instance=self.instance,
                          make_role=lambda inst: self.role_yes)
     photo = TreePhoto(instance=self.instance,
                       map_feature=plot, tree=tree)
     photo.set_image(self.load_resource('tree1.gif'))
     self.assertTrue(photo.user_can_create(user_yes))
Exemplo n.º 4
0
def add_tree_photo(request, plot_id):
    uploaded_image = ContentFile(request.raw_post_data)
    uploaded_image.name = "plot_%s.png" % plot_id

    plot = Plot.objects.get(pk=plot_id)
    tree = plot.current_tree()

    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()

    treephoto = TreePhoto(tree=tree,title=uploaded_image.name,reported_by=request.user)
    treephoto.photo.save("plot_%s.png" % plot_id, uploaded_image)

    treephoto.save()

    return { "status": "success", "title": treephoto.title, "id": treephoto.pk }
Exemplo n.º 5
0
 def test_add_photo_sets_updated(self):
     tree = Tree(diameter=10, plot=self.plot, instance=self.instance)
     tree.save_with_user(self.user)
     photo = TreePhoto(instance=self.instance,
                       map_feature=self.plot,
                       tree=tree)
     photo.set_image(self.load_resource('tree1.gif'))
     photo.save_with_user(self.fellow)
     self.plot.refresh_from_db()
     self.assertGreater(self.plot.updated_at, self.initial_updated)
     self.assertEqual(self.plot.updated_by, self.fellow)