예제 #1
0
파일: views.py 프로젝트: shacker/itaco
def apply(request):
    '''
    To avoid creating Users, Families and Students before a family is accepted, and to
    closely mimic the PDF application form, we store everything flat here. Later, if people
    are accepted, we copy fields from an app record into the appropriate models.
    '''

    # Submit a new application
    if request.POST:
        form = ApplicationForm(request.POST, files=request.FILES)

        if form.is_valid():
            # Don't commit the save until we've added in the fields we need to set
            app = form.save(commit=False)
            app.appdate = datetime.now()

            # If user is logged in, they are already a Crestmont family and this
            # app should be associated with that family
            if request.user.is_authenticated():
                app.family = request.user.profile.family

            app.save()

            # Upon successful submit, redirect to the app fee view for this applicant.
            return HttpResponseRedirect(reverse('app_fee', args=[app.id]))
        else:
            # print form.errors
            pass
    else:
        form = ApplicationForm()

    return render_to_response('apply/apply.html', locals(),
        context_instance=RequestContext(request),
    )
예제 #2
0
def application_save(request, app_id):
    application = get_object_or_404(Application,
                                    id=app_id,
                                    profile=request.user.get_profile())

    # application no longer valid?
    if not application.session.active:
        request.user.message_set.create(
            message=
            'The application session has ended; you cannot edit your application any more.'
        )
        return HttpResponseRedirect(reverse('applications'))

    if request.method == 'POST' and request.is_ajax():
        form = ApplicationForm(request.POST, instance=application)

        if form.is_valid():
            app = form.save()
            return HttpResponse("success")

        return render_to_response('apply/application/form.html', {
            'application': application,
            'form': form
        },
                                  context_instance=RequestContext(request))

    return HttpResponseForbidden()
예제 #3
0
def apply(request):
    if request.method == 'POST':
        form = ApplicationForm(request.POST)
        if form.is_valid():
            p = form.save(commit=False)
            p.date = datetime.now()
            form.save()
    else:
        form = ApplicationForm()
    args = {
        'form': form
    }
    return render(request, 'apply/apply.html', args)
예제 #4
0
def application_save(request, app_id):
    application = get_object_or_404(Application, id=app_id, profile=request.user.get_profile())
    
    # application no longer valid?
    if not application.session.active:
        request.user.message_set.create(message='The application session has ended; you cannot edit your application any more.')
        return HttpResponseRedirect(reverse('applications'))

    if request.method == 'POST' and request.is_ajax():
        form = ApplicationForm(request.POST, instance=application)
        
        if form.is_valid():
            app = form.save()
            return HttpResponse("success")
            
        return render_to_response('apply/application/form.html',
                                  {'application': application,
                                   'form': form
                                  },
                                  context_instance=RequestContext(request))
    
    return HttpResponseForbidden()
예제 #5
0
def apply(request):
    """Display the form to add a new Application to the database."""
    if request.method == 'POST':
        form = ApplicationForm(request.POST)
        if form.is_valid():  # All validation rules pass; form is savable.
            form.save()

            return http.HttpResponseRedirect(reverse('thanks'))
    else:
        form = ApplicationForm()

    return jingo.render(request, 'apply/apply.html', {'form': form})
예제 #6
0
def application_edit(request, app_id):
    application = get_object_or_404(Application,
                                    id=app_id,
                                    profile=request.user.get_profile())

    # application no longer valid?
    if not application.session.active:
        request.user.message_set.create(
            message=
            'The application session has ended; you cannot edit your application any more.'
        )
        return HttpResponseRedirect(
            reverse('applications_detail', kwargs={'app_id': application.id}))

    form = ApplicationForm(instance=application)

    # render response.  (no processing done here; that's all elsewhere in AJAX)
    return render_to_response('apply/application/apply.html', {
        "application": application,
        "form": form,
    },
                              context_instance=RequestContext(request))
예제 #7
0
 def test_portfolio_website_field_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(
         form.fields["portfolio_website"].label == "Portfolio website")
예제 #8
0
 def test_update_profile_is_bool(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertIsInstance(form.fields["update_profile"], BooleanField)
예제 #9
0
 def test_health_conditions_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(
         form.fields["health_conditions"].label == "Health conditions")
예제 #10
0
 def test_veteran_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["veteran"].label == "Veteran")
예제 #11
0
 def test_ethnicity_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["ethnicity"].label == "Ethnicity")
예제 #12
0
 def test_race_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["race"].label == "Race")
예제 #13
0
 def test_cover_letter_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["cover_letter"].label == "Cover letter")
예제 #14
0
 def test_gender_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["gender"].label == "Gender")
예제 #15
0
 def test_last_name_field_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["last_name"].label == "Last name")
예제 #16
0
 def test_phone_field_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["phone"].label == "Phone")
예제 #17
0
 def test_zip_code_field_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["zip_code"].label == "Zip code")
예제 #18
0
 def test_address_field_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["address_line"].label == "Address line")
예제 #19
0
 def test_email_field_label(self):
     form = ApplicationForm(instance=self.candidate)
     self.assertTrue(form.fields["email"].label == "Email")