本文整理汇总了Python中models.Item.delete方法的典型用法代码示例。如果您正苦于以下问题:Python Item.delete方法的具体用法?Python Item.delete怎么用?Python Item.delete使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类models.Item
的用法示例。
在下文中一共展示了Item.delete方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_model_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import delete [as 别名]
def test_model_item(self):
"Test item model"
type = ItemType(name='test')
type.save()
status = ItemStatus(name='test')
status.save()
obj = Item(name='test', item_type=type, status=status)
obj.save()
self.assertEquals('test', obj.name)
self.assertNotEquals(obj.id, None)
obj.delete()
示例2: items
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import delete [as 别名]
def items(request, item_id=None):
if request.method == 'POST':
data = request.POST
item = Item(name=data.get('name'), quantity=data.get('quantity'))
item.add()
if request.method == 'DELETE':
item = Item.objects.get(pk=item_id)
item.delete()
if request.method == 'PUT':
data = simplejson.loads(request.body)
item = Item.objects.get(pk=data.get('id'))
item.purchased = data.get('purchased')
item.save()
data = [dict(i) for i in Item.objects.all().values('id', 'name', 'quantity', 'purchased')]
return JsonResponse({'items': data})
示例3: api_item
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import delete [as 别名]
def api_item(request, item_pk=None):
created = False
if item_pk:
item = Item.objects.get(pk=item_pk)
if not item.created_by == request.user:
import pdb
pdb.set_trace()
return HttpResponse(status=403)
else:
item = Item()
item.created_by = request.user
created = True
if request.POST.get('delete'):
item.delete()
else:
expense = Expense.objects.get(pk=request.POST.get('expense'))
if not expense.created_by == request.user:
return HttpResponse(status=403)
item.expense = expense
item.description = request.POST.get('description')
item.amount = request.POST.get('amount')
item.save()
user_pks = request.POST.getlist('users')
item.users.clear()
for pk in user_pks:
user = User.objects.get(pk=pk)
item.users.add(user)
if request.is_ajax():
return HttpResponse(json.dumps({
'type': 'item',
'item_pk': item.pk,
'item_created': created,
'item_form': render_to_response('item_form.html', {'expense':item.expense, 'item':item}, context_instance = RequestContext(request)).content,
'empty_form': render_to_response('item_form.html', {'expense':item.expense}, context_instance = RequestContext(request)).content
}))
return HttpResponseRedirect("/%s" % item.expense_id)
示例4: finalizeItem
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import delete [as 别名]
def finalizeItem(batch_id, item_id, item_tasks_count):
item_tasks = []
for task_order in range(0, item_tasks_count):
item_tasks.append(Task(batch_id, item_id, task_order))
# the task with highest id for the specific item has all item data
last_task = item_tasks[-1]
item_data = last_task.item_data
item_data['timestamp'] = datetime.utcnow().isoformat("T") + "Z"
if item_data.has_key('status') and item_data['status'] == 'deleted':
whole_item_delete = True
else:
whole_item_delete = False
try:
old_item = Item(item_id)
except:
old_item = None
if old_item:
if not whole_item_delete:
item_data['image_meta'] = old_item.image_meta
else:
item_data['image_meta'] = {}
error = False
if not whole_item_delete:
for task in item_tasks:
if task.status == 'pending' or task.status == 'error':
error = True
# modification tasks never changes image_meta
elif task.type == 'mod':
pass
elif task.status == 'deleted':
# if the image is being really deleted not only being reshuffled
if not task.url in item_data['url']:
item_data['image_meta'].pop(task.url, None)
elif task.status == 'ok':
item_data['image_meta'][task.url] = task.image_meta
if not error:
if not (old_item and whole_item_delete):
item = Item(item_id, item_data)
ordered_image_meta = []
for url in item.url:
tmp = item.image_meta[url]
tmp['url'] = url
ordered_image_meta.append(tmp)
if CLOUDSEARCH_ITEM_DOMAIN is not None:
try:
cloudsearch = getCloudSearch(CLOUDSEARCH_ITEM_DOMAIN, 'document')
if old_item and whole_item_delete:
cloudsearch.delete(hashlib.sha512(item_id).hexdigest()[:128])
else:
cloudsearch.add(hashlib.sha512(item_id).hexdigest()[:128], {'id': item.id, 'title': item.title, 'creator': item.creator, 'source': item.source, 'institution': item.institution, 'institution_link': item.institution_link, 'license': item.license, 'description': item.description, 'url': json.dumps(item.url), 'timestamp': item.timestamp, 'image_meta': json.dumps(ordered_image_meta)})
cloudsearch.commit()
except:
if last_task.attempts < MAX_TASK_REPEAT * 2:
print '\nFailed Cloud Search attempt numb.: %s\nItem: %s\nError message:\n###\n%s###' % (last_task.attempts + 1, task.item_id, traceback.format_exc())
last_task.attempts += 1
last_task.status = 'pending'
last_task.type = 'cloud_search'
last_task.save()
rand = (last_task.attempts * 60) + random.randint(last_task.attempts * 60, last_task.attempts * 60 * 2)
return ingestQueue.apply_async(args=[batch_id, item_id, last_task.task_id], countdown=rand)
else:
last_task.status = 'error'
last_task.message = ERR_MESSAGE_CLOUDSEARCH
last_task.save()
if last_task.status == 'error':
cleanErrItem(item_id, len(item_data['image_meta']))
print "Item '%s' failed" % item_id
elif old_item and whole_item_delete:
old_item.delete()
print "Item '%s' deleted" % item_id
else:
item.save()
print "Item '%s' finalized" % item_id
else:
cleanErrItem(item_id, len(item_data['image_meta']))
print "Item '%s' failed" % item_id
return
示例5: post
# 需要导入模块: from models import Item [as 别名]
# 或者: from models.Item import delete [as 别名]
def post(self):
upload_files = self.get_uploads() # 'file' is file upload field in the form
blob_info = upload_files[0]
#self.redirect('/serve/%s' % blob_info.key())
blob_key = blob_info.key()
blob_reader = blobstore.BlobReader(blob_key)
document = blob_reader.read()
#self.response.out.write(document)
dom = xml.dom.minidom.parseString(document)
names = dom.getElementsByTagName("NAME")
xml_cat_name = names[0].toxml()
xml_cat_name = xml_cat_name.replace("<NAME>", "")
xml_cat_name = xml_cat_name.replace("</NAME>", "")
xml_item_names = []
for i in range(1, len(names)):
name = names[i].toxml()
name = name.replace("<NAME>", "")
name = name.replace("</NAME>", "")
xml_item_names.append(name)
currt_user = users.get_current_user()
account_key = db.Key.from_path('Account', currt_user.nickname())
account = db.get(account_key)
categories = Category.all()
categories.ancestor(account_key)
cat_names = []
for category in categories.run():
cat_names.append(category.cat_name)
### if category exists
if xml_cat_name in cat_names:
items = Item.all()
category = categories.filter("cat_name =", xml_cat_name)
category = category.get()
category_key = category.key()
items = items.ancestor(category_key)
item_names = []
for item in items:
item_names.append(item.item_name)
### add new items
for item_name in xml_item_names:
if item_name not in item_names:
item = Item(key_name=item_name, parent=category, item_name=item_name)
item.win = 0
item.lose = 0
item.put()
### delete old items
for item_name in item_names:
if item_name not in xml_item_names:
items = Item.all()
items = items.ancestor(category_key)
items.filter("item_name =", item_name)
item = items.get()
item.delete()
### if new category
else:
cat = Category(key_name=xml_cat_name, parent=account, cat_name=xml_cat_name)
cat.put()
for xml_item_name in xml_item_names:
item = Item(key_name=xml_item_name, parent=cat, item_name=xml_item_name)
item.win = 0
item.lose = 0
item.put()
self.redirect("/option?option=manage")