예제 #1
0
파일: admin.py 프로젝트: 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/')
예제 #2
0
파일: views.py 프로젝트: gmist/five-studio
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('/')
예제 #3
0
파일: admin.py 프로젝트: gmist/f-toy
def edit(request, key):
    ret_url = request.values.get('ret_url', '')
    gift = Gift.get(key)
    if gift is None:
        return redirect('/gift/admin/all/')
    edit_form = GiftForm(instance=gift)
    if request.method == 'POST' and edit_form.validate(request.form):
        edit_form.save()
        if ret_url:
            return redirect(ret_url)
        return redirect('/gift/admin/all/')
    add_new_thumb_form = AddNewThumb()
    return render_to_response('gift/admin/edit.html',
            {'edit_form':edit_form.as_widget(),
             'gift':gift,
             'add_new_thumb_form':add_new_thumb_form.as_widget()})
예제 #4
0
파일: views.py 프로젝트: gmist/five-studio
def get(request, uid):
    @memcached(24*60*60)
    def get_gift_additional(uid_, group):
        gifts = Gift.all().filter(
            'group =', group).filter('uid !=', uid_).fetch(3)
        return prefetch_refprops(gifts, Gift.category, Gift.group)

    @memcached(24*60*60)
    def html(gift_, referrer_):
        active_category = None
        if gift_.group:
            additional_gifts = get_gift_additional(uid, gift_.group)
            active_category = gift_.group.key().id()
        else:
            additional_gifts = None
            if gift_.category:
                active_category = gift_.category.key().id()
        return render_to_response('gift/get.html', {
            'active_category': active_category,
            'gift': gift_, 'gifts': additional_gifts,
            'referrer': referrer_
        })
    referrer = request.environ.get('HTTP_REFERER')
    gift = get_gift(uid)
    if not gift:
        return Response(status=404)
    if gift.name:
        gift.encode_name = re.sub('[/!,;."\'\-0-9]', '', gift.name)
        gift.encode_name = ' '.join(word for word in gift.encode_name.split() if len(word) > 2)
        gift.encode_name_cp1251 = wurls.url_fix(gift.encode_name, 'cp1251')
    if not request.user.is_admin:
        return html(gift, referrer)

    gift_edit_form = GiftEditForm(instance=gift)
    if request.method == 'POST':
        if gift_edit_form.validate(request.form):
            gift_edit_form.save()
            get_gift(uid, True)
        return redirect(url_for('gift/get', uid=uid))
    else:
        add_new_thumb_form = AddNewThumb()
        return render_to_response('gift/get.html', {
            'gift': gift,
            'referrer': referrer,
            'gift_edit_form': gift_edit_form.as_widget(),
            'add_new_thumb_form': add_new_thumb_form.as_widget()
        })