rattail-demo/rattail_demo/web/views/employees.py

45 lines
1.3 KiB
Python
Raw Normal View History

# -*- coding: utf-8; -*-
"""
Employee views
"""
from tailbone.views import employees as base
from tailbone.config import protected_usernames
class EmployeeView(base.EmployeesView):
"""
Prevent edit/delete for Chuck Norris
"""
def __init__(self, request, **kwargs):
super(EmployeeView, self).__init__(request, **kwargs)
self.protected_usernames = protected_usernames(self.rattail_config)
def is_employee_protected(self, employee):
if self.protected_usernames:
for user in employee.person.users:
if user.username in self.protected_usernames:
return True
return False
def editable_instance(self, employee):
if self.request.is_root:
return True
return not self.is_employee_protected(employee)
def deletable_instance(self, employee):
if self.request.is_root:
return True
return not self.is_employee_protected(employee)
def includeme(config):
# autocomplete
config.add_route('employees.autocomplete', '/employees/autocomplete')
config.add_view(base.EmployeesAutocomplete, route_name='employees.autocomplete',
renderer='json', permission='employees.list')
EmployeeView.defaults(config)