def single_upload_ajax(request): name = request.FILES["image"].name filename = generate_filename(name) handler = ImageHandlerSections() handler.load(filename, request.FILES["image"]) handler.save() url = handler.single_url() name = handler.original_filename() data = {"url": url, "name": name} return {"success": True, "data": data}
def save(self, commit=True): data = self.cleaned_data if data.get("photo") and not isinstance(data["photo"], basestring): if self.instance.photo and self.instance.image_handler and self.instance.image_handler.storage: self.instance.image_handler.delete() filename = generate_filename(data["photo"].name) handler = ImageHandlerUserPhoto() handler.load(filename, data["photo"]) handler.save_thumbnails("PNG") self.instance.photo = filename self.instance.friendly_name = data.get("friendly_name") self.instance.birth_date = data["birth_date"] self.instance.save()