2017-03-19 11:21:00 -05:00
|
|
|
# -*- coding: utf-8; -*-
|
2014-11-23 14:27:00 -06:00
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
2017-03-19 11:21:00 -05:00
|
|
|
# Copyright © 2010-2017 Lance Edgar
|
2014-11-23 14:27:00 -06:00
|
|
|
#
|
|
|
|
# This file is part of Rattail.
|
|
|
|
#
|
|
|
|
# Rattail is free software: you can redistribute it and/or modify it under the
|
2017-07-06 23:47:56 -05:00
|
|
|
# terms of the GNU General Public License as published by the Free Software
|
|
|
|
# Foundation, either version 3 of the License, or (at your option) any later
|
|
|
|
# version.
|
2014-11-23 14:27:00 -06:00
|
|
|
#
|
|
|
|
# Rattail is distributed in the hope that it will be useful, but WITHOUT ANY
|
|
|
|
# WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
|
2017-07-06 23:47:56 -05:00
|
|
|
# FOR A PARTICULAR PURPOSE. See the GNU General Public License for more
|
|
|
|
# details.
|
2014-11-23 14:27:00 -06:00
|
|
|
#
|
2017-07-06 23:47:56 -05:00
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
2014-11-23 14:27:00 -06:00
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
|
|
|
Settings Views
|
|
|
|
"""
|
|
|
|
|
2017-03-19 11:21:00 -05:00
|
|
|
from __future__ import unicode_literals, absolute_import
|
|
|
|
|
|
|
|
import re
|
2014-11-23 14:27:00 -06:00
|
|
|
|
|
|
|
from rattail.db import model
|
|
|
|
|
2017-05-19 10:42:05 -05:00
|
|
|
import formalchemy as fa
|
|
|
|
|
|
|
|
from tailbone.db import Session
|
2017-07-07 09:13:53 -05:00
|
|
|
from tailbone.views import MasterView2 as MasterView
|
2014-11-23 14:27:00 -06:00
|
|
|
|
|
|
|
|
2017-05-19 10:42:05 -05:00
|
|
|
def unique_name(value, field):
|
|
|
|
setting = Session.query(model.Setting).get(value)
|
|
|
|
if setting:
|
|
|
|
raise fa.ValidationError("Setting name must be unique")
|
|
|
|
|
|
|
|
|
2015-07-29 11:09:38 -05:00
|
|
|
class SettingsView(MasterView):
|
|
|
|
"""
|
|
|
|
Master view for the settings model.
|
|
|
|
"""
|
|
|
|
model_class = model.Setting
|
2017-03-19 11:21:00 -05:00
|
|
|
feedback = re.compile(r'^rattail\.mail\.user_feedback\..*')
|
2017-07-07 09:13:53 -05:00
|
|
|
grid_columns = [
|
|
|
|
'name',
|
|
|
|
'value',
|
|
|
|
]
|
2014-11-23 14:27:00 -06:00
|
|
|
|
2015-07-29 11:09:38 -05:00
|
|
|
def configure_grid(self, g):
|
|
|
|
g.filters['name'].default_active = True
|
|
|
|
g.filters['name'].default_verb = 'contains'
|
|
|
|
g.default_sortkey = 'name'
|
2017-07-07 09:13:53 -05:00
|
|
|
g.set_link('name')
|
2014-11-23 14:27:00 -06:00
|
|
|
|
2017-05-19 10:42:05 -05:00
|
|
|
def _preconfigure_fieldset(self, fs):
|
|
|
|
fs.name.set(validate=unique_name)
|
2015-07-29 11:09:38 -05:00
|
|
|
if self.editing:
|
2014-11-23 14:27:00 -06:00
|
|
|
fs.name.set(readonly=True)
|
|
|
|
|
2017-05-19 10:42:05 -05:00
|
|
|
def configure_fieldset(self, fs):
|
|
|
|
fs.configure(include=[
|
|
|
|
fs.name,
|
|
|
|
fs.value,
|
|
|
|
])
|
|
|
|
|
2017-03-19 11:21:00 -05:00
|
|
|
def editable_instance(self, setting):
|
|
|
|
if self.rattail_config.demo():
|
|
|
|
return not bool(self.feedback.match(setting.name))
|
|
|
|
return True
|
|
|
|
|
|
|
|
def deletable_instance(self, setting):
|
|
|
|
if self.rattail_config.demo():
|
|
|
|
return not bool(self.feedback.match(setting.name))
|
|
|
|
return True
|
|
|
|
|
2014-11-23 14:27:00 -06:00
|
|
|
|
|
|
|
def includeme(config):
|
2015-07-29 11:09:38 -05:00
|
|
|
SettingsView.defaults(config)
|