Created
July 28, 2011 19:56
-
-
Save pydanny/1112403 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Forms.py | |
| from django import forms | |
| from django.conf import settings | |
| from apps.common.utils.widgets import FileBrowserFrontendWidget | |
| from uni_form.helpers import FormHelper, Submit, Reset | |
| from uni_form.helpers import Layout, Fieldset, Row, Column, HTML | |
| from models import Lead | |
| import os | |
| class LeadSubmissionForm(forms.ModelForm): | |
| @property | |
| def helper(self): | |
| """ helper property """ | |
| helper = FormHelper() | |
| helper.form_tag = False | |
| helper.form_id = "lead_submission_form" | |
| layout = Layout( | |
| Fieldset('', | |
| 'parent_or_student', 'attending_school', 'how_much', 'year_of_study', | |
| 'zip_code', 'email_address', 'graduate_year', 'graduate_month', | |
| 'email_loan_results' | |
| ) | |
| ) | |
| helper.add_layout(layout) | |
| # Submit button(s) | |
| submit = Submit('submit','Submit') | |
| helper.add_input(submit) | |
| return helper | |
| class Meta: | |
| model = Lead | |
| fields = ['parent_or_student', 'attending_school', 'how_much', 'year_of_study', 'zip_code', 'email_address', 'graduate_year', 'graduate_month', 'email_loan_results'] | |
| # Models.py | |
| class Lead(TitleAndSlugModel): | |
| """ | |
| A lead submitted through the site (i.e. someone that has at-least submitted the search form | |
| """ | |
| PARENT_OR_STUDENT = get_namedtuple_choices('PARENT_OR_STUDENT', ( | |
| (0, 'PARENT', 'Parent'), | |
| (1, 'STUDENT', 'Student'), | |
| )) | |
| YEARS_OF_STUDY = get_namedtuple_choices('YEARS_OF_STUDY', ( | |
| (0, 'ONE', '1'), | |
| (1, 'TWO', '2'), | |
| (2, 'THREE', '3'), | |
| (3, 'FOUR', '4'), | |
| )) | |
| parent_or_student = models.PositiveIntegerField(choices=PARENT_OR_STUDENT.get_choices(), default=0) | |
| attending_school = models.ForeignKey(School) | |
| how_much = models.DecimalField(max_digits=10, decimal_places=2) | |
| year_of_study = models.PositiveIntegerField(choices=YEARS_OF_STUDY.get_choices(), default=0) | |
| zip_code = models.CharField(max_length=8) | |
| email_address = models.EmailField(max_length=255) | |
| graduate_year = models.IntegerField() | |
| graduate_month = models.IntegerField() | |
| email_loan_results = models.BooleanField(default=False) | |
| def __unicode__(self): | |
| return "%s - %s" % (self.email_address, self.attending_school) | |
| # Views.py | |
| @render_to("lender/main_views/home.html") | |
| def home(request): | |
| form = LeadSubmissionForm(request.POST or None) | |
| if form.is_valid(): | |
| form.save() | |
| return HttpResponseRedirect(reverse("search_results")) | |
| testimonials = Testimonial.objects.filter(published=True)[:3] | |
| return {'lead_submission_form':form, 'testimonials': testimonials} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Going to try and test this again to see if I can figure it out. Thanks for the input :)