Skip to content

Commit

Permalink
Troubleshooting CropperJS
Browse files Browse the repository at this point in the history
  • Loading branch information
abkruse committed Dec 23, 2016
1 parent 6dba4c7 commit 5b4602d
Show file tree
Hide file tree
Showing 3 changed files with 9 additions and 13 deletions.
3 changes: 2 additions & 1 deletion members/templates/members/profile_image_edit.html
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,9 @@ <h3 style='text-align:center;'>Edit Your Profile Image:</h3>
});

$("#profile_image_form").submit(function(){
var img = $("#image-preview").cropper('getCroppedCanvas').toDataURL('image/jpeg');
// add the cropped image data to the form, then submit.
$("#id_cropped_image_data").val($("#image-preview").cropper('getCroppedCanvas').toDataURL().match(/data:image\/(png|jpeg);base64,(.*)$/)[2])
$("#id_cropped_image_data").val(img);
return true;
})
</script>
Expand Down
12 changes: 6 additions & 6 deletions members/views/profile.py
Original file line number Diff line number Diff line change
Expand Up @@ -303,12 +303,12 @@ def edit_photo(request, username):

if request.method == 'POST':
form = ProfileImageForm(request.POST, request.FILES)
try:
if form.is_valid():
form.save()
return HttpResponseRedirect(reverse('member_profile', kwargs={'username': request.user.username}))
except Exception as e:
page_message = str(e)
# try:
# if form.is_valid():
# form.save()
# return HttpResponseRedirect(reverse('member_profile', kwargs={'username': request.user.username}))
# except Exception as e:
# page_message = str(e)
else:
form = ProfileImageForm()

Expand Down
7 changes: 1 addition & 6 deletions nadine/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -220,11 +220,6 @@ def save_cropped_image(raw_img_data, upload_path):
img_data = base64.b64decode(raw_img_data)
filename = "%s.jpeg" % upload_path

# upload_abs_path = os.path.join(settings.MEDIA_ROOT, upload_path)
# if not os.path.exists(upload_abs_path):
# os.makedirs(upload_abs_path)
# full_file_name = os.path.join(upload_abs_path, filename)

with open(filename, 'wb') as f:
f.write(img_data)
f.close()
Expand All @@ -237,7 +232,7 @@ class ProfileImageForm(forms.Form):

def save(self):
user = User.objects.get(username=self.cleaned_data['username'])
# Delete the old photo before we save a new one

try:
img_data = self.cleaned_data['cropped_image_data']
if (not img_data) or img_data is None or len(img_data) == 0:
Expand Down

0 comments on commit 5b4602d

Please sign in to comment.