Пример #1
0
    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)
Пример #2
0
    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)
Пример #3
0
 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()
Пример #4
0
def index(request):
    random = Photo.get_random(8)
    tags = Tag.get_cloud()
    t = settings.GALLERY_SETTINGS["recent_photos_time"]
    recent = Photo.get_random(8, since=(time.time() - t))
    recent_tags = Tag.get_recent_tags_cloud()
    params = {"random": random, "tags": tags, "recent": recent, "recent_tags": recent_tags}
    if hasattr(request, "openid"):
        params["openid"] = request.openid
    params.update(DEFAULT_PARAMS)
    return render_to_response("gallery/index.html", params, context_instance=RequestContext(request))
Пример #5
0
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()
Пример #6
0
    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
Пример #7
0
def recent(request, tag_name=None, page=None):
    tag = Tag.with_name(tag_name)
    if not tag:
        photo_set = Photo.recent()
        video_set = Video.recent()
    else:
        photo_set = tag.get_recent_photos()
        video_set = tag.get_recent_videos()

    media_set = list(photo_set) + list(video_set)
    total = len(media_set)
    page, start, end, nb_pages = get_page(page, total)

    medias = media_set[start:end]
    total_pages = range(nb_pages)

    slug = "/%s/recent/" % G_URL
    if tag_name:
        slug += "%s/" % tag_name

    params = {
        "tag": tag,
        "page": page,
        "slug": slug,
        "tag_name": tag_name,
        "nb_pages": nb_pages,
        "total_pages": total_pages,
        "medias": medias,
    }
    params.update(DEFAULT_PARAMS)
    return render_to_response("gallery/tag.html", params, context_instance=RequestContext(request))
Пример #8
0
def tag_file(file_id, auth_dict=None):
    file_id = int(file_id)
    file_model = File.query.filter(File.id == file_id).first()

    if file_model is None:
        return "file not found", 404

    current_tags = Tag.query.filter(Tag.file_id == file_id).all()
    for tag in current_tags:
        db.session.delete(tag)
        db.session.flush()
        db.session.commit()

    uuids = json.loads(request.form.get('members'))

    for uuid in uuids:
        # Don't allow empty tag entries
        if uuid != '':
            tag_model = Tag(file_id, uuid)
            db.session.add(tag_model)
            db.session.flush()
            db.session.commit()
            db.session.refresh(tag_model)

    return "ok", 200
Пример #9
0
    def test_delete_tag(self):
        tag = Tag()
        db.session.add(tag)
        db.session.commit()
        self.assertIsNotNone(Tag.query.get(1))

        response = self.client.post(url_for('admin.delete_tag', tag_id=1), follow_redirects=True)
        data = response.get_data(as_text=True)
        self.assertIn('Tag deleted.', data)
        self.assertEqual(Tag.query.get(1), None)
Пример #10
0
def medias_in_tag(request, tag_name, photo_id=None, video_id=None, page=None):
    if photo_id:
        return photo(request, photo_id, in_tag_name=tag_name)
    elif video_id:
        return video(request, video_id, in_tag_name=tag_name)
    else:
        if tag_name.find("+") > -1:
            # combination of tags
            media_set = Tag.build_set(tag_name)
            tag = None
        else:
            # display all photos of the tag
            tag = Tag.with_name(tag_name)
            if not tag:
                raise Http404
            else:
                photo_set = tag.photo_set.order_by("timestamp")
                video_set = tag.video_set.order_by("time_created")
                media_set = list(photo_set) + list(video_set)

        total = len(media_set)
        page, start, end, nb_pages = get_page(page, total)

        medias = media_set[start:end]
        total_pages = range(nb_pages)
        slug = "%s/tag/%s/" % (G_URL, tag_name)
        params = {
            "tag": tag,
            "page": page,
            "slug": slug,
            "tag_name": tag_name,
            "nb_pages": nb_pages,
            "total_pages": total_pages,
            "medias": medias,
        }
        params.update(DEFAULT_PARAMS)
        return render_to_response("gallery/tag.html", params, context_instance=RequestContext(request))
Пример #11
0
    def test_delete_tag(self):
        photo = Photo.query.get(2)
        tag = Tag(name='test')
        photo.tags.append(tag)
        db.session.commit()

        self.login()
        response = self.client.post(url_for('main.delete_tag',
                                            photo_id=2,
                                            tag_id=2),
                                    follow_redirects=True)
        data = response.get_data(as_text=True)
        self.assertIn('Tag deleted.', data)

        self.assertEqual(photo.tags, [])
        self.assertIsNone(Tag.query.get(2))
