Expose UserEvent table in UI
normal table access, plus per-user row grid
This commit is contained in:
parent
82e8f49dd1
commit
2f0f3fa463
|
@ -40,6 +40,7 @@ from webhelpers2.html import HTML, tags
|
||||||
|
|
||||||
from tailbone import forms
|
from tailbone import forms
|
||||||
from tailbone.db import Session
|
from tailbone.db import Session
|
||||||
|
from tailbone.views import MasterView2 as MasterView
|
||||||
from tailbone.views.principal import PrincipalMasterView
|
from tailbone.views.principal import PrincipalMasterView
|
||||||
|
|
||||||
|
|
||||||
|
@ -128,6 +129,8 @@ class UsersView(PrincipalMasterView):
|
||||||
Master view for the User model.
|
Master view for the User model.
|
||||||
"""
|
"""
|
||||||
model_class = model.User
|
model_class = model.User
|
||||||
|
has_rows = True
|
||||||
|
model_row_class = model.UserEvent
|
||||||
has_versions = True
|
has_versions = True
|
||||||
|
|
||||||
mergeable = True
|
mergeable = True
|
||||||
|
@ -149,6 +152,11 @@ class UsersView(PrincipalMasterView):
|
||||||
'person',
|
'person',
|
||||||
]
|
]
|
||||||
|
|
||||||
|
row_grid_columns = [
|
||||||
|
'type_code',
|
||||||
|
'occurred',
|
||||||
|
]
|
||||||
|
|
||||||
def query(self, session):
|
def query(self, session):
|
||||||
return session.query(model.User)\
|
return session.query(model.User)\
|
||||||
.options(orm.joinedload(model.User.person))
|
.options(orm.joinedload(model.User.person))
|
||||||
|
@ -217,6 +225,20 @@ class UsersView(PrincipalMasterView):
|
||||||
return user.username != 'chuck'
|
return user.username != 'chuck'
|
||||||
return True
|
return True
|
||||||
|
|
||||||
|
def get_row_data(self, user):
|
||||||
|
return self.Session.query(model.UserEvent)\
|
||||||
|
.filter(model.UserEvent.user == user)
|
||||||
|
|
||||||
|
def configure_row_grid(self, g):
|
||||||
|
super(UsersView, self).configure_row_grid(g)
|
||||||
|
g.width = 'half'
|
||||||
|
g.filterable = False
|
||||||
|
g.default_sortkey = 'occurred'
|
||||||
|
g.default_sortdir = 'desc'
|
||||||
|
g.set_enum('type_code', self.enum.USER_EVENT)
|
||||||
|
g.set_label('type_code', "Event Type")
|
||||||
|
g.main_actions = []
|
||||||
|
|
||||||
def get_version_child_classes(self):
|
def get_version_child_classes(self):
|
||||||
return [
|
return [
|
||||||
(model.UserRole, 'user_uuid'),
|
(model.UserRole, 'user_uuid'),
|
||||||
|
@ -262,5 +284,51 @@ class UsersView(PrincipalMasterView):
|
||||||
self.Session.delete(removing)
|
self.Session.delete(removing)
|
||||||
|
|
||||||
|
|
||||||
|
class UserEventsView(MasterView):
|
||||||
|
"""
|
||||||
|
Master view for all user events
|
||||||
|
"""
|
||||||
|
model_class = model.UserEvent
|
||||||
|
url_prefix = '/user-events'
|
||||||
|
viewable = False
|
||||||
|
creatable = False
|
||||||
|
editable = False
|
||||||
|
deletable = False
|
||||||
|
|
||||||
|
grid_columns = [
|
||||||
|
'user',
|
||||||
|
'person',
|
||||||
|
'type_code',
|
||||||
|
'occurred',
|
||||||
|
]
|
||||||
|
|
||||||
|
def get_data(self, session=None):
|
||||||
|
query = super(UserEventsView, self).get_data(session=session)
|
||||||
|
return query.join(model.User)
|
||||||
|
|
||||||
|
def configure_grid(self, g):
|
||||||
|
super(UserEventsView, self).configure_grid(g)
|
||||||
|
g.set_joiner('person', lambda q: q.outerjoin(model.Person))
|
||||||
|
g.set_sorter('user', model.User.username)
|
||||||
|
g.set_sorter('person', model.Person.display_name)
|
||||||
|
g.filters['user'] = g.make_filter('user', model.User.username)
|
||||||
|
g.filters['person'] = g.make_filter('person', model.Person.display_name)
|
||||||
|
g.set_enum('type_code', self.enum.USER_EVENT)
|
||||||
|
g.set_type('occurred', 'datetime')
|
||||||
|
g.set_renderer('user', self.render_user)
|
||||||
|
g.set_renderer('person', self.render_person)
|
||||||
|
g.default_sortkey = 'occurred'
|
||||||
|
g.default_sortdir = 'desc'
|
||||||
|
g.set_label('user', "Username")
|
||||||
|
g.set_label('type_code', "Event Type")
|
||||||
|
|
||||||
|
def render_user(self, event, column):
|
||||||
|
return event.user.username
|
||||||
|
|
||||||
|
def render_person(self, event, column):
|
||||||
|
return event.user.person.display_name
|
||||||
|
|
||||||
|
|
||||||
def includeme(config):
|
def includeme(config):
|
||||||
UsersView.defaults(config)
|
UsersView.defaults(config)
|
||||||
|
UserEventsView.defaults(config)
|
||||||
|
|
Loading…
Reference in a new issue