Various things to support "notes management" from person profile view
This commit is contained in:
parent
6749604210
commit
1ee76878d9
|
@ -1272,12 +1272,14 @@ class GridAction(object):
|
|||
'actions' column when rendering the grid.
|
||||
"""
|
||||
|
||||
def __init__(self, key, label=None, url='#', icon=None, target=None):
|
||||
def __init__(self, key, label=None, url='#', icon=None, target=None,
|
||||
click_handler=None):
|
||||
self.key = key
|
||||
self.label = label or prettify(key)
|
||||
self.icon = icon
|
||||
self.url = url
|
||||
self.target = target
|
||||
self.click_handler = click_handler
|
||||
|
||||
def get_url(self, row, i):
|
||||
"""
|
||||
|
|
|
@ -20,9 +20,15 @@
|
|||
% if grid.main_actions or grid.more_actions:
|
||||
<b-table-column field="actions" label="Actions">
|
||||
% for action in grid.main_actions:
|
||||
<a :href="props.row._action_url_${action.key}"><i class="fas fa-${action.icon}"></i>
|
||||
<a :href="props.row._action_url_${action.key}"
|
||||
% if action.click_handler:
|
||||
@click.prevent="${action.click_handler}"
|
||||
% endif
|
||||
>
|
||||
<i class="fas fa-${action.icon}"></i>
|
||||
${action.label}
|
||||
</a>
|
||||
|
||||
% endfor
|
||||
</b-table-column>
|
||||
% endif
|
||||
|
|
|
@ -148,6 +148,7 @@
|
|||
<a :href="props.row._action_url_${action.key}"><i class="fas fa-${action.icon}"></i>
|
||||
${action.label}
|
||||
</a>
|
||||
|
||||
% endfor
|
||||
</b-table-column>
|
||||
% endif
|
||||
|
|
|
@ -252,11 +252,25 @@ class PeopleView(MasterView):
|
|||
template = 'view_profile_buefy' if use_buefy else 'view_profile'
|
||||
return self.render_to_response(template, context)
|
||||
|
||||
def valid_note_types(self):
|
||||
# TODO: should return something by default?
|
||||
return {}
|
||||
def make_note_form(self, mode, person):
|
||||
schema = NoteSchema().bind(session=self.Session(),
|
||||
person_uuid=person.uuid)
|
||||
if mode == 'create':
|
||||
del schema['uuid']
|
||||
form = forms.Form(schema=schema, request=self.request)
|
||||
return form
|
||||
|
||||
def profile_make_note(self, person, form):
|
||||
def profile_add_note(self):
|
||||
person = self.get_instance()
|
||||
form = self.make_note_form('create', person)
|
||||
if form.validate(newstyle=True):
|
||||
note = self.create_note(person, form)
|
||||
self.Session.flush()
|
||||
return self.profile_add_note_success(note)
|
||||
else:
|
||||
return self.profile_add_note_failure(person, form)
|
||||
|
||||
def create_note(self, person, form):
|
||||
note = model.PersonNote()
|
||||
note.type = form.validated['note_type']
|
||||
note.subject = form.validated['note_subject']
|
||||
|
@ -265,23 +279,54 @@ class PeopleView(MasterView):
|
|||
person.notes.append(note)
|
||||
return note
|
||||
|
||||
def profile_add_note(self):
|
||||
person = self.get_instance()
|
||||
schema = AddNote().bind(note_types=self.valid_note_types())
|
||||
form = forms.Form(schema=schema, request=self.request)
|
||||
if form.validate(newstyle=True):
|
||||
note = self.profile_make_note(person, form)
|
||||
self.Session.flush()
|
||||
return self.profile_add_note_success(note)
|
||||
else:
|
||||
return self.profile_add_note_failure(person, form)
|
||||
|
||||
def profile_add_note_success(self, note):
|
||||
return self.redirect(self.get_action_url('view_profile', person))
|
||||
|
||||
def profile_add_note_failure(self, person, form):
|
||||
return self.redirect(self.get_action_url('view_profile', person))
|
||||
|
||||
def profile_edit_note(self):
|
||||
person = self.get_instance()
|
||||
form = self.make_note_form('edit', person)
|
||||
if form.validate(newstyle=True):
|
||||
note = self.update_note(person, form)
|
||||
self.Session.flush()
|
||||
return self.profile_edit_note_success(note)
|
||||
else:
|
||||
return self.profile_edit_note_failure(person, form)
|
||||
|
||||
def update_note(self, person, form):
|
||||
note = self.Session.query(model.PersonNote).get(form.validated['uuid'])
|
||||
note.subject = form.validated['note_subject']
|
||||
note.text = form.validated['note_text']
|
||||
return note
|
||||
|
||||
def profile_edit_note_success(self, note):
|
||||
return self.redirect(self.get_action_url('view_profile', person))
|
||||
|
||||
def profile_edit_note_failure(self, person, form):
|
||||
return self.redirect(self.get_action_url('view_profile', person))
|
||||
|
||||
def profile_delete_note(self):
|
||||
person = self.get_instance()
|
||||
form = self.make_note_form('delete', person)
|
||||
if form.validate(newstyle=True):
|
||||
self.delete_note(person, form)
|
||||
self.Session.flush()
|
||||
return self.profile_delete_note_success(person)
|
||||
else:
|
||||
return self.profile_delete_note_failure(person, form)
|
||||
|
||||
def delete_note(self, person, form):
|
||||
note = self.Session.query(model.PersonNote).get(form.validated['uuid'])
|
||||
self.Session.delete(note)
|
||||
|
||||
def profile_delete_note_success(self, person):
|
||||
return self.redirect(self.get_action_url('view_profile', person))
|
||||
|
||||
def profile_delete_note_failure(self, person, form):
|
||||
return self.redirect(self.get_action_url('view_profile', person))
|
||||
|
||||
def make_user(self):
|
||||
uuid = self.request.POST['person_uuid']
|
||||
person = self.Session.query(model.Person).get(uuid)
|
||||
|
@ -326,26 +371,26 @@ class PeopleView(MasterView):
|
|||
# add note
|
||||
config.add_tailbone_permission(permission_prefix, '{}.profile_add_note'.format(permission_prefix),
|
||||
"Add new {} note from profile view".format(model_title))
|
||||
config.add_route('{}.profile_add_note'.format(route_prefix), '{}/{{{}}}/profile/add-note'.format(url_prefix, model_key),
|
||||
config.add_route('{}.profile_add_note'.format(route_prefix), '{}/{{{}}}/profile/new-note'.format(url_prefix, model_key),
|
||||
request_method='POST')
|
||||
config.add_view(cls, attr='profile_add_note', route_name='{}.profile_add_note'.format(route_prefix),
|
||||
permission='{}.profile_add_note'.format(permission_prefix))
|
||||
|
||||
# # edit note
|
||||
# config.add_tailbone_permission(permission_prefix, '{}.profile_edit_note'.format(permission_prefix),
|
||||
# "Edit existing {} note from profile view".format(model_title))
|
||||
# config.add_route('{}.profile_edit_note'.format(route_prefix), '{}/{{{}}}/profile/edit-note/{{note_uuid}}'.format(url_prefix, model_key),
|
||||
# request_method='POST')
|
||||
# config.add_view(cls, 'profile_edit_note', route_name='{}.profile_edit_note'.format(route_prefix),
|
||||
# permission='{}.profile_edit_note'.format(permission_prefix))
|
||||
# edit note
|
||||
config.add_tailbone_permission(permission_prefix, '{}.profile_edit_note'.format(permission_prefix),
|
||||
"Edit existing {} note from profile view".format(model_title))
|
||||
config.add_route('{}.profile_edit_note'.format(route_prefix), '{}/{{{}}}/profile/edit-note'.format(url_prefix, model_key),
|
||||
request_method='POST')
|
||||
config.add_view(cls, attr='profile_edit_note', route_name='{}.profile_edit_note'.format(route_prefix),
|
||||
permission='{}.profile_edit_note'.format(permission_prefix))
|
||||
|
||||
# # delete note
|
||||
# config.add_tailbone_permission(permission_prefix, '{}.profile_delete_note'.format(permission_prefix),
|
||||
# "Delete existing {} note from profile view".format(model_title))
|
||||
# config.add_route('{}.profile_delete_note'.format(route_prefix), '{}/{{{}}}/profile/delete-note/{{note_uuid}}'.format(url_prefix, model_key),
|
||||
# request_method='POST')
|
||||
# config.add_view(cls, 'profile_delete_note', route_name='{}.profile_delete_note'.format(route_prefix),
|
||||
# permission='{}.profile_delete_note'.format(permission_prefix))
|
||||
# delete note
|
||||
config.add_tailbone_permission(permission_prefix, '{}.profile_delete_note'.format(permission_prefix),
|
||||
"Delete existing {} note from profile view".format(model_title))
|
||||
config.add_route('{}.profile_delete_note'.format(route_prefix), '{}/{{{}}}/profile/delete-note'.format(url_prefix, model_key),
|
||||
request_method='POST')
|
||||
config.add_view(cls, attr='profile_delete_note', route_name='{}.profile_delete_note'.format(route_prefix),
|
||||
permission='{}.profile_delete_note'.format(permission_prefix))
|
||||
|
||||
# make user for person
|
||||
config.add_route('{}.make_user'.format(route_prefix), '{}/make-user'.format(url_prefix),
|
||||
|
@ -428,19 +473,25 @@ class PersonNoteView(MasterView):
|
|||
|
||||
|
||||
@colander.deferred
|
||||
def valid_note_type(node, kw):
|
||||
note_types = kw['note_types']
|
||||
def valid_note_uuid(node, kw):
|
||||
session = kw['session']
|
||||
person_uuid = kw['person_uuid']
|
||||
def validate(node, value):
|
||||
if value not in note_types:
|
||||
raise colander.Invalid(node, "Invalid note type")
|
||||
return value
|
||||
note = session.query(model.PersonNote).get(value)
|
||||
if not note:
|
||||
raise colander.Invalid(node, "Note not found")
|
||||
if note.person.uuid != person_uuid:
|
||||
raise colander.Invalid(node, "Note is for the wrong person")
|
||||
return note.uuid
|
||||
return validate
|
||||
|
||||
|
||||
class AddNote(colander.Schema):
|
||||
class NoteSchema(colander.Schema):
|
||||
|
||||
note_type = colander.SchemaNode(colander.String(),
|
||||
validator=valid_note_type)
|
||||
uuid = colander.SchemaNode(colander.String(),
|
||||
validator=valid_note_uuid)
|
||||
|
||||
note_type = colander.SchemaNode(colander.String())
|
||||
|
||||
note_subject = colander.SchemaNode(colander.String(), missing='')
|
||||
|
||||
|
|
Loading…
Reference in a new issue