def apply(request): if request.method == 'POST': form = ApplicationForm(request.POST, request.FILES) context = {} if form.is_valid(): l1_address = get_lot_address(form.cleaned_data['lot_1_address']) lot1_info = { 'ppn': form.cleaned_data['lot_1_ppn'], 'address': l1_address, # 'planned_use': form.cleaned_data.get('lot_1_use') } try: lot1 = Lot.objects.get(ppn=lot1_info['ppn']) except Lot.DoesNotExist: lot1 = Lot(**lot1_info) lot1.save() c_address_info = { 'street': form.cleaned_data['contact_street'], 'city': form.cleaned_data['contact_city'], 'state': form.cleaned_data['contact_state'], 'zip_code': form.cleaned_data['contact_zip_code'] } c_address, created = Address.objects.get_or_create(**c_address_info) owned_address = get_lot_address(form.cleaned_data['owned_address']) app_info = { 'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'owned_address': owned_address, 'plan_image': form.cleaned_data['plan_image'], 'contact_address': c_address, 'phone': form.cleaned_data['phone'], 'phone_2': form.cleaned_data['phone_2'], 'email': form.cleaned_data.get('email'), 'how_heard': form.cleaned_data.get('how_heard'), 'tracking_id': unicode(uuid4()), 'owned_live': form.cleaned_data.get('owned_live'), 'owned_properties': form.cleaned_data.get('owned_properties'), 'owned_properties_info': form.cleaned_data.get('owned_properties_info'), 'lot_1_use' : form.cleaned_data.get('lot_1_use'), 'lot_1_improvements' : form.cleaned_data.get('lot_1_improvements'), 'lot_1_descr' : form.cleaned_data.get('lot_1_descr'), 'fencing_descr': form.cleaned_data.get('fencing_descr'), 'fencing_cost': form.cleaned_data.get('fencing_cost'), 'landscaping_descr': form.cleaned_data.get('landscaping_descr'), 'landscaping_cost': form.cleaned_data.get('landscaping_cost'), 'apron_descr': form.cleaned_data.get('apron_descr'), 'apron_cost': form.cleaned_data.get('apron_cost'), 'other_descr': form.cleaned_data.get('other_descr'), 'other_cost': form.cleaned_data.get('other_cost'), } app = Application(**app_info) app.save() app.lot_set.add(lot1) app.save() html_template = get_template('apply_html_email.html') text_template = get_template('apply_text_email.txt') lots = [l for l in app.lot_set.all()] context = Context({'app': app, 'lots': lots, 'host': request.get_host()}) html_content = html_template.render(context) text_content = text_template.render(context) subject = 'Large Lots Application for %s %s' % (app.first_name, app.last_name) from_email = settings.EMAIL_HOST_USER to_email = [from_email, '*****@*****.**'] #TODO: Get mailserver configured and running - ASKoiman 2/10/2015 ## if provided, send confirmation email to applicant if app.email: to_email.append(app.email) ## send email confirmation to settings.EMAIL_HOST_USER msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) msg.attach_alternative(html_content, 'text/html') msg.send() return HttpResponseRedirect('/apply-confirm/%s/' % app.tracking_id) else: #TODO: Update this section pursuant to above one - ASKoiman context['lot_1_address'] = form['lot_1_address'].value() context['lot_1_ppn'] = form['lot_1_ppn'].value() context['lot_1_use'] = form['lot_1_use'].value() context['lot_1_improvements'] = form['lot_1_improvements'].value() context['lot_1_descr'] = form['lot_1_descr'].value() context['owned_address'] = form['owned_address'].value() context['owned_live'] = form['owned_live'].value() context['owned_properties'] = form['owned_properties'].value() context['owned_properties_info'] = form['owned_properties_info'].value() context['fencing_descr'] = form['fencing_descr'].value() context['fencing_cost'] = form['fencing_cost'].value() context['landscaping_descr'] = form['landscaping_descr'].value() context['landscaping_cost'] = form['landscaping_cost'].value() context['apron_descr'] = form['apron_descr'].value() context['apron_cost'] = form['apron_cost'].value() context['other_descr'] = form['other_descr'].value() context['other_cost'] = form['other_cost'].value() context['plan_image'] = form['plan_image'].value() context['first_name'] = form['first_name'].value() context['last_name'] = form['last_name'].value() # context['organization'] = form['organization'].value() context['phone'] = form['phone'].value() context['phone_2'] = form['phone_2'].value() context['email'] = form['email'].value() context['contact_street'] = form['contact_street'].value() context['contact_city'] = form['contact_city'].value() context['contact_state'] = form['contact_state'].value() context['contact_zip_code'] = form['contact_zip_code'].value() context['how_heard'] = form['how_heard'].value() context['terms'] = form['terms'].value() context['form'] = form fields = [f for f in form.fields] context['error_messages'] = OrderedDict() for field in fields: label = form.fields[field].label error = form.errors.get(field) if label and error: context['error_messages'][label] = form.errors[field][0] return render(request, 'apply.html', context) else: if application_active(): form = ApplicationForm() else: form = None return render(request, 'apply.html', {'form': form})
def apply(request): if request.method == 'POST': form = ApplicationForm(request.POST, request.FILES) context = {} address_parts = [ 'street_number', 'street_dir', 'street_name', 'street_type' ] if form.is_valid(): l1_address = get_lot_address(form.cleaned_data['lot_1_address'], form.cleaned_data['lot_1_pin']) lot1_info = { 'pin': form.cleaned_data['lot_1_pin'], 'address': l1_address, 'planned_use': form.cleaned_data.get('lot_1_use') } try: lot1 = Lot.objects.get(pin=lot1_info['pin']) except Lot.DoesNotExist: lot1 = Lot(**lot1_info) lot1.save() lot2 = None if form.cleaned_data.get('lot_2_pin'): l2_address = get_lot_address( form.cleaned_data['lot_2_address'], form.cleaned_data['lot_2_pin']) lot2_info = { 'pin': form.cleaned_data['lot_2_pin'], 'address': l2_address, 'planned_use': form.cleaned_data.get('lot_2_use') } try: lot2 = Lot.objects.get(pin=lot2_info['pin']) except Lot.DoesNotExist: lot2 = Lot(**lot2_info) lot2.save() c_address_info = { 'street': form.cleaned_data['contact_street'], 'city': form.cleaned_data['contact_city'], 'state': form.cleaned_data['contact_state'], 'zip_code': form.cleaned_data['contact_zip_code'] } c_address, created = Address.objects.get_or_create( **c_address_info) owned_address = get_lot_address(form.cleaned_data['owned_address'], form.cleaned_data['owned_pin']) app_info = { 'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'organization': form.cleaned_data.get('organization'), 'owned_address': owned_address, 'owned_pin': form.cleaned_data['owned_pin'], 'deed_image': form.cleaned_data['deed_image'], 'contact_address': c_address, 'phone': form.cleaned_data['phone'], 'email': form.cleaned_data.get('email'), 'how_heard': form.cleaned_data.get('how_heard'), 'tracking_id': unicode(uuid4()), 'pilot': settings.CURRENT_PILOT, } app = Application(**app_info) app.save() app.lot_set.add(lot1) if lot2: app.lot_set.add(lot2) app.save() html_template = get_template('apply_html_email.html') text_template = get_template('apply_text_email.txt') lots = [l for l in app.lot_set.all()] context = Context({ 'app': app, 'lots': lots, 'host': request.get_host() }) html_content = html_template.render(context) text_content = text_template.render(context) subject = 'Large Lots Application for %s %s' % (app.first_name, app.last_name) from_email = settings.EMAIL_HOST_USER to_email = [from_email] # if provided, send confirmation email to applicant if app.email: to_email.append(app.email) # send email confirmation to [email protected] msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) msg.attach_alternative(html_content, 'text/html') msg.send() return HttpResponseRedirect('/apply-confirm/%s/' % app.tracking_id) else: context['lot_1_address'] = form['lot_1_address'].value() context['lot_1_pin'] = form['lot_1_pin'].value() context['lot_1_use'] = form['lot_1_use'].value() context['lot_2_address'] = form['lot_2_address'].value() context['lot_2_pin'] = form['lot_2_pin'].value() context['lot_2_use'] = form['lot_2_use'].value() context['owned_address'] = form['owned_address'].value() context['owned_pin'] = form['owned_pin'].value() context['deed_image'] = form['deed_image'].value() context['first_name'] = form['first_name'].value() context['last_name'] = form['last_name'].value() context['organization'] = form['organization'].value() context['phone'] = form['phone'].value() context['email'] = form['email'].value() context['contact_street'] = form['contact_street'].value() context['contact_city'] = form['contact_city'].value() context['contact_state'] = form['contact_state'].value() context['contact_zip_code'] = form['contact_zip_code'].value() context['how_heard'] = form['how_heard'].value() context['terms'] = form['terms'].value() context['form'] = form fields = [f for f in form.fields] context['error_messages'] = OrderedDict() for field in fields: label = form.fields[field].label error = form.errors.get(field) if label and error: context['error_messages'][label] = form.errors[field][0] return render(request, 'apply.html', context) else: if application_active(request): form = ApplicationForm() else: form = None return render(request, 'apply.html', {'form': form})
def apply(request): if request.method == 'POST': form = ApplicationForm(request.POST, request.FILES) context = {} address_parts = ['street_number', 'street_dir', 'street_name', 'street_type'] if form.is_valid(): l1_address = get_lot_address(form.cleaned_data['lot_1_address'], form.cleaned_data['lot_1_pin']) lot1_info = { 'pin': form.cleaned_data['lot_1_pin'], 'address': l1_address, 'planned_use': form.cleaned_data.get('lot_1_use') } try: lot1 = Lot.objects.get(pin=lot1_info['pin']) except Lot.DoesNotExist: lot1 = Lot(**lot1_info) lot1.save() lot2 = None if form.cleaned_data.get('lot_2_pin'): l2_address = get_lot_address(form.cleaned_data['lot_2_address'], form.cleaned_data['lot_2_pin']) lot2_info = { 'pin': form.cleaned_data['lot_2_pin'], 'address': l2_address, 'planned_use': form.cleaned_data.get('lot_2_use') } try: lot2 = Lot.objects.get(pin=lot2_info['pin']) except Lot.DoesNotExist: lot2 = Lot(**lot2_info) lot2.save() c_address_info = { 'street': form.cleaned_data['contact_street'], 'city': form.cleaned_data['contact_city'], 'state': form.cleaned_data['contact_state'], 'zip_code': form.cleaned_data['contact_zip_code'] } c_address, created = Address.objects.get_or_create(**c_address_info) owned_address = get_lot_address(form.cleaned_data['owned_address'], form.cleaned_data['owned_pin']) app_info = { 'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'organization': form.cleaned_data.get('organization'), 'owned_address': owned_address, 'owned_pin': form.cleaned_data['owned_pin'], 'deed_image': form.cleaned_data['deed_image'], 'contact_address': c_address, 'phone': form.cleaned_data['phone'], 'email': form.cleaned_data.get('email'), 'how_heard': form.cleaned_data.get('how_heard'), 'tracking_id': unicode(uuid4()), 'pilot': settings.CURRENT_PILOT, } app = Application(**app_info) app.save() app.lot_set.add(lot1) if lot2: app.lot_set.add(lot2) app.save() html_template = get_template('apply_html_email.html') text_template = get_template('apply_text_email.txt') lots = [l for l in app.lot_set.all()] context = Context({'app': app, 'lots': lots, 'host': request.get_host()}) html_content = html_template.render(context) text_content = text_template.render(context) subject = 'Large Lots Application for %s %s' % (app.first_name, app.last_name) from_email = settings.EMAIL_HOST_USER to_email = [from_email] # if provided, send confirmation email to applicant if app.email: to_email.append(app.email) # send email confirmation to [email protected] msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) msg.attach_alternative(html_content, 'text/html') msg.send() return HttpResponseRedirect('/apply-confirm/%s/' % app.tracking_id) else: context['lot_1_address'] = form['lot_1_address'].value() context['lot_1_pin'] = form['lot_1_pin'].value() context['lot_1_use'] = form['lot_1_use'].value() context['lot_2_address'] = form['lot_2_address'].value() context['lot_2_pin'] = form['lot_2_pin'].value() context['lot_2_use'] = form['lot_2_use'].value() context['owned_address'] = form['owned_address'].value() context['owned_pin'] = form['owned_pin'].value() context['deed_image'] = form['deed_image'].value() context['first_name'] = form['first_name'].value() context['last_name'] = form['last_name'].value() context['organization'] = form['organization'].value() context['phone'] = form['phone'].value() context['email'] = form['email'].value() context['contact_street'] = form['contact_street'].value() context['contact_city'] = form['contact_city'].value() context['contact_state'] = form['contact_state'].value() context['contact_zip_code'] = form['contact_zip_code'].value() context['how_heard'] = form['how_heard'].value() context['terms'] = form['terms'].value() context['form'] = form fields = [f for f in form.fields] context['error_messages'] = OrderedDict() for field in fields: label = form.fields[field].label error = form.errors.get(field) if label and error: context['error_messages'][label] = form.errors[field][0] return render(request, 'apply.html', context) else: if application_active(request): form = ApplicationForm() else: form = None return render(request, 'apply.html', {'form': form})
def apply(request): if request.method == 'POST': form = ApplicationForm(request.POST, request.FILES) context = {} if form.is_valid(): l1_address = get_lot_address(form.cleaned_data['lot_1_address']) lot1_info = { 'ppn': form.cleaned_data['lot_1_ppn'], 'address': l1_address, # 'planned_use': form.cleaned_data.get('lot_1_use') } try: lot1 = Lot.objects.get(ppn=lot1_info['ppn']) except Lot.DoesNotExist: lot1 = Lot(**lot1_info) lot1.save() c_address_info = { 'street': form.cleaned_data['contact_street'], 'city': form.cleaned_data['contact_city'], 'state': form.cleaned_data['contact_state'], 'zip_code': form.cleaned_data['contact_zip_code'] } c_address, created = Address.objects.get_or_create(**c_address_info) owned_address = get_lot_address(form.cleaned_data['owned_address']) app_info = { 'first_name': form.cleaned_data['first_name'], 'last_name': form.cleaned_data['last_name'], 'owned_address': owned_address, 'plan_image': form.cleaned_data['plan_image'], 'contact_address': c_address, 'phone': form.cleaned_data['phone'], 'phone_2': form.cleaned_data['phone_2'], 'email': form.cleaned_data.get('email'), 'how_heard': form.cleaned_data.get('how_heard'), 'tracking_id': unicode(uuid4()), 'owned_live': form.cleaned_data.get('owned_live'), 'owned_properties': form.cleaned_data.get('owned_properties'), 'owned_properties_info': form.cleaned_data.get('owned_properties_info'), 'lot_1_use' : form.cleaned_data.get('lot_1_use'), 'lot_1_improvements' : form.cleaned_data.get('lot_1_improvements'), 'lot_1_descr' : form.cleaned_data.get('lot_1_descr'), 'fencing_descr': form.cleaned_data.get('fencing_descr'), 'fencing_cost': form.cleaned_data.get('fencing_cost'), 'landscaping_descr': form.cleaned_data.get('landscaping_descr'), 'landscaping_cost': form.cleaned_data.get('landscaping_cost'), 'apron_descr': form.cleaned_data.get('apron_descr'), 'apron_cost': form.cleaned_data.get('apron_cost'), 'other_descr': form.cleaned_data.get('other_descr'), 'other_cost': form.cleaned_data.get('other_cost'), } app = Application(**app_info) app.save() app.lot_set.add(lot1) app.save() html_template = get_template('apply_html_email.html') text_template = get_template('apply_text_email.txt') lots = [l for l in app.lot_set.all()] context = Context({'app': app, 'lots': lots, 'host': request.get_host()}) html_content = html_template.render(context) text_content = text_template.render(context) subject = 'Large Lots Application for %s %s' % (app.first_name, app.last_name) from_email = settings.EMAIL_HOST_USER to_email = [from_email] #TODO: Get mailserver configured and running - ASKoiman 2/10/2015 ## if provided, send confirmation email to applicant if app.email: to_email.append(app.email) ## send email confirmation to settings.EMAIL_HOST_USER msg = EmailMultiAlternatives(subject, text_content, from_email, to_email) msg.attach_alternative(html_content, 'text/html') msg.send() return HttpResponseRedirect('/apply-confirm/%s/' % app.tracking_id) else: #TODO: Update this section pursuant to above one - ASKoiman context['lot_1_address'] = form['lot_1_address'].value() context['lot_1_ppn'] = form['lot_1_ppn'].value() context['lot_1_use'] = form['lot_1_use'].value() context['owned_address'] = form['owned_address'].value() context['plan_image'] = form['plan_image'].value() context['first_name'] = form['first_name'].value() context['last_name'] = form['last_name'].value() # context['organization'] = form['organization'].value() context['phone'] = form['phone'].value() context['phone_2'] = form['phone_2'].value() context['email'] = form['email'].value() context['contact_street'] = form['contact_street'].value() context['contact_city'] = form['contact_city'].value() context['contact_state'] = form['contact_state'].value() context['contact_zip_code'] = form['contact_zip_code'].value() context['how_heard'] = form['how_heard'].value() context['terms'] = form['terms'].value() context['form'] = form fields = [f for f in form.fields] context['error_messages'] = OrderedDict() for field in fields: label = form.fields[field].label error = form.errors.get(field) if label and error: context['error_messages'][label] = form.errors[field][0] return render(request, 'apply.html', context) else: if application_active(): form = ApplicationForm() else: form = None return render(request, 'apply.html', {'form': form})