本文整理汇总了Python中apps.gift.models.Gift.all方法的典型用法代码示例。如果您正苦于以下问题:Python Gift.all方法的具体用法?Python Gift.all怎么用?Python Gift.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类apps.gift.models.Gift
的用法示例。
在下文中一共展示了Gift.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: quick_import
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
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
示例2: index
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
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('/')
示例3: search
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
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('/')
示例4: export
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
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')])
示例5: preview_newsletter
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def preview_newsletter(request, key):
newsletter = Newsletter.get(key)
gifts = []
if newsletter.gifts:
gifts_split = newsletter.gifts.split(",")
for gift in gifts_split:
try:
gift = gift.strip()
obj = Gift.all().filter("uid =", gift).get()
if obj:
gifts.append(obj)
except Exception:
pass
managers = []
users = UserProfile.all().filter("is_send_newsletter =", True).filter("email !=", None)
if newsletter.type != 999:
users = users.filter("newsletter_type =", newsletter.type)
files = []
for file_key in newsletter.n_price_list:
file_ = File.get(file_key)
if file_:
files.append(file_)
return render_to_response(
"postman/admin/newsletters/preview.html",
{"newsletter": newsletter, "gifts": gifts, "key": key, "files": files, "managers": managers, "users": users},
)
示例6: get_gift_mem
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def get_gift_mem(uid_):
if not uid_:
return None
try:
gift = Gift.all().filter('uid =', uid_).get()
return prefetch_refprops([gift], Gift.category, Gift.group)[0]
except Exception:
return None
示例7: get_list_all
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def get_list_all(request):
list_gifts = memcache.get('api_get_list_all')
if not list_gifts:
gifts = Gift.all()
if gifts:
list_gifts = [gift.uid for gift in gifts]
memcache.add('api_get_list_all', list_gifts, 7200)
return render_json_response(list_gifts)
示例8: sync_new_task
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
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})
示例9: sync_gift
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def sync_gift(request):
for gift in Gift.all():
if gift.uid_5studio:
def txn():
taskqueue.add(url=url_for('sync/sync_gift_task',
key=gift.key()),
transactional=True)
db.run_in_transaction(txn)
return render_to_response('sync/sync_gift.html')
示例10: get_gift
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
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()})
示例11: trash_ajax
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def trash_ajax(request):
if request.method == 'POST':
last_gift = request.values.get('last_gift')
if last_gift:
last_gift = int(last_gift)
gifts = gifts = Gift.all().filter('in_trash =', True)
if gifts:
gifts = gifts.fetch(50, last_gift)
return render_to_response('gift/list.html', {'gifts': gifts})
return render_to_response("empty.html")
示例12: update_images
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def update_images(imgs_path):
#cat_path = os.path.(imgs_path)
if not os.path.exists(imgs_path):
print "Error! Path of images directory not exists!"
return False
gifts = Gift.all()
for i, gift in enumerate(gifts):
print i + 1
if gift.thumbs:
continue
fill_obj(gift, imgs_path)
示例13: export
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def export():
export_path = 'experiments/images/'
if not os.path.exists(export_path):
os.mkdir(export_path)
for gift in Gift.all():
if gift.thumbs:
path = os.path.join(export_path, gift.uid)
os.mkdir(path)
for i,thumb in enumerate(gift.thumbs):
img = internal_thumb_image(thumb, size="700x700")
if img:
fimage = open(os.path.join(path,'%s.jpg' % i), 'wb')
fimage.write(img)
示例14: all_brands
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def all_brands(request):
objs_tmp = Brand.all()
brands = {}
brands_ids = {}
objs = []
for o in objs_tmp:
if o.gifts.filter('leftovers >', 0).count():
objs.append(o)
for brand in objs:
brands[brand.brand] = [Gift.all().filter('brand =', brand).fetch(3)]
brands_ids[brand.brand] = brand.key().id()
return render_to_response('index_page/brands.html',
{'brands': brands, 'brands_ids': brands_ids})
示例15: all
# 需要导入模块: from apps.gift.models import Gift [as 别名]
# 或者: from apps.gift.models.Gift import all [as 别名]
def all(request):
gifts_list = Gift.all()
paginator = Paginator(gifts_list, 26)
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())
return render_to_response('gift/admin/all.html', {'gifts':gifts})