Ejemplo n.º 1
0
def update_data(
obj_key=None, catalogue_uid=None,
name=None, name_origin=None,
brand=None, rating=None, category=None,
subcategory=None, group=None,
price=None, barcode=None,
box_size=None, master_box=None,
status=None, receipt_date=None, real_price=None):
    obj = Gift.get(obj_key)
    if not obj:
        print "Unknown error - object not found!"
        exit(1)
    i = 0
    i += update_value(obj, 'catalogue_id', catalogue_uid)
    i += update_value(obj, 'name_origin', name_origin)
    i += update_value(obj, 'name', name)
    i += update_value(obj, 'brand', brand)
    i += update_value(obj, 'category', category)
    i += update_value(obj, 'subcategory', subcategory)
    i += update_value(obj, 'group', group)
    i += update_value(obj, 'barcode', barcode)
    i += update_value(obj, 'master_box', master_box)
    i += update_value(obj, 'box_size', box_size)
    i += update_value(obj, 'price', price)
    i += update_value(obj, 'real_price', real_price)
    i += update_value(obj, 'rating', rating)
    i += update_value(obj, 'status', status)
    i += update_receipt_date(obj, receipt_date)
    if i:
        obj.put()
Ejemplo n.º 2
0
Archivo: admin.py Proyecto: 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/')
Ejemplo n.º 3
0
def restore_from_trash(request, gift_key):
    gift = Gift.get(gift_key)
    if gift:
        gift.in_trash = False
        gift.put()
        get_gift(gift.uid, True)
    return redirect('/g/%s' % gift.uid)
Ejemplo n.º 4
0
def recalculate_order(request, remove_one=None):
    gifts = []
    total_price = 0
    items_count = 0
    for key in request.session['order'].keys():
        if key == remove_one:
            del(request.session['order'][key])
            continue
        gift_obj = Gift.get(key)
        if gift_obj:
            gift_obj.number = request.session['order'][key]
            if not request.user or request.user.is_anonymous():
                total_price += gift_obj.price * gift_obj.number
            else:
                total_price += gift_obj.real_price * gift_obj.number
            gifts.append(gift_obj)
            items_count += request.session['order'][key]
        else:
            del(request.session['order'][key])
    if gifts:
        request.session['order_items_number'] = len(request.session['order'].keys())
        request.session['order_total_price'] = total_price
        request.session['order_items_count'] = items_count
    else:
        reset_order(request)
    return gifts
Ejemplo n.º 5
0
def move_to_trash(request, gift_key):
    gift = Gift.get(gift_key)
    if gift:
        gift.in_trash = True
        gift.put()
        get_gift(gift.uid, True)
    return redirect('/g/%s' % gift.uid)
Ejemplo n.º 6
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('/')
Ejemplo n.º 7
0
Archivo: admin.py Proyecto: 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)
Ejemplo n.º 8
0
Archivo: views.py Proyecto: gmist/f-toy
def sync_gift_task(request, key):
    gift = Gift.get(key)
    if not gift:
        return render_to_response('empty.html')
    url = 'http://www.5studio.ru/api/v1/get/gift.json?&uid=%s' \
        % gift.uid_5studio
    result = urlfetch.fetch(url)
    if result.status_code == 200:
        j = simplejson.loads(result.content)
        gift.leftovers = j.get('leftovers', 0)
        gift.category = get_category(j)
        gift.subcategory = get_subcategory(j, gift.category)
        gift.put()
    else:
        gift.delete()
    return render_to_response('empty.html')
Ejemplo n.º 9
0
def mass_reset_receipt_dates(request):
    gifts_ids = request.session['mass_edit_items']
    gifts = []
    for gift_id in gifts_ids:
        gift = Gift.get(gift_id)
        if gift:
            gifts.append(gift)

    if not gifts:
        return redirect('/admin/mass_edit/select_filters/')

    for gift in gifts:
        if gift.receipt_date:
            gift.receipt_date = None
            gift.put()
    return redirect('/admin/mass_edit/edit/')
