Exemplo n.º 1
0
Arquivo: admin.py Projeto: gmist/f-toy
def delete_thumb(request, thumb_key):
    thumb = ThumbImage.get(thumb_key)
    if thumb:
        gift = thumb.gift
        thumb.delete()
        if gift.thumbs.count() and not gift.main_thumb.count():
            tmp_thumb = gift.thumbs[0]
            tmp_thumb.main_gift = gift
            tmp_thumb.put()
        return redirect('/gift/admin/edit/%s/' % gift.key())
    return redirect('/admin/view_all/')
Exemplo n.º 2
0
Arquivo: admin.py Projeto: gmist/f-toy
def set_default_thumb(request, gift, key):
    thumb = ThumbImage.get(key)
    if thumb:
        gift_obj = Gift.get(gift)
        if gift_obj:
            if gift_obj.main_thumb.count():
                for old_thumb in gift_obj.main_thumb:
                    old_thumb.main_gift = None
                    old_thumb.put()
            thumb.main_gift = gift_obj
            thumb.put()
    return redirect('/gift/admin/edit/%s/' % gift)
Exemplo n.º 3
0
Arquivo: admin.py Projeto: gmist/f-toy
def add_news_image(request, news_key):
    news = News.get(news_key)
    if not news:
        news = News()
        news.put()

    form = NewsForm(instance=news)
    images_form = NewsImageForm(action='/news/admin/news/add_image/%s/' % news.key())
    if request.method == 'POST':
        if images_form.validate(request.form, request.files):
            img = images_form['image_file']
            content_type = 'image/jpeg'
            if not images_form['title']:
                title = ''
            else:
                title = images_form['title']
                title = title.replace('"', '"')
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=img,
                                    thumb_size=(100, 100),
                                    content_type=content_type,
                                    title=title)
            if not images_form['width'] or not images_form['height']:
                width = height = 300
            else:
                width = images_form['width']
                height = images_form['height']
            thumb_img.add_new_thumb(blob_img=img,
                                    thumb_size=(width, height),
                                    content_type=content_type,
                                    title=title)
            thumb_img.put()
            news_image = NewsImage()
            news_image.title = title
            news_image.news = news
            news_image.image = thumb_img
            news_image.size = '%sx%s' % (width, height)
            news_image.put()
            return redirect('/news/admin/news/edit/%s/' % news.key())
    return render_to_response('news/admin/news_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget()})
Exemplo n.º 4
0
def add_image_to_new_action(request):
    action = Action(title=u'Новая  акция', discount=0.0)
    action.put()
    action_key = action.key()
    form = ActionForm(instance=action)
    images_form = ActionImageForm(action='/news/admin/actions/add_image_action/')
    if request.method == 'POST':
        if images_form.validate(request.form, request.files):
            img = images_form['image_file']
            content_type = 'image/jpeg'
            if not images_form['title']:
                title = ''
            else:
                title = images_form['title']
                title = title.replace('"', '"')
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=img,
                                    thumb_size=(100, 100),
                                    content_type=content_type,
                                    title=title)
            if not images_form['width'] or not images_form['height']:
                width = height = 300
            else:
                width = images_form['width']
                height = images_form['height']
            thumb_img.add_new_thumb(blob_img=img,
                                    thumb_size=(width, height),
                                    content_type=content_type,
                                    title=title)
            thumb_img.put()
            news_image = ActionImage()
            news_image.title = title
            news_image.action = action
            news_image.image = thumb_img
            news_image.size = '%sx%s' % (width, height)
            news_image.put()
            images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % action_key)
            return redirect('/news/admin/actions/edit/%s/' % action_key)
    images_form = ActionImageForm(action='/news/admin/actions/add_image/%s/' % action_key)
    return render_to_response('news/admin/actions_add.html',
        {'form':form.as_widget(),
         'images_form':images_form.as_widget()})
Exemplo n.º 5
0
Arquivo: admin.py Projeto: gmist/f-toy
def main_page(request):
    form = MainPageBannerForm()
    if request.method == 'POST' and form.validate(request.form, request.files):
        raw_img = form['raw_img']
        name = form['name']
        if not name:
            name = ''
        url = form['url']
        desc = form['desc']
        if not desc:
            desc = ''
        thumb_img = ThumbImage()
        thumb_img.add_new_thumb(blob_img=raw_img, thumb_size=(960, 400),
                                    title=name, content_type='image/png')
        thumb_img.add_new_thumb(blob_img=raw_img, thumb_size=(192, 80),
                                    title=name, content_type='image/png')
        thumb_img.put()
        banner = MainPageBanner(name=name, url=url, desc=desc, img = thumb_img)
        banner.put()
        form = MainPageBannerForm()
    banners = MainPageBanner.all()
    return render_to_response('banner/admin/main_page.html', {'banners':banners, 'form':form.as_widget()})
