def edit_logo(request, slug): school = get_object_or_404(School, slug=slug) if request.method == 'POST': form = school_forms.SchoolLogoForm(request.POST, request.FILES, instance=school) if form.is_valid(): messages.success(request, _('Image updated')) form.save() return http.HttpResponseRedirect(reverse('school_edit_logo', kwargs={'slug': school.slug})) else: messages.error(request, _('There was an error uploading your image')) else: form = school_forms.SchoolLogoForm(instance=school) return render_to_response('schools/school_edit_logo.html', { 'school': school, 'form': form, 'logo_tab': True, }, context_instance=RequestContext(request))
def edit_logo_async(request, slug): school = get_object_or_404(School, slug=slug) form = school_forms.SchoolLogoForm(request.POST, request.FILES, instance=school) if form.is_valid(): instance = form.save() return http.HttpResponse(simplejson.dumps({ 'filename': instance.logo.name, })) return http.HttpResponse(simplejson.dumps({ 'error': 'There was an error uploading your image.', }))