Add basic 'about' page with some package versions

This commit is contained in:
Lance Edgar 2016-11-28 18:28:33 -06:00
parent b2d7e14ef7
commit ee6d3195c5
2 changed files with 68 additions and 18 deletions

View file

@ -0,0 +1,10 @@
## -*- coding: utf-8 -*-
<%inherit file="/base.mako" />
<%def name="title()">About ${project_title}</%def>
<h2>${project_title} ${project_version}</h2>
% for name, version in packages.iteritems():
<h3>${name} ${version}</h3>
% endfor

View file

@ -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):
"""
Base class for common views; override as needed.
"""
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(request, schema=Feedback)
form = Form(self.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.")
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)