def form(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)

    SurveyFormset = inlineformset_factory(Survey, Child, form=ChildForm, extra=1, can_delete=False)

    formerror = False

    if request.method == 'POST':
        surveyform = SurveyForm(request.POST, school=school)

        if surveyform.is_valid():
            survey = surveyform.save(commit=False)
            survey.school = school
            survey.update_distance()
            survey.created = datetime.now()
            survey.ip = request.META['REMOTE_ADDR']

            surveyformset = SurveyFormset(request.POST, instance=survey)
            if surveyformset.is_valid():
                survey.save()
                surveyformset.save()

                return render_to_response(
                    'survey/thanks.html',
                    context_instance=RequestContext(request)
                )
            else:
                surveyformset = SurveyFormset(request.POST, instance=Survey())
                formerror = True
        else:
            surveyformset = SurveyFormset(request.POST, instance=Survey())
            formerror = True
    else:
        survey = Survey()
        surveyform = SurveyForm(instance=survey)
        surveyformset = SurveyFormset(instance=survey)

    return render_to_response('survey/form.html', {
            'formerror': formerror,
            'school': school,
            'surveyform': surveyform,
            'surveyformset': surveyformset,
        },
        context_instance=RequestContext(request)
    )