Пример #12
0
def photo(request, photo_id, in_tag_name=None, in_event_id=None):
    reset_cache, form = process_form(request, aksmet, photo_id=photo_id)

    response = None
    cache_key = "photo_%s" % photo_id

    if not reset_cache:
        response = cache.get(cache_key)
        if not response:
            reset_cache = True

    if reset_cache or not response:
        p = get_object_or_404(Photo.objects.using("gallery"), pk=photo_id)
        exported = get_object_or_404(OriginalExport.objects.using("gallery"), id=photo_id)

        tag = None
        event = None
        if in_tag_name:
            tag = Tag.with_name(in_tag_name)
            kw = dict(tag=tag)
        elif in_event_id:
            kw = dict(event_id=in_event_id)
            event = get_object_or_404(Event.objects.using("gallery"), pk=in_event_id)
        else:
            kw = {}
        previous = p.get_sibling_media("previous", **kw)
        next = p.get_sibling_media("next", **kw)
        p.increment_hit()
        slug = "/%s/photo/%s/" % (G_URL, p.id)
        slideshow_url = "%s/slideshow/%s/%d" % (G_URL, in_tag_name, p.id)
        params = {
            "tag": tag,
            "media": p,
            "previous": previous,
            "slug": slug,
            "next": next,
            "exported": exported,
            "form": form,
            "event": event,
            "slideshow_url": slideshow_url,
        }
        params.update(DEFAULT_PARAMS)
        context = RequestContext(request)
        response = render_to_response("gallery/photo.html", params, context_instance=context)
        cache.set(cache_key, response, CACHE_TIMEOUT)
    return response
Пример #13
0
def new_tag(photo_id):
    photo = Photo.query.get_or_404(photo_id)
    if current_user != photo.author and not current_user.can('MODERATE'):
        abort(403)

    form = TagForm()
    if form.validate_on_submit():
        for name in form.tag.data.split():
            tag = Tag.query.filter_by(name=name).first()
            if tag is None:
                tag = Tag(name=name)
                db.session.add(tag)
                db.session.commit()
            if tag not in photo.tags:
                photo.tags.append(tag)
                db.session.commit()
        flash('Tag added.', 'success')

    flash_errors(form)
    return redirect(url_for('.show_photo', photo_id=photo_id))
Пример #14
0
 def get_object(self, bits):
     if len(bits) != 1:
         raise ObjectDoesNotExist
     return Tag.with_name(bits[0])
Пример #15
0
 def items(self):
     return Tag.get_recent_tags_cloud()
Пример #16
0
    def setUp(self):
        app = create_app('testing')
        self.context = app.test_request_context()
        self.context.push()
        self.client = app.test_client()
        self.runner = app.test_cli_runner()

        db.create_all()
        Role.init_role()

        admin_user = User(email='*****@*****.**',
                          name='Admin',
                          username='******',
                          confirmed=True)
        admin_user.set_password('123')
        normal_user = User(email='*****@*****.**',
                           name='Normal User',
                           username='******',
                           confirmed=True)
        normal_user.set_password('123')
        unconfirmed_user = User(email='*****@*****.**',
                                name='Unconfirmed',
                                username='******',
                                confirmed=False)
        unconfirmed_user.set_password('123')
        locked_user = User(email='*****@*****.**',
                           name='Locked User',
                           username='******',
                           confirmed=True,
                           locked=True)
        locked_user.set_password('123')
        locked_user.lock()

        blocked_user = User(email='*****@*****.**',
                            name='Blocked User',
                            username='******',
                            confirmed=True,
                            active=False)
        blocked_user.set_password('123')

        photo = Photo(filename='test.jpg',
                      filename_s='test_s.jpg',
                      filename_m='test_m.jpg',
                      description='Photo 1',
                      author=admin_user)
        photo2 = Photo(filename='test2.jpg',
                       filename_s='test_s2.jpg',
                       filename_m='test_m2.jpg',
                       description='Photo 2',
                       author=normal_user)

        comment = Comment(body='test comment body',
                          photo=photo,
                          author=normal_user)
        tag = Tag(name='test tag')
        photo.tags.append(tag)
        db.session.add_all([
            admin_user, normal_user, unconfirmed_user, locked_user,
            blocked_user
        ])
        db.session.commit()
Пример #17
0
def get_files_tagged(uuids: List[str]) -> List[File]:
    # NOTE(rossdylan): I think this is what was originally intended for this
    # function. It was seriously broken so I rewrote it from scratch
    fids = Tag.query(Tag.file_id).filter(Tag.uid in uuids).all()
    return File.query.filter(File.id in fids).all()
Пример #18
0
def slideshow(request, tag_name=None, photo_id=None):
    tag = Tag.with_name(tag_name)
    p = get_object_or_404(Photo.objects.using("gallery"), pk=photo_id)
    photos = tag.photo_set_from(p.timestamp)
    params = {"photos": photos}
    return render_to_response("gallery/slideshow.html", params, context_instance=RequestContext(request))