Beispiel #1
0
    def handle(self, *args, **kwargs):

        coll = kwargs.get('collection')

        if not coll:
            print "--collection is a required parameter"
            return

        if coll.isdigit():
            collection = Collection.objects.get(id=coll)
        else:
            collection = Collection.objects.get(name=coll)

        admins = User.objects.filter(is_superuser=True)
        if admins:
            admin = admins[0]
        else:
            admin = None

        pb = ProgressBar(collection.records.count())
        for count, record in enumerate(collection.records.all()):

            get_thumbnail_for_record(record, admin)
            get_thumbnail_for_record(record, admin, crop_to_square=True)

            pb.update(count)

        pb.done()
Beispiel #2
0
def record_thumbnail(request, id, name):
    force_reprocess = request.GET.get('reprocess') == 'true'
    filename = get_thumbnail_for_record(id,
                                        request.user,
                                        crop_to_square='square' in request.GET,
                                        force_reprocess=force_reprocess)
    if filename:
        Activity.objects.create(
            event='media-thumbnail',
            request=request,
            content_type=ContentType.objects.get_for_model(Record),
            object_id=id,
            data=dict(square=int('square' in request.GET)))
        try:
            response = HttpResponse(content=open(filename, 'rb').read(),
                                    content_type='image/jpeg')
            patch_cache_control(response, private=True, max_age=3600)
            return response
        except IOError:
            logging.error("IOError: %s" % filename)

    response = HttpResponseRedirect(
        reverse('static', args=('images/thumbnail_unavailable.png', )))
    patch_cache_control(response, no_cache=True)
    return response
Beispiel #3
0
    def test_retrieval(self):
        url = "file:///" + os.path.join(os.path.dirname(__file__), 'test_data', 'dcmetro.tif').replace('\\', '/')
        media = Media.objects.create(record=self.record, storage=self.storage, url=url, mimetype='image/tiff')
        thumbnail = get_thumbnail_for_record(self.record)
        width, height = Image.open(thumbnail).size
        self.assertTrue(width == 100)
        self.assertTrue(height < 100)

        media.delete()
Beispiel #4
0
    def test_retrieval(self):
        url = "file:///" + os.path.join(os.path.dirname(__file__), 'test_data', 'dcmetro.tif').replace('\\', '/')
        media = Media.objects.create(record=self.record, storage=self.storage, url=url, mimetype='image/tiff')
        thumbnail = get_thumbnail_for_record(self.record)
        width, height = Image.open(thumbnail).size
        self.assertTrue(width == 100)
        self.assertTrue(height < 100)

        media.delete()
Beispiel #5
0
    def test_thumbnail(self):
        Media.objects.filter(record=self.record).delete()
        media = Media.objects.create(record=self.record, name='tiff', mimetype='image/tiff', storage=self.storage)
        with open(os.path.join(os.path.dirname(__file__), 'test_data', 'dcmetro.tif'), 'rb') as f:
            media.save_file('dcmetro.tif', f)

        thumbnail = get_thumbnail_for_record(self.record)
        width, height = Image.open(thumbnail).size
        self.assertTrue(width == 100)
        self.assertTrue(height < 100)

        media.delete()
Beispiel #6
0
    def test_thumbnail(self):
        Media.objects.filter(record=self.record).delete()
        media = Media.objects.create(record=self.record, name='tiff', mimetype='image/tiff', storage=self.storage)
        with open(os.path.join(os.path.dirname(__file__), 'test_data', 'dcmetro.tif'), 'rb') as f:
            media.save_file('dcmetro.tif', f)

        thumbnail = get_thumbnail_for_record(self.record)
        width, height = Image.open(thumbnail).size
        self.assertTrue(width == 100)
        self.assertTrue(height < 100)

        media.delete()
Beispiel #7
0
def record_thumbnail(request, id, name):
    filename = get_thumbnail_for_record(id, request.user, crop_to_square=request.GET.has_key('square'))
    if filename:
        Activity.objects.create(event='media-thumbnail',
                                request=request,
                                content_type=ContentType.objects.get_for_model(Record),
                                object_id=id,
                                #content_object=record,
                                data=dict(square=int(request.GET.has_key('square'))))
        try:
            return HttpResponse(content=open(filename, 'rb').read(), mimetype='image/jpeg')
        except IOError:
            logging.error("IOError: %s" % filename)
    return HttpResponseRedirect(reverse('static', args=('images/thumbnail_unavailable.png',)))
Beispiel #8
0
def thumbnail(request, username, id, name):
    record = get_object_or_404(Record, id=id, owner__username=username, source__startswith='jmutube')

    filename = get_thumbnail_for_record(record, request.user, crop_to_square=request.GET.has_key('square'))
    if filename:
        try:
            content = open(filename, 'rb').read()
            if content:
                return HttpResponse(content=content, mimetype="image/jpeg")
        except IOError:
            pass
        return HttpResponseServerError()
    else:
        return HttpResponseRedirect(reverse('jmutube-static', args=('images/nothumbnail.jpg',)))
Beispiel #9
0
def record_thumbnail(request, id, name):
    filename = get_thumbnail_for_record(
        id, request.user, crop_to_square=request.GET.has_key('square'))
    if filename:
        Activity.objects.create(
            event='media-thumbnail',
            request=request,
            content_type=ContentType.objects.get_for_model(Record),
            object_id=id,
            #content_object=record,
            data=dict(square=int(request.GET.has_key('square'))))
        try:
            return HttpResponse(content=open(filename, 'rb').read(),
                                mimetype='image/jpeg')
        except IOError:
            logging.error("IOError: %s" % filename)
    return HttpResponseRedirect(
        reverse('static', args=('images/thumbnail_unavailable.png', )))
Beispiel #10
0
def record_thumbnail(request, id, name):
    print 'record_thumbnail'
    filename = get_thumbnail_for_record(id, request.user, crop_to_square=request.GET.has_key('square'))
    if filename:
        Activity.objects.create(event='media-thumbnail',
                                request=request,
                                content_type=ContentType.objects.get_for_model(Record),
                                object_id=id,
                                #content_object=record,
                                data=dict(square=int(request.GET.has_key('square'))))
        try:
            return HttpResponse(content=open(filename, 'rb').read(), mimetype='image/jpeg')
        except IOError:
            logging.error("IOError: %s" % filename)
    record = Record.filter_one_by_access(request.user, id)
    if record and record.tmp_extthumb:
        return HttpResponseRedirect(record.tmp_extthumb)
    print "THUMBNAIL UNAVAILABLE - NO RECORD"
    return HttpResponseRedirect(reverse('static', args=('images/thumbnail_unavailable.png',)))
Beispiel #11
0
def record_thumbnail(request, id, name):
    print 'record_thumbnail'
    filename = get_thumbnail_for_record(id, request.user, crop_to_square=request.GET.has_key('square'))
    if filename:
        Activity.objects.create(event='media-thumbnail',
                                request=request,
                                content_type=ContentType.objects.get_for_model(Record),
                                object_id=id,
                                #content_object=record,
                                data=dict(square=int(request.GET.has_key('square'))))
        try:
            return HttpResponse(content=open(filename, 'rb').read(), mimetype='image/jpeg')
        except IOError:
            logging.error("IOError: %s" % filename)
    record = Record.filter_one_by_access(request.user, id)
    if record and record.tmp_extthumb:
        return HttpResponseRedirect(record.tmp_extthumb)
    print "THUMBNAIL UNAVAILABLE - NO RECORD"
    return HttpResponseRedirect(reverse('static', args=('images/thumbnail_unavailable.png',)))