Ejemplo n.º 10
0
Archivo: admin.py Proyecto: 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()})
Ejemplo n.º 11
0
def change_main_thumb(request):
    gift_key = request.values.get('gift_key')
    thumb_key = request.values.get('thumb_key')
    gift = Gift.get(gift_key)
    if gift is None:
        return redirect('/')
    thumb = ThumbImage.get(thumb_key)
    if thumb is None:
        gift.thumbs.remove(thumb_key)
        gift.put()
        get_gift(gift.uid, True)
        return redirect('/g/%s' % gift.uid)

    if gift.main_thumb == thumb_key:
        return redirect('/g/%s' % gift.uid)
    else:
        gift.main_thumb = thumb_key
        gift.put()
        get_gift(gift.uid, True)
    return redirect('/g/%s' % gift.uid)
Ejemplo n.º 12
0
def delete_thumb(request):
    gift_key = request.values.get('gift_key')
    thumb_key = request.values.get('thumb_key')
    gift = Gift.get(gift_key)
    if gift is None:
        return redirect('/')
    thumb = ThumbImage.get(thumb_key)
    if thumb is None:
        gift.thumbs.remove(thumb_key)
        gift.put()
        get_gift(gift.uid, True)
        return redirect('/g/%s' % gift.uid)

    if gift.main_thumb == thumb_key:
        gift.main_thumb = None
    gift.thumbs.remove(thumb_key)
    thumb.delete()
    if not len(gift.thumbs):
        gift.main_thumb = ''
    gift.put()
    get_gift(gift.uid, True)
    return redirect('/g/%s' % gift.uid)
Ejemplo n.º 13
0
def mass_selection_edit(request):
    if request.method == 'POST':
        new_brand_name = string.strip(request.values.get('new_brand_name'))
        new_presentation_id = string.strip(request.values.get('new_presentation_id'))
        new_youtube_id = string.strip(request.values.get('new_youtube_id'))
        new_subcategory = string.strip(request.values.get('new_subcategory'))
        new_group = string.strip(request.values.get('new_group'))
        new_receipt_date = string.strip(request.values.get('new_receipt_date', ''))
        if new_receipt_date:
            try:
                new_receipt_date = datetime.date(datetime.strptime(new_receipt_date, '%Y-%m-%d'))
            except ValueError:
                new_receipt_date = ''

        gifts_ids = request.session['mass_edit_items']
        gifts_array = []
        for gift_id in gifts_ids:
            gift = Gift.get(gift_id)
            if gift:
                gifts_array.append(gift)

        if not gifts_array:
            return redirect('/admin/mass_edit/select_filters/')

        flag_brand_change = False
        flag_groups_change = False

        for gift in gifts_array:
            flag = False
            if new_brand_name and new_brand_name != gift.name:
                gift.brand = new_brand_name
                flag = flag_brand_change = True

            if new_presentation_id and new_presentation_id != gift.presentation_id:
                gift.presentation_id = new_presentation_id
                flag = True

            if new_youtube_id and new_youtube_id != gift.youtube_id:
                gift.youtube_id = new_youtube_id
                flag = True

            if new_subcategory and new_subcategory != gift.subcategory:
                gift.subcategory = new_subcategory
                flag = True
                flag_groups_change = True

            if new_group and new_group != gift.group:
                gift.group = new_group
                flag = True
                flag_groups_change = True

            if new_receipt_date and new_receipt_date != gift.receipt_date:
                gift.receipt_date = new_receipt_date
                flag = True

            if flag:
                gift.put()
        if flag_brand_change:
            Gift.get_brand_list(force=True, is_admin=True)
        if flag_groups_change:
            Gift.get_subcategories_list(force=True)
        request.session['mass_edit_items'] = 0
        return redirect('/admin/mass_edit/select_filters/')
    count = len(request.session['mass_edit_items'])
    return render_to_response('admin/mass_edit/edit.html', {'count':count})
Ejemplo n.º 14
0
Archivo: admin.py Proyecto: gmist/f-toy
def delete(request, key):
    gift = Gift.get(key)
    if gift:
        gift.delete()
    return redirect('/gift/admin/all/')
Ejemplo n.º 15
0
def delete_gift(request, gift_key):
    gift = Gift.get(gift_key)
    if gift:
        gift.delete()
        return redirect('/')
    return redirect(request.url)