Isn’t it even simpler to just {% extends "page/form.html" %} in index.html ?


Le mardi 20 mai 2014 09:24:44 UTC+2, aleksiy a écrit :
>
> Hello!
>
> I created small contact form on Home page by may be wrong, but quite 
> simple way - without programming at all
> 1) Create regular mezzanine form in admin with URL "contact-form",
> 2) Open form on site and look for fields names,
> 3) Hardcode form fields in index.html template using generated fields 
> names and action="/contact-form/" (and don't forget {% csrf_token %} ) 
>
> works fine for me!
>
> воскресенье, 18 мая 2014 г., 15:43:34 UTC+3 пользователь bob hosk написал:
>>
>> I've made a custom HomePage model, so I can edit the home page content 
>> (headers etc)
>> from the admin easily. I'm trying to add a 'Contact us' form to the 
>> bottom of this page.
>>
>> In my 'myproject/mytheme' dir I have 'page_processors.py' containing
>>
>> from django import forms
>> from django.http import HttpResponseRedirect
>> from mezzanine.pages.page_processors import processor_for
>> from .models import HomePage
>>
>> class ContactForm(forms.Form):
>>     subject = forms.CharField(max_length=100, initial='The subject...', 
>> required=True)
>>     message = forms.CharField(max_length= 5000, widget=forms.Textarea, 
>> initial='Hello, ', required=True)
>>     sender = forms.EmailField(initial='Your e-mail...')  
>>     rchoices= (
>>               ('WORK','Hire Me'),
>>               ('PROB','Site problems'),
>>               ('OTH', 'Other'),
>>               ) 
>>     regarding = ChoiceField(widget=forms.Select(), choices=rchoices, 
>> blank_choice='Regarding?', initial='blank_choice')
>>
>> @processor_for(HomePage)
>> def contact_form(request, page):
>>     form = ContactForm() 
>>     if request.method == 'POST':
>>         form = ContactForm(request.POST) 
>>         if form.is_valid(): # All validation rules pass
>>             
>>             subject = form.cleaned_data['subject']
>>             message = form.cleaned_data['message']
>>             sender = form.cleaned_data['sender']
>>             recipients = ['[email protected]']
>>             print message
>>             if cc_myself:
>>                 recipients.append(sender)
>>
>>             from django.core.mail import send_mail
>>             send_mail(subject, message, sender, recipients)
>>
>>             redirect = request.path + "?submitted=true"
>>             return HttpResponseRedirect(redirect) # Redirect after POST
>>
>>     return {'form': form}
>>
>> As for the template for the custom home page, it {% extends 
>> "pages/page.html" %},
>> and at the bottom of the block I have
>>
>> {{ block.super }}
>> {% if request.GET.sent %}
>>     {% editable page.form.response %}
>>     {{ page.form.response|richtext_filters|safe }}
>>     {% endeditable %}
>> {% else %}
>>     {% with page.form as page_form %}
>>     {% editable page_form.content %}
>>     {{ page_form.content|richtext_filters|safe }}
>>     {% endeditable %}
>>     {% endwith %}
>>
>>     {% errors_for form %}
>>
>>     <form class="mezzanine-form" method="post"{% if form.is_multipart %} 
>> enctype="multipart/form-data"{% endif %}>
>>         {% fields_for form %}
>>         <div class="form-actions">
>>             <input class="btn btn-primary btn-lg" type="submit" value="{{ 
>> page.form.button_text }}">
>>         </div>
>>     </form>
>> {% endif %}
>>
>> which I copied from 'mezzanine/forms/templates/pages/form.html' mostly. 
>>
>> This gives a variable not found error when the homepage is loaded. If 
>> instead I did
>> {% fields_for page.form %} then I don't get an error but nor do the 
>> fields appear to be rendered.
>>
>> How do I get this to work?
>>
>>
>>
>>
>>
>>

-- 
You received this message because you are subscribed to the Google Groups 
"Mezzanine Users" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to [email protected].
For more options, visit https://groups.google.com/d/optout.

Reply via email to