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