Customizing Contacts form

17 views
Skip to first unread message

Brabadu

unread,
Feb 15, 2011, 12:22:08 PM2/15/11
to djang...@googlegroups.com
Hi all!

I need to customize contacts form in LFC. 
I've already made it look like I want, but I need to add some more fields and tricky validation on message that is going to be sent. 

I inherited from a lfc.forms.ContactForm, added fields and methods I need, created templatetag to add my form to template context, but validation doesn't work.
For added field "topic" method clean_topic isn't running.

As I understand, lfc.forms.ContactForm is being passed to view (from lfc/urls.py) so my form and all customization in it is ignored:

# Contact form
urlpatterns += patterns('contact_form.views',
    url(r'^contact$', "contact_form", { "form_class" : ContactForm }, name='contact_form'),
    url(r'^sent$', direct_to_template, { 'template': 'contact_form/contact_form_sent.html' }, name='contact_form_sent'),
)

Looks like ContentType (with portlets and others) are static things, so I can't do forms with validation and things with them. As much as creating of new views is quite restricted.

So could you direct me: What is the best way to customize contact form?

Maciej Wisniowski

unread,
Feb 15, 2011, 2:55:04 PM2/15/11
to djang...@googlegroups.com
> I need to customize contacts form in LFC.
> I've already made it look like I want, but I need to add some more
> fields and tricky validation on message that is going to be sent.
>
> I inherited from a lfc.forms.ContactForm, added fields and methods I
> need, created templatetag to add my form to template context, but
> validation doesn't work.
> For added field "topic" method clean_topic isn't running.
>
> As I understand, lfc.forms.ContactForm is being passed to view (from
> lfc/urls.py) so my form and all customization in it is ignored:
>
> # Contact form
> urlpatterns += patterns('contact_form.views',
> url(r'^contact$', "contact_form", { "form_class" : ContactForm },
> name='contact_form'),
> url(r'^sent$', direct_to_template, { 'template':
> 'contact_form/contact_form_sent.html' }, name='contact_form_sent'),
> )
In your urls.py put urlpatterns for contact form, containing modified
form and template BEFORE importing lfc.urls, like:

# Contact Form


urlpatterns += patterns('contact_form.views',

url(r'^contact$', "contact_form", { 'success_url':
'contact-thank-you', "form_class" : MyContactForm }, name='contact_form'),
url(r'^contact-thank-you$', direct_to_template, { 'template':

'contact_form/contact_form_sent.html' }, name='contact_form_sent'),
)

# LFC Blog
urlpatterns += patterns("",
(r'', include('lfc_blog.urls')),
)

# LFC
urlpatterns += patterns('',
(r'^manage/', include('lfc.manage.urls')),
(r'', include('lfc.urls')),
)


> Looks like ContentType (with portlets and others) are static things, so
> I can't do forms with validation and things with them. As much as
> creating of new views is quite restricted.

I'm not sure what you mean... what are static things?


--
Maciej Wisniowski
http://natcam.pl

Boryslav Larin

unread,
Feb 15, 2011, 3:13:48 PM2/15/11
to djang...@googlegroups.com
Thanks for you response, Maciej!

2011/2/15 Maciej Wisniowski <pigl...@gmail.com>:

Changing existing LFC codebase isn't the best way for me to do it.
I need to do it in a separate app, but can't see any way to make LFC
look for urls.py or views.py in my app. Looks like if there's no
straight way to do it, I'd have to somehow monkey patch urlhandler to
consider my urls, not LFC defaults.

>
>
>> Looks like ContentType (with portlets and others) are static things, so
>> I can't do forms with validation and things with them. As much as
>> creating of new views is quite restricted.
>
> I'm not sure what you mean... what are static things?

I mean they are used to show some kind of content but are not good
user interaction (filling forms, validating and showing errors to give
opportunity to fix them). Maybe there's somewhere an example of using
forms in LFC ContentTypes like polls or user comments for an article?

>
>
> --
> Maciej Wisniowski
> http://natcam.pl
>

--
Boryslav Larin
063 272 21 44 | bra...@gmail.com
Twitter: http://twitter.com/brabadu

Maciej Wisniowski

unread,
Feb 15, 2011, 3:27:10 PM2/15/11
to djang...@googlegroups.com
> Changing existing LFC codebase isn't the best way for me to do it.
> I need to do it in a separate app, but can't see any way to make LFC
> look for urls.py or views.py in my app. Looks like if there's no
> straight way to do it, I'd have to somehow monkey patch urlhandler to
> consider my urls, not LFC defaults.
You don't have to change LFC code. Modify urls.py in your project. Also,
if you have to add new app do it in the same way as with all other
django apps: INSTALLED_APPS and include in urls.py (in project).

Boryslav Larin

unread,
Feb 15, 2011, 5:36:11 PM2/15/11
to djang...@googlegroups.com
2011/2/15 Maciej Wisniowski <pigl...@gmail.com>:

Thanks, Maciej! Sorted it out. That's right what I needed.

>
> --
> Maciej Wisniowski
> http://natcam.pl
>

--

Reply all
Reply to author
Forward
0 new messages