Add initial/basic user feedback form support

This commit is contained in:
Lance Edgar 2016-05-01 20:39:05 -05:00
parent 4ec8fdcf82
commit 1c0c148294
4 changed files with 122 additions and 1 deletions

View file

@ -32,4 +32,5 @@ from .alchemy import AlchemyForm
from .fields import AssociationProxyField from .fields import AssociationProxyField
from .renderers import * from .renderers import *
from tailbone.forms import renderers from . import renderers
from . import validators

View file

@ -0,0 +1,53 @@
## -*- coding: utf-8 -*-
<%inherit file="/base.mako" />
<%def name="title()">User Feedback</%def>
<%def name="head_tags()">
${parent.head_tags()}
<style type="text/css">
div.field-wrapper div.field input[type=text] {
width: 25em;
}
div.field-wrapper div.field textarea {
width: 50em;
}
div.buttons {
margin-left: 15em;
}
</style>
</%def>
<div class="form">
${form.begin()}
${form.hidden('user', value=request.user.uuid if request.user else None)}
<br />
<p>
Questions, suggestions, comments, complaints, etc. regarding this website
are welcome and may be submitted below.&nbsp; Messages will be delivered to
the local IT department, and possibly others.
</p>
<br />
## % if error:
## <div class="error">${error}</div>
## % 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))}
<div class="buttons">
${form.submit('send', "Send Message")}
${h.link_to("Cancel", request.get_referrer(), class_='button')}
</div>
${form.end()}
</div>

View file

@ -53,6 +53,7 @@ def includeme(config):
renderer='/home.mako') renderer='/home.mako')
config.include('tailbone.views.core') config.include('tailbone.views.core')
config.include('tailbone.views.common')
config.include('tailbone.views.auth') config.include('tailbone.views.auth')
config.include('tailbone.views.batches') config.include('tailbone.views.batches')

66
tailbone/views/common.py Normal file
View file

@ -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 <http://www.gnu.org/licenses/>.
#
################################################################################
"""
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')