def test_rotate_image_not_allowed_for_user_in_different_family(self): ''' Tests that user can not rotate image for another family ''' p = Person.objects.create(name='badger', family_id=self.family.id) #Copy test image to media area shutil.copy2(self.test_image, self.test_image_destination) im = Image(gallery=self.gallery, family=self.family, original_image=self.test_image_destination, thumbnail=self.test_image_destination, large_thumbnail=self.test_image_destination) im.save() tag = Tag(image_id=im.id, x1=0.5, y1=0.8, x2=0.5, y2=0.5, person_id=p.id) tag.save() self.client.login(email='*****@*****.**', password='******') response = self.client.post('/image={0}/rotate/'.format(im.id), {'anticlockwise_angle': '90'}) self.assertEqual(404, response.status_code) tag = Tag.objects.get(id=tag.id) self.assertEqual(0.5, tag.x2)
def test_rotate_image(self): ''' Tests that user can rotate image succesffully ''' p = Person.objects.create(name='badger', family_id=self.family.id) #Copy test image to media area shutil.copy2(self.test_image, self.test_image_destination) im = Image( gallery=self.gallery, family=self.family, original_image=self.test_image_key, thumbnail=self.test_image_key, large_thumbnail=self.test_image_key ) im.save() im.upload_files_to_s3() tag = Tag( image_id=im.id, x1=0.5, y1=0.8, x2=0.5, y2=0.5, person_id=p.id) tag.save() self.client.login(email='*****@*****.**', password='******') response = self.client.post('/image={0}/rotate/'.format(im.id), {'anticlockwise_angle': '90'}) self.assertNotEqual(404, response.status_code) tag = Tag.objects.get(id=tag.id) self.assertEqual(0.8, tag.x2)
def _recreate_default_tags(self): tag_list = [] self._delete_tags_from_db() for roots, dirs, file_names in os.walk(self._gallery_path): for tag in dirs: if tag != '' and tag != 'thumbs': tag_list.append(tag) for tag in tag_list: # TODO: add exception for unique new_tag = Tag(name=tag, verbal_name=tag) new_tag.save()
def create_new_tag(request): post_tag = request.POST['tag'] try: # Try to fetch the inputted tag from the table containing unique # examples of tags used exists = Tag.objects.get(title=post_tag) except ObjectDoesNotExist: # If this fetch fails, we know the tag has never been used before # and we create it from scratch new_tag = Tag() new_tag.title = post_tag new_tag.save()
def convertToTag(self, person_id): new_tag = Tag(image_id=self.image_id, person_id=person_id, x1=self.x1, y1=self.y1, x2=self.x2, y2=self.y2, face_detected=True) new_tag.save() self.delete() return new_tag