Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add an additional one column layout for the contact form view. Use de…

…corators for view config. Add fanstatic filter to development.ini.
  • Loading branch information...
commit 2ee20fc007fa1695eaf36cbc8f35e6aee9ffc962 1 parent a2c4fbe
@disko disko authored
View
1  AUTHORS.txt
@@ -4,6 +4,7 @@ Authors
- Tetsuya Morimoto
- Christian Neumann
- Marco Scheidhuber
+- Andreas Kaiser
For a complete list of contributors, see
https://github.com/chrneumann/kotti_contactform/graphs/contributors
View
7 CHANGES.txt
@@ -4,14 +4,16 @@ History
0.2 - Unreleased
----------------
+- Add an additional one column layout for the contact form view.
+- Use decorators for view config
0.1.1 - 2012-12-28
------------------
- Changes for compatibility with Kotti>=0.8. These changes
- are not backward compatibel. If you want to use kotti_contactform
+ are not backward compatible. If you want to use kotti_contactform
with Kotti<=0.7.x then pin to 0.1.1a5.
- - Use form classes for the form views instead of deprecated generic functions.
+- Use form classes for the form views instead of deprecated generic functions.
- Use pyramid.includes instead of deprecated kotti.includes.
@@ -43,7 +45,6 @@ History
- Attachment as optional setting.
- Added database migration with alembic.
-
0.1.0b4 - 2012-05-21
--------------------
View
6 README.rst
@@ -7,7 +7,7 @@ to your site. |build status|_
`Find out more about Kotti`_
-Development happens at https://github.com/chrneumann/kotti_contactform
+Development happens at https://github.com/Kotti/kotti_contactform
.. |build status| image:: https://secure.travis-ci.org/chrneumann/kotti_contactform.png?branch=master
.. _build status: http://travis-ci.org/chrneumann/kotti_contactform
@@ -39,8 +39,8 @@ database. The migration is performed with `alembic`_ and Kotti's
console script ``kotti-migrate``. To migrate, run ``kotti-migrate
upgrade_all --scripts=kotti_contactform:alembic``.
-For integration of alembic in your environment please refer to the
-`alembic documentation`_. If you have problems with the upgrade,
+For integration of alembic in your environment please refer to the
+`alembic documentation`_. If you have problems with the upgrade,
please create a new issue in the `tracker`_.
.. _alembic: http://pypi.python.org/pypi/alembic
View
14 development.ini
@@ -1,20 +1,22 @@
[app:main]
use = egg:kotti
+filter-with = fanstatic
pyramid.reload_templates = true
pyramid.debug_authorization = false
pyramid.debug_notfound = false
pyramid.debug_routematch = false
pyramid.debug_templates = true
-pyramid.includes = pyramid_debugtoolbar
- pyramid_tm
+pyramid.includes =
+ pyramid_debugtoolbar
+ pyramid_tm
sqlalchemy.url = sqlite:///%(here)s/Kotti.db
-
kotti.site_title = Kotti with contact forms
kotti.secret = qwerty
-
-# kotti_contactform specific configuration:
kotti.configurators = kotti_contactform.kotti_configure
+[filter:fanstatic]
+use = egg:fanstatic#fanstatic
+
[server:main]
use = egg:waitress#main
host = 0.0.0.0
@@ -50,4 +52,4 @@ formatter = generic
[formatter_generic]
format = %(asctime)s %(levelname)-5.5s [%(name)s][%(threadName)s] %(message)s
-# End logging configuration
+# End logging configuration
View
11 kotti_contactform/__init__.py
@@ -1,10 +1,19 @@
from pyramid.i18n import TranslationStringFactory
+
_ = TranslationStringFactory('kotti_contactform')
def kotti_configure(settings):
- settings['pyramid.includes'] += ' kotti_contactform.views'
+ settings['pyramid.includes'] += ' kotti_contactform'
settings['kotti.available_types'] += (
' kotti_contactform.resources.ContactForm'
)
settings['kotti.alembic_dirs'] += ' kotti_contactform:alembic'
+
+
+def includeme(config):
+ config.include('pyramid_mailer')
+ config.add_translation_dirs('kotti_contactform:locale')
+ config.add_static_view('static-kotti_contactform',
+ 'kotti_contactform:static')
+ config.scan()
View
12 kotti_contactform/resources.py
@@ -1,29 +1,37 @@
+from kotti.resources import Content
+from sqlalchemy import Boolean
from sqlalchemy import Column
from sqlalchemy import ForeignKey
from sqlalchemy import Integer
from sqlalchemy import String
from sqlalchemy import Text
-from sqlalchemy import Boolean
-from kotti.resources import Content
+
from kotti_contactform import _
class ContactForm(Content):
+
__tablename__ = 'contact_forms'
__mapper_args__ = dict(polymorphic_identity='contact_form')
+
id = Column('id', Integer, ForeignKey('contents.id'), primary_key=True)
recipient = Column(String(255), nullable=False)
body = Column(Text)
show_attachment = Column(Boolean(), nullable=False)
+
type_info = Content.type_info.copy(
name=u'ContactForm',
title=_(u'Contact form'),
add_view=u'add_contactform',
addable_to=[u'Document'],
+ selectable_default_views=[
+ ('view-1-col', u'1 column layout'),
+ ],
)
def __init__(self, recipient=u"", body=u"",
show_attachment=True, **kwargs):
+
super(ContactForm, self).__init__(**kwargs)
self.recipient = recipient
self.body = body
View
21 kotti_contactform/templates/contactform-view-one-column.pt
@@ -0,0 +1,21 @@
+<!DOCTYPE html>
+<html xmlns="http://www.w3.org/1999/xhtml"
+ xml:lang="en"
+ xmlns:tal="http://xml.zope.org/namespaces/tal"
+ xmlns:i18n="http://xml.zope.org/namespaces/i18n"
+ i18n:domain="kotti_contactform"
+ metal:use-macro="api.macro('kotti:templates/view/master.pt')">
+ <article metal:fill-slot="content" class="contactform-view content">
+ <h1>${api.context.title}</h1>
+ <p class="description">
+ ${api.context.description}
+ </p>
+ ${structure: api.context.body}
+ <div tal:condition="form">
+ ${structure: form}
+ </div>
+ <div tal:condition="appstruct">
+ <p class="alert alert-success" i18n:translate="">Thanks for your submission!</p>
+ </div>
+ </article>
+</html>
View
0  kotti_contactform/templates/contactform-view.pt → ...actform/templates/contactform-view-two-columns.pt
File renamed without changes
View
2  kotti_contactform/tests/__init__.py
@@ -1,2 +0,0 @@
-def setup_dummy_mailer(config):
- config.include('pyramid_mailer.testing')
View
2  kotti_contactform/tests/browser.txt
@@ -8,7 +8,7 @@ Setup and Login
>>> from kotti import testing
>>> tools = testing.setUpFunctional(
... **{'kotti.configurators': 'kotti_contactform.kotti_configure',
- ... 'pyramid.includes': 'kotti_contactform.tests.setup_dummy_mailer',
+ ... 'pyramid.includes': 'pyramid_mailer.testing',
... })
>>> browser = tools['Browser']()
>>> ctrl = browser.getControl
View
92 kotti_contactform/views.py
@@ -1,26 +1,29 @@
import colander
-from pyramid_mailer import get_mailer
-from pyramid_mailer.message import Attachment
-from pyramid_mailer.message import Message
-from pyramid.i18n import get_locale_name
-from deform.widget import RichTextWidget
-from deform.widget import TextAreaWidget
-from deform.widget import HiddenWidget
-from deform import Form
-from deform import FileData
from deform import Button
+from deform import FileData
+from deform import Form
from deform import ValidationFailure
from deform.widget import FileUploadWidget
+from deform.widget import HiddenWidget
+from deform.widget import RichTextWidget
+from deform.widget import TextAreaWidget
from kotti.views.edit import ContentSchema
from kotti.views.form import AddFormView
from kotti.views.form import EditFormView
-from kotti.views.util import template_api
from kotti.views.form import FileUploadTempStore
-from kotti_contactform.resources import ContactForm
+from kotti.views.util import template_api
+from pyramid.i18n import get_locale_name
+from pyramid.view import view_config
+from pyramid_mailer import get_mailer
+from pyramid_mailer.message import Attachment
+from pyramid_mailer.message import Message
+
from kotti_contactform import _
+from kotti_contactform.resources import ContactForm
class ContactFormSchema(ContentSchema):
+
recipient = colander.SchemaNode(colander.String())
body = colander.SchemaNode(
colander.String(),
@@ -36,17 +39,25 @@ class ContactFormSchema(ContentSchema):
)
-class ContactformEditForm(EditFormView):
- schema_factory = ContactFormSchema
-
-
+@view_config(name=ContactForm.type_info.add_view,
+ permission='add',
+ renderer='kotti:templates/edit/node.pt')
class ContactformAddForm(AddFormView):
schema_factory = ContactFormSchema
add = ContactForm
item_type = _(u"Contact Form")
+@view_config(name='edit',
+ context=ContactForm, permission='edit',
+ renderer='kotti:templates/edit/node.pt')
+class ContactformEditForm(EditFormView):
+
+ schema_factory = ContactFormSchema
+
+
def mail_submission(context, request, appstruct):
+
mailer = get_mailer(request)
message = Message(subject=appstruct['subject'],
sender=appstruct['name'] + ' <'
@@ -63,7 +74,16 @@ def mail_submission(context, request, appstruct):
mailer.send(message)
+@view_config(name='view',
+ context=ContactForm,
+ permission='view',
+ renderer='kotti_contactform:templates/contactform-view-two-columns.pt')
+@view_config(name='view-1-col',
+ context=ContactForm,
+ permission='view',
+ renderer='kotti_contactform:templates/contactform-view-one-column.pt')
def view_contactform(context, request):
+
locale_name = get_locale_name(request)
tmpstore = FileUploadTempStore(request)
@@ -82,6 +102,7 @@ def maybe_show_attachment(node, kw):
del node['attachment']
class SubmissionSchema(colander.MappingSchema):
+
name = colander.SchemaNode(colander.String(),
title=_("Full Name"))
sender = colander.SchemaNode(colander.String(),
@@ -125,44 +146,3 @@ class SubmissionSchema(colander.MappingSchema):
'appstruct': appstruct,
'api': template_api(context, request),
}
-
-
-def includeme_edit(config):
- config.add_view(
- ContactformEditForm,
- context=ContactForm,
- name='edit',
- permission='edit',
- renderer='kotti:templates/edit/node.pt',
- )
-
- config.add_view(
- ContactformAddForm,
- name=ContactForm.type_info.add_view,
- permission='add',
- renderer='kotti:templates/edit/node.pt',
- )
-
-
-def includeme_view(config):
- config.add_view(
- view_contactform,
- context=ContactForm,
- name='view',
- permission='view',
- renderer='templates/contactform-view.pt',
- )
- config.add_static_view('static-kotti_contactform',
- 'kotti_contactform:static')
-# config.add_static_view('static', 'deform:static')
-
-
-def includeme(config):
- config.include('pyramid_mailer')
- includeme_edit(config)
- includeme_view(config)
- config.add_translation_dirs('kotti_contactform:locale/',
- # last two should get included by kotti
- 'colander:locale',
- 'deform:locale',
- )
View
6 setup.cfg
@@ -28,11 +28,11 @@ addopts =
--ignore=kotti_contactform/templates/
--strict
--pep8
- kotti_contactform/
+ kotti_contactform/tests
python_files = test*py
markers =
user: mark test to be run as the given user
-#pep8ignore = E501 E122 E123 E125 E128 E711
+pep8ignore = E501 E122 E123 E125 E128 E711
[aliases]
-dev = develop easy_install kotti_contactform[testing]
+dev = develop easy_install kotti_contactform[testing]
Please sign in to comment.
Something went wrong with that request. Please try again.