本文整理汇总了Python中photos.models.Photo.get_name方法的典型用法代码示例。如果您正苦于以下问题:Python Photo.get_name方法的具体用法?Python Photo.get_name怎么用?Python Photo.get_name使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类photos.models.Photo
的用法示例。
在下文中一共展示了Photo.get_name方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: post
# 需要导入模块: from photos.models import Photo [as 别名]
# 或者: from photos.models.Photo import get_name [as 别名]
def post(self, *args, **kwargs):
print(self.request.POST)
if self.steps.current == '0':
if self.request.is_ajax() and self.request.FILES:
try:
temp_hash = self.request.POST.get('0-temp_hash')
uploaded_photos = Photo.objects.filter(temp_hash=temp_hash).count()
product = Product.objects.get(slug=self.kwargs.get('slug', None))
if uploaded_photos < product.image_total:
photo = self.request.FILES.get('file')
new_image = Photo(image=photo, temp_hash=self.request.POST.get('0-temp_hash'))
new_image.save()
response = {'file': []}
response['file'].append({
'id': '%s' % new_image.id,
'name': '%s' % new_image.image.name,
'size': '%d' % self.request.FILES.__sizeof__(),
'url': '%s' % new_image.smart.url,
'thumbnailUrl': '%s' % new_image.thumbnail.url,
'deleteUrl': '\/image\/delete\/%s' % new_image.id,
"deleteType": 'DELETE'
})
# Get the minimum image dimension for square crop
if new_image.smart.width >= new_image.smart.height:
image_dimension = new_image.smart.height
else:
image_dimension = new_image.smart.width
# Simulate initial crop with dummy coordinates.
filter_data = [{
'name': 'crop',
'params':
{'x': 0,
'y': 0,
'width': image_dimension,
'height': image_dimension,
'rotate': 0,
}
}]
# Crop and create the new Cropped object
result_image = apply_filters_to_image(new_image.smart.name, filter_data)
new_cropped_file, created = Cropped.objects.get_or_create(original=new_image)
new_cropped_file.image_cropped.save(new_image.get_name("crop_"), result_image)
return JsonResponse(response)
else:
return HttpResponseForbidden(self.request)
except Exception as e:
print("Exception Uploading the image", e.message)
pass
else:
if self.request.POST.get('0-uploaded_photo_count') == '0':
raise ValidationError("Ocurrio un error, recibimos un total de 0 fotos cargadas!")
elif self.steps.current == '1':
# TODO: Cambiar el json.loads porque no todos los exploradores pueden enviar el JSON con los resultados del sort, ej: iPhone.
try:
sorted_photo_list = json.loads(self.request.POST.get('1-photo_sort_list', None))
for index, sorted_photo in enumerate(sorted_photo_list):
photo = get_object_or_404(Photo, id=sorted_photo['id'])
Photo.objects.filter(id=sorted_photo['id']).update(sequence=index)
# photo.sequence = index
# photo.save()
except Exception as e:
print("AQUI2", e)
pass
# elif self.steps.current == '2':
# if not self.request.POST.get('wizard_goto_step'):
# product = Product.objects.get(slug=self.kwargs.get('slug', None))
# qty = self.request.POST['2-quantity']
# cart_id = self.request.POST.get('2-cart')
#
# prev_data = self.storage.get_step_data('0')
# if prev_data:
# temp_hash = prev_data.get('0-temp_hash', None)
#
# cart = Cart.objects.get(id=cart_id)
#
# photos = Photo.objects.filter(temp_hash=temp_hash)
#
# cart_item = CartItem.objects.create(cart=cart, product=product)
# cart_item.photo_set = photos
# cart_item.quantity = qty
# cart_item.line_total = product.price
# cart_item.save()
# return HttpResponseRedirect(reverse("cart"))
return super(UploadPhotosWizard, self).post(self.request, *args, **kwargs)