Created
December 12, 2011 16:59
-
-
Save anonymous/1468190 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
#handle_uploaded_image.py | |
def handle_uploaded_image(photo, caption, source, more_info): | |
photo_dir = '%s/uploaded_photos/Not_Published/%Y/%m/%d' % settings.MEDIA_ROOT | |
photo_destination = open(photo_dir, 'wb+') | |
for chunk in photo.chunks(): | |
destination.write(chunk) | |
photo_destination.close() | |
info_file = '%s/uploaded_photos/Not_Published/%Y/%m/%d/PHOTO_INFO.txt' % settings.MEDIA_ROOT | |
write_info = "name: %s\n caption: %s\n source: %s\n more_info: %s\n\n" % photo.name, caption, source, more_info | |
photo_info_destination = open(info_file, 'a') | |
photo_info_destination.write(write_info) | |
photo_info_destination.close() | |
#views.py | |
def submit_image(request): | |
if request.method == 'POST': | |
form = UploadImageForm(request.POST, request.FILES) | |
if form.is_valid(): | |
uploadedImage = form.cleaned_data['image'] | |
caption = form.cleaned_data['caption'] | |
source = form.cleaned_data['source'] | |
more_info = form.cleaned_data['more_info'] | |
handle_uploaded_image(uploadedImage, caption, source, more_info) | |
return redirect('photos.views.upload_success') | |
else: | |
form = UploadImageForm() | |
return render(request,'photos/upload.html', {'form': form}) | |
def upload_success(request): | |
return render(request, 'photos/submit-success.html') |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment