def add_screenshot(request): """ Received POST request to add a new screenshot. """ img_form = ScreenshotForm(request.POST, request.FILES) if img_form.is_valid(): # Somehow (not sure how yet) the file name is slugified, so that there # will never be characters such as ";", "#", "&" etc in the names # We benefit from that by allowing the magnifier setting to be # specified after a ";" character. img = models.Screenshot(img_file_raw=img_form.\ cleaned_data['spc_image_upload']) img.save() msg = ('<div class="spc-item-upload-success" style="float: left;">' 'Upload successful. Insert the image in your description as' ' <tt>:image:`%s`</tt><br>' 'Want a <b>smaller</b> image? e.g. scaled down to 40%%: ' ' <tt>:image:`%s;40`</tt><br></div>') %\ (img.img_file_raw.name.partition('/')[2], img.img_file_raw.name.partition('/')[2]) return HttpResponse(msg) else: msg = ('<div class="spc-field-error" style="float: left; font-style: ' 'italic;">%s</div>') % img_form.errors.get('spc_image_upload')[0] return HttpResponse(msg)
def add_screenshot(request): """ Received POST request to add a new screenshot. """ if not (request.method == 'POST' and \ request.user.is_authenticated() ): raise Http404 img_form = ScreenshotForm(request.POST, request.FILES) if img_form.is_valid(): # Somehow (not sure how yet) the file name is slugified, so that there # will never be characters such as ";", "#", "&" etc in the names # We benefit from that by allowing the magnifier setting to be # specified after a ";" character. try: img = models.Screenshot(img_file_raw=img_form.\ cleaned_data['spc_image_upload']) img.save() msg = ('Upload successful. Insert the image in your description as' ' <tt>:image:`%s`</tt><br>' '<br>' '<i>Want a smaller image? e.g. scaled down to 40%%:</i> ' ' <tt>:image:`%s;40`</tt><br>') %\ (img.img_file_raw.name.partition('/')[2], img.img_file_raw.name.partition('/')[2]) except Exception, e: msg = 'Error on server, please try again \n' + str(e) return HttpResponse(msg)