From 1c0c148294937899c811b49f121cccb5f2616d5f Mon Sep 17 00:00:00 2001 From: Lance Edgar Date: Sun, 1 May 2016 20:39:05 -0500 Subject: [PATCH] Add initial/basic user feedback form support --- tailbone/forms/__init__.py | 3 +- tailbone/templates/feedback.mako | 53 +++++++++++++++++++++++++ tailbone/views/__init__.py | 1 + tailbone/views/common.py | 66 ++++++++++++++++++++++++++++++++ 4 files changed, 122 insertions(+), 1 deletion(-) create mode 100644 tailbone/templates/feedback.mako create mode 100644 tailbone/views/common.py diff --git a/tailbone/forms/__init__.py b/tailbone/forms/__init__.py index 64689621..14e5b1a3 100644 --- a/tailbone/forms/__init__.py +++ b/tailbone/forms/__init__.py @@ -32,4 +32,5 @@ from .alchemy import AlchemyForm from .fields import AssociationProxyField from .renderers import * -from tailbone.forms import renderers +from . import renderers +from . import validators diff --git a/tailbone/templates/feedback.mako b/tailbone/templates/feedback.mako new file mode 100644 index 00000000..e8f03cc7 --- /dev/null +++ b/tailbone/templates/feedback.mako @@ -0,0 +1,53 @@ +## -*- coding: utf-8 -*- +<%inherit file="/base.mako" /> + +<%def name="title()">User Feedback + +<%def name="head_tags()"> + ${parent.head_tags()} + + + +
+ ${form.begin()} + ${form.hidden('user', value=request.user.uuid if request.user else None)} + +
+

+ Questions, suggestions, comments, complaints, etc. regarding this website + are welcome and may be submitted below.  Messages will be delivered to + the local IT department, and possibly others. +

+
+ +## % if error: +##
${error}
+## % endif + + % if request.user: + ${form.field_div('user_name', form.hidden('user_name', value=unicode(request.user)) + unicode(request.user), label="Your Name")} + % else: + ${form.field_div('user_name', form.text('user_name'), label="Your Name")} + % endif + + ${form.field_div('referrer', form.hidden('referrer', value=request.get_referrer()) + request.get_referrer(), label="Referring URL")} + + ${form.field_div('message', form.textarea('message', rows=15))} + +
+ ${form.submit('send', "Send Message")} + ${h.link_to("Cancel", request.get_referrer(), class_='button')} +
+ + ${form.end()} +
diff --git a/tailbone/views/__init__.py b/tailbone/views/__init__.py index f2f8bbdf..3c155780 100644 --- a/tailbone/views/__init__.py +++ b/tailbone/views/__init__.py @@ -53,6 +53,7 @@ def includeme(config): renderer='/home.mako') config.include('tailbone.views.core') + config.include('tailbone.views.common') config.include('tailbone.views.auth') config.include('tailbone.views.batches') diff --git a/tailbone/views/common.py b/tailbone/views/common.py new file mode 100644 index 00000000..b72ecbd8 --- /dev/null +++ b/tailbone/views/common.py @@ -0,0 +1,66 @@ +# -*- coding: utf-8 -*- +################################################################################ +# +# Rattail -- Retail Software Framework +# Copyright © 2010-2016 Lance Edgar +# +# This file is part of Rattail. +# +# Rattail is free software: you can redistribute it and/or modify it under the +# terms of the GNU Affero General Public License as published by the Free +# Software Foundation, either version 3 of the License, or (at your option) +# any later version. +# +# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY +# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS +# FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for +# more details. +# +# You should have received a copy of the GNU Affero General Public License +# along with Rattail. If not, see . +# +################################################################################ +""" +Various common views +""" + +from __future__ import unicode_literals, absolute_import + +from rattail.mail import send_email + +import formencode +from pyramid import httpexceptions +from formencode import validators +from pyramid_simpleform import Form + +from tailbone import forms + + +class Feedback(formencode.Schema): + """ + Form schema for user feedback. + """ + allow_extra_fields = True + user = forms.validators.ValidUser() + user_name = validators.NotEmpty() + message = validators.NotEmpty() + + +def feedback(request): + """ + Generic view to present/handle the user feedback form. + """ + 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)} + + +def includeme(config): + config.add_route('feedback', '/feedback') + config.add_view(feedback, route_name='feedback', renderer='/feedback.mako')