Пример #1
0
def add_image_task(request, task_id):
    data = memcache.get(task_id)
    memcache.delete(task_id)
    if not data or not data.get('gift_id') or not data.get('img_url'):
        return render_to_response('empty.html')
    img = urlfetch.fetch(data['img_url'])
    if img.status_code == 200:
        thumb = img.content
        gift = Gift.get_by_id(data['gift_id'])
        if gift:
            title = gift.name.replace('"', '"')
            content_type = 'image/jpeg'
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type)
            thumb_img.put()
            gift.thumbs.append(str(thumb_img.key()))
            if not gift.main_thumb:
                gift.main_thumb = str(thumb_img.key())
            gift.put()
    return render_to_response('empty.html')
Пример #2
0
def upload_new_image(request):
    if request.method == 'POST':
        locstore_key = request.values.get('locstore_key', None)
        locstore = None
        if locstore_key:
            locstore = LocStore.get(locstore_key)
        if locstore is None:
            return redirect('admin/locstore/list/')

        new_th_form = AddNewThumb()
        if request.form and new_th_form.validate(request.form, request.files):
            thumb = new_th_form['img']
            content_type = 'image/jpeg'
            if locstore.name:
                title = locstore.name.replace('"', '"')
            else:
                title = ''
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type)
            thumb_img.put()
            locstore.images.append(str(thumb_img.key()))
            if len(locstore.images) == 1:
                locstore.main_image = str(thumb_img.key())
            locstore.put()
            memcache.delete('get_locstore_%s' % locstore.key())
            return redirect('admin/locstore/edit/%s/' % locstore.key())
    return redirect('/')
Пример #3
0
def upload_new_thumb(request):
    if request.method == 'POST':
        gift_key = request.values.get('gift_key')
        gift = Gift.get(gift_key)
        if gift is None:
            return redirect('/')

        new_th_form = AddNewThumb()
        if request.form and new_th_form.validate(request.form, request.files):
            thumb = new_th_form['img']
            content_type = 'image/jpeg'
            if gift.name:
                title = gift.name.replace('"', '"')
            else:
                title = ''
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type)
            thumb_img.put()
            gift.thumbs.append(str(thumb_img.key()))
            gift.put()
            get_gift(gift.uid, True)
            return redirect('/g/%s' % gift.uid)
    return redirect('/')
Пример #4
0
def add_manager_photo(request):
    if request.method == 'POST':
        manager_key = request.values.get('manager_key')
        manager = Manager.get(manager_key)
        if manager is None:
            return redirect('/admin/managers')

        new_th_form = ManagerPhoto()
        if request.form and new_th_form.validate(request.form, request.files):
            if manager.photo:
                thumb = ThumbImage.get(manager.photo)
                thumb.delete()
                manager.photo = None

            thumb = new_th_form['img']
            content_type = 'image/jpeg'
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200,), content_type=content_type)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100,), content_type=content_type)
            thumb_img.put()
            manager.photo = str(thumb_img.key())
            manager.put()
            return redirect('/admin/edit_manager/%s' % manager.key())
    return redirect('/admin/managers')
Пример #5
0
def fill_obj(obj, fred_path):
    if not obj or not obj.catalogue_id:
        return False

    title = obj.name.replace('"', '"')
    cat_path = os.path.join(fred_path, obj.catalogue_id)
    if not os.path.exists(cat_path):
        return False
    file_names = os.listdir(cat_path)

    if file_names:
        for i in obj.thumbs:
            thumb = ThumbImage.get(i)
            if  thumb:
                thumb.delete()
        obj.thumbs = []
    else:
        return

    file_names.sort()
    first = None
    for fn in file_names:
        if fn[0] == '_':
            first = fn
            file_names.remove(fn)
            break

    if first is not None:
        try:
            full_file_name = os.path.join(cat_path, first)
            img_700 = pilImage.open(full_file_name)
            content_type = 'image/jpeg'
            buf = StringIO.StringIO()
            img_700.save(buf, format=CONVERT_RULES_PIL[content_type][2])
            img_700 = buf.getvalue()
            thumb_img = ThumbImage()

            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(700, 700, ),
                is_using_pil=True,
                title=title,
                content_type=content_type)
            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(400, 400, ),
                is_using_pil=True,
                title=title,
                content_type=content_type)
            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(200, 200, ),
                is_using_pil=True,
                title=title,
                content_type=content_type)
            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(100, 100, ),
                is_using_pil=True,
                title=title,
                content_type=content_type)
            thumb_img.put()
            obj.thumbs.append(str(thumb_img.key()))
            obj.main_thumb = str(thumb_img.key())
        except Exception, ex:
            print obj.catalogue_id
            print ex
Пример #6
0
        except Exception, ex:
            print obj.catalogue_id
            print ex

    for f in file_names:
        try:
            content_type = content_type = 'image/jpeg'
            full_file_name = os.path.join(cat_path, f)
            img_700 = pilImage.open(full_file_name)
            buf = StringIO.StringIO()
            img_700.save(buf, format=CONVERT_RULES_PIL[content_type][2])
            img_700 = buf.getvalue()
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(700, 700, ),
                is_using_pil=True,
                title=title,
                content_type=content_type)
            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(400, 400, ),
                is_using_pil=True,
                title=title,
                content_type=content_type)
            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(200, 200, ),
                is_using_pil=True,
                title=title,
                content_type=content_type)
            thumb_img.add_new_thumb(blob_img=img_700,
                thumb_size=(100, 100, ),
                is_using_pil=True,