2022-01-29 14:51:59 -06:00
|
|
|
# -*- coding: utf-8; -*-
|
|
|
|
################################################################################
|
|
|
|
#
|
|
|
|
# Rattail -- Retail Software Framework
|
|
|
|
# Copyright © 2010-2022 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 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 General Public License for more
|
|
|
|
# details.
|
|
|
|
#
|
|
|
|
# You should have received a copy of the GNU General Public License along with
|
|
|
|
# Rattail. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
#
|
|
|
|
################################################################################
|
|
|
|
"""
|
|
|
|
Harvest User views
|
|
|
|
"""
|
|
|
|
|
|
|
|
from rattail_harvest.db.model import HarvestUser
|
|
|
|
|
2022-01-30 17:41:17 -06:00
|
|
|
import colander
|
|
|
|
|
|
|
|
from tailbone import forms
|
2022-01-29 14:51:59 -06:00
|
|
|
from .master import HarvestMasterView
|
|
|
|
|
|
|
|
|
|
|
|
class HarvestUserView(HarvestMasterView):
|
|
|
|
"""
|
|
|
|
Master view for Harvest Users
|
|
|
|
"""
|
|
|
|
model_class = HarvestUser
|
|
|
|
url_prefix = '/harvest/users'
|
|
|
|
route_prefix = 'harvest.users'
|
|
|
|
|
|
|
|
grid_columns = [
|
|
|
|
'id',
|
|
|
|
'first_name',
|
|
|
|
'last_name',
|
|
|
|
'email',
|
|
|
|
'telephone',
|
|
|
|
'timezone',
|
|
|
|
'is_admin',
|
|
|
|
]
|
|
|
|
|
|
|
|
def configure_grid(self, g):
|
|
|
|
super(HarvestUserView, self).configure_grid(g)
|
2022-01-30 17:41:17 -06:00
|
|
|
model = self.model
|
|
|
|
|
|
|
|
g.set_joiner('person_name', lambda q: q.outerjoin(model.Person))
|
|
|
|
g.set_filter('person_name', model.Person.display_name)
|
2022-01-29 14:51:59 -06:00
|
|
|
|
|
|
|
g.set_sort_defaults('first_name')
|
|
|
|
|
|
|
|
g.set_link('id')
|
|
|
|
g.set_link('first_name')
|
|
|
|
g.set_link('last_name')
|
|
|
|
g.set_link('email')
|
|
|
|
|
|
|
|
def configure_form(self, f):
|
|
|
|
super(HarvestUserView, self).configure_form(f)
|
2022-01-30 17:41:17 -06:00
|
|
|
model = self.model
|
|
|
|
user = f.model_instance
|
|
|
|
|
|
|
|
# person
|
|
|
|
f.set_renderer('person', self.render_person)
|
|
|
|
if self.creating or self.editing:
|
|
|
|
if 'person' in f.fields:
|
|
|
|
f.remove('person_uuid')
|
|
|
|
f.replace('person', 'person_uuid')
|
|
|
|
person_display = ""
|
|
|
|
if self.request.method == 'POST':
|
|
|
|
if self.request.POST.get('person_uuid'):
|
|
|
|
person = self.Session.query(model.Person).get(self.request.POST['person_uuid'])
|
|
|
|
if person:
|
|
|
|
person_display = str(person)
|
|
|
|
elif self.editing:
|
|
|
|
person_display = str(user.person or '')
|
|
|
|
people_url = self.request.route_url('people.autocomplete')
|
|
|
|
f.set_widget('person_uuid', forms.widgets.JQueryAutocompleteWidget(
|
|
|
|
field_display=person_display, service_url=people_url))
|
|
|
|
f.set_validator('person_uuid', self.valid_person)
|
|
|
|
f.set_label('person_uuid', "Person")
|
2022-01-29 14:51:59 -06:00
|
|
|
|
2022-01-30 17:41:17 -06:00
|
|
|
# timestamps
|
|
|
|
if self.creating or self.editing:
|
|
|
|
f.remove('created_at')
|
|
|
|
f.remove('updated_at')
|
|
|
|
|
|
|
|
# time_entries
|
2022-01-29 14:51:59 -06:00
|
|
|
# TODO: should add this as child rows/grid instead
|
|
|
|
f.remove('time_entries')
|
|
|
|
|
2022-01-30 17:41:17 -06:00
|
|
|
def valid_person(self, node, value):
|
|
|
|
model = self.model
|
|
|
|
if value:
|
|
|
|
person = self.Session.query(model.Person).get(value)
|
|
|
|
if not person:
|
|
|
|
raise colander.Invalid(node, "Person not found (you must *select* a record)")
|
|
|
|
|
2022-01-29 14:51:59 -06:00
|
|
|
|
2022-03-03 19:33:01 -06:00
|
|
|
def defaults(config, **kwargs):
|
|
|
|
base = globals()
|
|
|
|
|
|
|
|
HarvestUserView = kwargs.get('HarvestUserView', base['HarvestUserView'])
|
2022-01-29 14:51:59 -06:00
|
|
|
HarvestUserView.defaults(config)
|
2022-03-03 19:33:01 -06:00
|
|
|
|
|
|
|
|
|
|
|
def includeme(config):
|
|
|
|
defaults(config)
|