Exemplo n.º 6
0
Arquivo: views.py Projeto: gmist/f-toy
def sync_add_image(request, uid):
    logging.info("Add image for gift with key: %s" % uid)
    mem_key = 'sync/add_image/%s' % uid
    img_url = memcache.get(mem_key)
    if img_url:
        memcache.delete(mem_key)
        img = urlfetch.fetch(img_url)
        if img.status_code == 200:
            thumb = img.content
            gift = Gift.get_by_id(uid)
            if gift:
                title = gift.name.replace('"', '"')
                thumb_img = ThumbImage()
                content_type = 'image/jpeg'
                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)
                if not gift.thumbs.count():
                    thumb_img.main_gift = gift
                thumb_img.gift = gift
                thumb_img.put()
    return render_json_response({'api_msg': 'Ok', 'api_success': True})
Exemplo n.º 7
0
Arquivo: admin.py Projeto: gmist/f-toy
def view_all(request):
    images = ThumbImage.all()
    return render_to_response('img/admin/view_all.html', {'images':images})
Exemplo n.º 8
0
Arquivo: admin.py Projeto: gmist/f-toy
def delete_thumb(request, key):
    thumb = ThumbImage.get(key)
    if thumb:
        thumb.delete()
    return redirect('/img/admin/view_all/')
Exemplo n.º 9
0
def import_data(in_file='quick_export.csv'):
    images_path = os.path.join(DEFAULT_PATH, 'images')
    reader = csv.reader(open(os.path.join(DEFAULT_PATH, in_file)))
    for i, line in enumerate(reader):
        if not i:
            continue
        uid = line[0]
        gift_imgs_path = os.path.join(images_path, uid)
        try:
            imgs_files = os.listdir(gift_imgs_path)
        except OSError:
            imgs_files = []
        name = line[2].decode('utf-8')
        category = line[3].decode('utf-8')
        subcategory = line[4].decode('utf-8')
        brand = line[5].decode('utf-8')

        if line[6]:
            price = float(line[6])
        else:
            price = 0.0

        size = line[9].decode('utf-8')
        if not size:
            size = u''
        desc = line[10].decode('utf-8')

        if line[11]:
            rating = float(line[11])
        else:
            rating = 3.0
            
        if imgs_files:
            imgs_files =\
            [open(os.path.join(gift_imgs_path, img), 'rb').read() \
             for img in imgs_files]

        if brand:
            brand_obj = Brand.all().filter('brand =', brand)
            if not brand_obj.count():
                brand_obj = Brand(brand=brand)
                brand_obj.put()
            else:
                brand_obj = brand_obj[0]
        else:
            brand_obj = None

        if category:
            category_obj = Category.all().filter('category =', category)
            if category_obj.count():
                category_obj = category_obj[0]
            else:
                category_obj = Category(category=category)
                category_obj.put()
        else:
            category_obj = None

        if category and subcategory:
            subcategory_obj = Subcategory.all().filter('subcategory =', subcategory).filter('on_category =', category_obj)
            if subcategory_obj.count():
                subcategory_obj = subcategory_obj[0]
            else:
                subcategory_obj = Subcategory(subcategory=subcategory, on_category=category_obj)
                subcategory_obj.put()
        else:
            subcategory_obj = None

        gift = Gift(name=name,
                    uid_5studio=uid,
                    brand=brand_obj,
                    category=category_obj,
                    subcategory=subcategory_obj,
                    description=desc,
                    rating=rating,
                    price=price,
                    size=size)
        gift.put()

        if gift.name:
            title = gift.name.replace('"', '"')
        else:
            title = ''
        content_type = 'image/jpeg'
        for thumb in imgs_files:
            thumb_img = ThumbImage()
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(700, 700, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(400, 400, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(200, 200, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            thumb_img.add_new_thumb(blob_img=thumb, thumb_size=(100, 100, ),
                                    title=title, content_type=content_type, is_using_pil=True)
            if not gift.thumbs.count():
                thumb_img.main_gift = gift
            thumb_img.gift = gift
            thumb_img.put()
Exemplo n.º 10
0
Arquivo: admin.py Projeto: gmist/f-toy
def add_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('/gift/admin/edit/%s/' % gift_key)

        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)
            if not gift.thumbs.count():
                thumb_img.main_gift = gift
            thumb_img.gift = gift
            thumb_img.put()

        return redirect('/gift/admin/edit/%s/' % gift_key)
    return redirect('/gift/admin/all/')