diff --git a/tailbone/templates/about.mako b/tailbone/templates/about.mako
new file mode 100644
index 00000000..5f71b73b
--- /dev/null
+++ b/tailbone/templates/about.mako
@@ -0,0 +1,10 @@
+## -*- coding: utf-8 -*-
+<%inherit file="/base.mako" />
+
+<%def name="title()">About ${project_title}%def>
+
+
${project_title} ${project_version}
+
+% for name, version in packages.iteritems():
+ ${name} ${version}
+% endfor
diff --git a/tailbone/views/common.py b/tailbone/views/common.py
index b72ecbd8..3eca9de9 100644
--- a/tailbone/views/common.py
+++ b/tailbone/views/common.py
@@ -26,41 +26,81 @@ Various common views
from __future__ import unicode_literals, absolute_import
+import rattail
from rattail.mail import send_email
+from rattail.util import OrderedDict
-import formencode
+import formencode as fe
from pyramid import httpexceptions
-from formencode import validators
from pyramid_simpleform import Form
+import tailbone
from tailbone import forms
+from tailbone.views import View
-class Feedback(formencode.Schema):
+class Feedback(fe.Schema):
"""
Form schema for user feedback.
"""
allow_extra_fields = True
user = forms.validators.ValidUser()
- user_name = validators.NotEmpty()
- message = validators.NotEmpty()
+ user_name = fe.validators.NotEmpty()
+ message = fe.validators.NotEmpty()
-def feedback(request):
+class CommonView(View):
"""
- Generic view to present/handle the user feedback form.
+ Base class for common views; override as needed.
"""
- form = Form(request, schema=Feedback)
- if form.validate():
- data = dict(form.data)
- if data['user']:
- data['user_url'] = request.route_url('users.view', uuid=data['user'].uuid)
- send_email(request.rattail_config, 'user_feedback', data=data)
- request.session.flash("Thank you for your feedback.")
- return httpexceptions.HTTPFound(location=form.data['referrer'])
- return {'form': forms.FormRenderer(form)}
+ project_title = "Tailbone"
+ project_version = tailbone.__version__
+
+ def about(self):
+ """
+ Generic view to show "about project" info page.
+ """
+ return {
+ 'project_title': self.project_title,
+ 'project_version': self.project_version,
+ 'packages': self.get_packages(),
+ }
+
+ def get_packages(self):
+ """
+ Should return the full set of packages which should be displayed on the
+ 'about' page.
+ """
+ return OrderedDict([
+ ('rattail', rattail.__version__),
+ ('Tailbone', tailbone.__version__),
+ ])
+
+ def feedback(self):
+ """
+ Generic view to present/handle the user feedback form.
+ """
+ form = Form(self.request, schema=Feedback)
+ if form.validate():
+ data = dict(form.data)
+ if data['user']:
+ data['user_url'] = self.request.route_url('users.view', uuid=data['user'].uuid)
+ send_email(self.rattail_config, 'user_feedback', data=data)
+ self.request.session.flash("Thank you for your feedback.")
+ return httpexceptions.HTTPFound(location=form.data['referrer'])
+ return {'form': forms.FormRenderer(form)}
+
+ @classmethod
+ def defaults(cls, config):
+
+ config.add_route('about', '/about')
+ config.add_view(cls, attr='about', route_name='about',
+ renderer='/about.mako')
+
+ config.add_route('feedback', '/feedback')
+ config.add_view(cls, attr='feedback', route_name='feedback',
+ renderer='/feedback.mako')
def includeme(config):
- config.add_route('feedback', '/feedback')
- config.add_view(feedback, route_name='feedback', renderer='/feedback.mako')
+ CommonView.defaults(config)