本文整理汇总了Python中apps.gift.models.Gift类的典型用法代码示例。如果您正苦于以下问题:Python Gift类的具体用法?Python Gift怎么用?Python Gift使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了Gift类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: index
def index(request):
if request.method == 'POST':
text = request.form.get('q', '')
if not text:
return redirect('/')
text = text.strip()
gifts = Gift.all().filter('in_trash =', False)\
.filter('leftovers >', 0).search(
text, properties=['name']
)
if not gifts.count():
gifts = Gift.all().filter('in_trash =', False)\
.filter('leftovers >', 0).search(
text, properties=['barcode']
)
if not gifts.count():
gifts = Gift.all().filter('in_trash =', False)\
.filter('leftovers >', 0).search(
text, properties=['catalogue_id']
)
if not gifts:
return redirect('/')
return render_to_response(
'srch/index.html',
{'gifts': gifts, 'search_text': text}
)
else:
return redirect('/')
示例2: quick_import
def quick_import(file_name='leftovers.csv'):
csv_file = open_csv(file_name)
for i, line in enumerate(csv_file):
if line[0] and line[1]:
name = unicode.strip(line[0].decode('utf8'))
gift = Gift.all().filter('name =', name)
if gift.count():
gift = gift[0]
leftovers = line[1].strip().replace(',', '').replace('.', '')
if not leftovers:
leftovers = 0
else:
leftovers = int(leftovers)
if gift.leftovers == leftovers:
if gift.leftovers !=0 and gift.receipt_date:
gift.receipt_date = None
gift.put()
continue
gift.leftovers = leftovers
if gift.receipt_date:
gift.receipt_date = None
gift.put()
print "%s %s : %s" % (i, gift.uid, gift.leftovers)
print "========================================================"
for g in Gift.all():
print g.leftovers
示例3: show
def show(request):
gifts = []
order_items = request.session.get('order', {})
if not order_items:
return render_to_response('cart/show.html', {'gifts':gifts})
total_price = 0
for k, val in order_items.iteritems():
gift = Gift.get_by_id(k)
if gift:
gift.count = val
gifts.append(gift)
total_price += gift.price * val
form = OrderForm()
if request.method == 'POST' and form.validate(request.form):
order = form.save(commit=False)
order.email = request.form.get('email', None)
order.address = request.form.get('address', None)
order.put()
for k, v in request.session.get('order', {}).items():
gift = Gift.get_by_id(k)
if gift:
oi = OrderItem(gift_id=gift, count=v)
oi.in_order = order
oi.put()
clear_cart(request)
return render_to_response('cart/confirm_complete.html')
return render_to_response('cart/show.html', {'gifts':gifts,
'total_price':total_price,
'form':form.as_widget()})
示例4: get_gift
def get_gift(request, idx):
gift = Gift.get_by_id(idx)
if not gift:
return redirect('/')
additional_gifts = Gift.all().filter('subcategory =', gift.subcategory).filter(
'name !=', gift.name).fetch(4)
return render_to_response('gift/get.html',
{'gift': gift,
'additional_gifts': additional_gifts,
'price_modif': GlobalPriceModif.get_price_modif()})
示例5: sync_gift_task
def sync_gift_task(request, task_id):
gift_id = memcache.get(task_id)
memcache.delete(task_id)
if gift_id:
try:
result = urlfetch.fetch(
'http://www.3dhero.ru/api/v2/product.json?id=%s' % gift_id
)
if result.status_code == 200:
result = simplejson.loads(result.content)
if result['success']:
model = result['result']
if model['id_1c']:
category = Category.all().filter('name =', u'Развивающие Игры').get()
if category:
group = Group.all().filter('category =', category).filter('name =', u'Фигурки Героев').get()
else:
group = None
gift = Gift(
name = model.get('name', ''),
id_1c = model['id_1c'],
catalogue_id = model.get('catalogue_id', ''),
barcode = model.get('barcode', ''),
brand = model.get('brand', ''),
country = model.get('country', ''),
material = model.get('material', ''),
gift_size = model.get('size', ''),
weight = model.get('weight',''),
box_size = model.get('box_size', ''),
master_box = model.get('box_amount', ''),
real_price = model.get('price_trade', 0.0),
price = model.get('price_retail', 0.0),
leftovers = model.get('leftovers', 0),
remote_leftovers = model.get('leftovers_on_way', 0),
to_sync = True
)
if category and group:
gift.category = category
gift.group = group
gift.put()
images = model.get('images', [])
if images:
for img in images:
def txn():
task_id = str(uuid.uuid4())
data = {'gift_id': gift.key().id(), 'img_url': img}
memcache.add(task_id, data, TASK_LIVE_TIMEOUT)
taskqueue.add(
url=url_for('sync/add_image_task', task_id=task_id),
transactional=True
)
db.run_in_transaction(txn)
except:
pass
return render_to_response('empty.html')
示例6: get_menu
def get_menu(request):
filters = request.session.get('filters', [])
if request.user.is_admin:
return render_to_response(
'categories_view.html',
{
'subcategories': Gift.get_subcategories_list(filters, is_admin=True),
'brand_list': Gift.get_brand_list(filters, is_admin=True)
})
return render_to_response(
'categories_view.html',
{
'subcategories': Gift.get_subcategories_list(filters),
'brand_list': Gift.get_brand_list(filters)
})
示例7: sync_new_task
def sync_new_task(request, uid):
logging.info("Create new gift from 5studio.ru with uid: %s" % uid)
url = 'http://www.5studio.ru/api/v1/get/gift.json?&uid=%s' % uid
result = urlfetch.fetch(url)
if result.status_code == 200:
j = simplejson.loads(result.content)
if len(j):
name = j.get('name', '').replace('\\"', '"')
name_origin = j.get('name_origin', '').replace('\\"', '"')
barcode = j.get('barcode', '')
description = j.get('description', '').replace('\\"', '"')
price = j.get('price', 0.0)
leftovers = j.get('leftovers', 0)
gift = Gift.all().filter('uid_5studio =', uid).fetch(1)
if gift:
gift = gift[0]
is_new = False
else:
is_new = True
gift = Gift(
uid_5studio=uid,
name=name,
name_origin=name_origin,
barcode=barcode,
description=description,
price=price,
leftovers=leftovers)
brand = j.get('brand', '').replace('\\"', '"')
if brand:
brand_obs = Brand.all().filter('brand =', brand)
if not brand_obs.count():
brand = Brand(brand=brand)
brand.put()
else:
brand = brand_obs.get()
gift.brand = brand
gift.category = get_category(j)
gift.subcategory = get_subcategory(j, gift.category)
gift.put()
if is_new or not gift.thumbs:
thumbs_url = j.get('thumbs_url', [])
for url in thumbs_url:
gift_uid = gift.key().id()
memcache.add('sync/add_image/%s' % gift_uid,
'http://%s' % url, 7200)
def txn():
taskqueue.add(url=url_for(
'sync/sync_add_image',
uid=gift.key().id()),
transactional=True)
db.run_in_transaction(txn)
return render_json_response({'api_msg': 'Ok', 'api_success': True})
示例8: export
def export():
writer = csv.writer(open('quick_export.csv', 'wb'))
writer.writerow(['Идентификатор',
'Название',
'Краткое описание',
'Полное описание'])
for gift in Gift.all():
name = gift.name
if name:
name = name.encode('utf-8')
else:
name = u''
short_description = gift.short_description
if short_description:
short_description = clear_data(short_description)
else:
short_description = u''
description = gift.description
if description:
description = clear_data(description)
else:
description = u''
writer.writerow([gift.uid,
name,
short_description.encode('utf-8'),
description.encode('utf-8')])
示例9: add_new_thumb
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/')
示例10: recalculate_order
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
示例11: get_counts
def get_counts(request):
counts = memcache.get('api_get_count')
if not counts:
coming_soon = Gift.accept_filters(filters=['coming_soon']).count()
on_sale = Gift.accept_filters(filters=['on_sale']).count()
no_sale = Gift.accept_filters(filters=['no_sale']).count()
total = coming_soon + on_sale + no_sale
if total:
counts = {
'coming_soon': coming_soon,
'on_sale': on_sale,
'no_sale': no_sale,
'total': total}
if counts:
memcache.set('api_get_count', counts, 7200)
return render_json_response(counts)
示例12: search
def search(request):
if request.method == 'POST':
text = request.form.get('q', '')
if not text:
return redirect('/')
gifts_list = Gift.all().filter('leftovers >', 0).search(text,
properties=['name'])
gifts_list = filter_leftovers(gifts_list)
if not gifts_list:
return redirect('/')
paginator = Paginator(gifts_list, 24)
try:
page = int(request.args.get('page', 1))
except ValueError:
page = 1
try:
gifts = paginator.page(page)
except (EmptyPage, InvalidPage):
gifts = paginator.page(paginator.num_pages())
categories = get_cat_subcat()
return render_to_response('index_page/main_page.html',
{'gifts': gifts,
'categories': categories[0],
'subcategories': categories[1],
'subcategories_keys': categories[2],
'price_modif': GlobalPriceModif.get_price_modif()})
else:
return redirect('/')
示例13: restore_from_trash
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)
示例14: move_to_trash
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)
示例15: upload_new_thumb
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('/')