def school_edit(request, district_slug, school_slug, **kwargs):

    # check if district exists
    district = get_object_or_404(District.objects, slug__iexact=district_slug)

    # get school in district
    school = get_object_or_404(School.objects, districtid=district, slug__iexact=school_slug)

    # translate to lat/lon
    school.geometry.transform(4326)

    class BaseSurveySetFormSet(BaseModelFormSet):
        def __init__(self, *args, **kwargs):
            super(BaseSurveySetFormSet, self).__init__(*args, **kwargs)
            self.queryset = SurveySet.objects.filter(school=school).order_by('-begin')

    surveysets = SurveySet.objects.filter(school=school)
    SurveySetFormSet = modelformset_factory(
        SurveySet, formset=BaseSurveySetFormSet, form=SurveySetForm,
        can_delete=True, extra=1
    )

    if request.method == 'POST':
        formset = SurveySetFormSet(request.POST)
        if formset.is_valid():
            sets = formset.save(commit=False)
            for surveyset in sets:
                surveyset.school = school
                surveyset.save()

            formset = SurveySetFormSet()
    else:
        #formset = SurveySetFormSet()
        formset = SurveySetFormSet()

    surveys = Survey.objects.filter(school=school)
    count_day = surveys.filter(created__gte=datetime.today() - timedelta(hours=24)).count()
    count_week = surveys.filter(created__gte=datetime.today() - timedelta(days=7)).count()

    return render_to_response('survey/school_edit.html', {
            'school': school,
            'district': district,
            'surveys': surveys,
            'count_day': count_day,
            'count_week': count_week,
            'formset': formset,
            'surveysets': surveysets,
            'now': datetime.now()
        },
        context_instance=RequestContext(request)
    )