Beispiel #1
0
    def view(self, request):
        f = AddWishForm(request.user, request.REQUEST)
        if f.is_valid():
            f.save()
            title = f.cleaned_data["title"]

            image = ImageRipper().rip_one_image(title.encode("utf-8"))

            if image != None:
                filename = request.user.username + str(f.instance.id) + ".jpg"
                image_path = os.path.join(MEDIA_ROOT, "wishlists/", filename)
                save_fixed_resolution_image(image, image_path, image_max_size)
                image_url = "/static/user/wishlists/{0}".format(filename)
                thumbnail_path = init_thumbnail(image_path).name
                thumbnail_url = "/static/user/wishlists/{0}".format(os.path.basename(thumbnail_path))
            else:
                image_url = "/static/img/product.jpg"
                thumbnail_url = "/static/img/icon.jpg"

            f.instance.image = image_url
            f.instance.thumbnail = thumbnail_url
            f.instance.save()

            return super(AddWishView, self).view(
                request, {"title": title, "thumbnail_url": thumbnail_url, "id": f.instance.id}
            )
        else:
            return super(AddWish, self).view(request, {"errors": f.errors, "form": f})
Beispiel #2
0
	def view( self, request ):
		upload_file = request.FILES[ 'upload' ]
		filename = upload_file.name
		filename2 = while_path_exists( os.path.join( MEDIA_ROOT, "img/{0}".format( filename ) ) )
		url = "{0}img/{1}".format( MEDIA_URL, filename2 )
		
		# resize/crop image
		save_fixed_resolution_image( request.FILES[ 'upload' ], os.path.join( MEDIA_ROOT, "img/{0}".format( filename2 ) ), 400 )
		
		return super( UploadView, self ).view( request, { 'url': url, 'CKEditorFuncNum': request.GET[ 'CKEditorFuncNum' ] } )