More tweaks to new master-based batch views, etc.
This commit is contained in:
parent
7ac4af5f34
commit
874fd6d4b3
|
@ -4,7 +4,9 @@
|
|||
<%def name="title()">New ${model_title}</%def>
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
<li>${h.link_to("Back to {0}".format(model_title_plural), index_url)}</li>
|
||||
% if request.has_perm('{}.list'.format(permission_prefix)):
|
||||
<li>${h.link_to("Back to {}".format(model_title_plural), index_url)}</li>
|
||||
% endif
|
||||
</%def>
|
||||
|
||||
<ul id="context-menu">
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
## -*- coding: utf-8 -*-
|
||||
<%inherit file="/base.mako" />
|
||||
|
||||
<%def name="title()">Delete ${model_title}: ${unicode(instance)}</%def>
|
||||
<%def name="title()">Delete ${model_title}: ${instance_title}</%def>
|
||||
|
||||
<%def name="context_menu_items()">
|
||||
<li>${h.link_to("Back to {}".format(model_title_plural), url(route_prefix))}</li>
|
||||
|
|
|
@ -173,8 +173,9 @@ class BatchMasterView(MasterView):
|
|||
fs.cognized_by.set(label="Cognized by", renderer=forms.renderers.UserFieldRenderer)
|
||||
fs.executed_by.set(label="Executed by", renderer=forms.renderers.UserFieldRenderer)
|
||||
|
||||
batch = fs.model
|
||||
batch.created_by_uuid = self.request.user.uuid
|
||||
if self.request.user:
|
||||
batch = fs.model
|
||||
batch.created_by_uuid = self.request.user.uuid
|
||||
|
||||
def configure_fieldset(self, fs):
|
||||
"""
|
||||
|
@ -332,18 +333,39 @@ class BatchMasterView(MasterView):
|
|||
exactly this means will depend on the type of batch etc.
|
||||
"""
|
||||
batch = self.get_instance()
|
||||
route_prefix = self.get_route_prefix()
|
||||
permission_prefix = self.get_permission_prefix()
|
||||
|
||||
cognizer = self.request.user
|
||||
if not cognizer:
|
||||
uuid = self.request.session.pop('late_login_user', None)
|
||||
cognizer = Session.query(model.User).get(uuid) if uuid else None
|
||||
|
||||
# If handler doesn't declare the need for progress indicator, things
|
||||
# are nice and simple.
|
||||
if not self.handler.show_progress:
|
||||
self.refresh_data(Session(), batch)
|
||||
self.refresh_data(Session, batch, cognizer=cognizer)
|
||||
self.request.session.flash("Batch data has been refreshed.")
|
||||
|
||||
# TODO: This seems hacky...it exists for (only) one specific scenario.
|
||||
if not self.request.has_perm('{}.view'.format(permission_prefix)):
|
||||
return self.redirect(self.request.route_url('{}.create'.format(route_prefix)))
|
||||
|
||||
return self.redirect(self.get_action_url('view', batch))
|
||||
|
||||
# Showing progress requires a separate thread; start that first.
|
||||
key = '{}.refresh'.format(self.model_class.__tablename__)
|
||||
progress = SessionProgress(self.request, key)
|
||||
thread = Thread(target=self.refresh_thread, args=(batch.uuid, progress))
|
||||
# success_url = self.request.route_url('vendors.scangenius.create') if not self.request.user else None
|
||||
|
||||
# TODO: This seems hacky...it exists for (only) one specific scenario.
|
||||
success_url = None
|
||||
if not self.request.user:
|
||||
success_url = self.request.route_url('{}.create'.format(route_prefix))
|
||||
|
||||
thread = Thread(target=self.refresh_thread, args=(batch.uuid, progress,
|
||||
cognizer.uuid if cognizer else None,
|
||||
success_url))
|
||||
thread.start()
|
||||
|
||||
# Send user to progress page.
|
||||
|
@ -352,6 +374,11 @@ class BatchMasterView(MasterView):
|
|||
'cancel_url': self.get_action_url('view', batch),
|
||||
'cancel_msg': "Batch refresh was canceled.",
|
||||
}
|
||||
|
||||
# TODO: This seems hacky...it exists for (only) one specific scenario.
|
||||
if not self.request.has_perm('{}.view'.format(permission_prefix)):
|
||||
kwargs['cancel_url'] = self.request.route_url('{}.create'.format(route_prefix))
|
||||
|
||||
return render_to_response('/progress.mako', kwargs, request=self.request)
|
||||
|
||||
def refresh_data(self, session, batch, cognizer=None, progress=None):
|
||||
|
@ -596,7 +623,7 @@ class BatchMasterView(MasterView):
|
|||
|
||||
key = '{}.execute'.format(self.model_class.__tablename__)
|
||||
progress = SessionProgress(self.request, key)
|
||||
thread = Thread(target=self.execute_thread, args=(batch.uuid, progress))
|
||||
thread = Thread(target=self.execute_thread, args=(batch.uuid, self.request.user.uuid, progress))
|
||||
thread.start()
|
||||
|
||||
kwargs = {
|
||||
|
@ -606,7 +633,7 @@ class BatchMasterView(MasterView):
|
|||
}
|
||||
return render_to_response('/progress.mako', kwargs, request=self.request)
|
||||
|
||||
def execute_thread(self, batch_uuid, progress=None):
|
||||
def execute_thread(self, batch_uuid, user_uuid, progress=None):
|
||||
"""
|
||||
Thread target for executing a batch with progress indicator.
|
||||
"""
|
||||
|
@ -633,7 +660,7 @@ class BatchMasterView(MasterView):
|
|||
else:
|
||||
if result:
|
||||
batch.executed = datetime.datetime.utcnow()
|
||||
batch.executed_by = session.merge(self.request.user)
|
||||
batch.executed_by_uuid = user_uuid
|
||||
session.commit()
|
||||
else:
|
||||
session.rollback()
|
||||
|
|
|
@ -64,6 +64,14 @@ class CustomerGroupsView(MasterView):
|
|||
for assignment in q:
|
||||
Session.delete(assignment)
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
|
||||
# fix permission group title
|
||||
config.add_tailbone_permission_group('customergroups', "Customer Groups")
|
||||
|
||||
cls._defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
CustomerGroupsView.defaults(config)
|
||||
|
|
|
@ -108,8 +108,8 @@ class MasterView(View):
|
|||
self.save_create_form(form)
|
||||
instance = form.fieldset.model
|
||||
self.after_create(instance)
|
||||
self.request.session.flash("{} {} has been created.".format(
|
||||
self.get_model_title(), instance))
|
||||
self.request.session.flash("{} has been created: {}".format(
|
||||
self.get_model_title(), self.get_instance_title(instance)))
|
||||
return self.redirect_after_create(instance)
|
||||
return self.render_to_response('create', {'form': form})
|
||||
|
||||
|
@ -168,10 +168,11 @@ class MasterView(View):
|
|||
"""
|
||||
self.deleting = True
|
||||
instance = self.get_instance()
|
||||
instance_title = self.get_instance_title(instance)
|
||||
|
||||
if not self.deletable_instance(instance):
|
||||
self.request.session.flash("Deletion is not permitted for {} {}".format(
|
||||
self.get_model_title(), instance))
|
||||
self.request.session.flash("Deletion is not permitted for {}: {}".format(
|
||||
self.get_model_title(), instance_title))
|
||||
return self.redirect(self.get_action_url('view', instance))
|
||||
|
||||
form = self.make_form(instance)
|
||||
|
@ -185,12 +186,15 @@ class MasterView(View):
|
|||
return result
|
||||
|
||||
self.delete_instance(instance)
|
||||
self.request.session.flash("{} {} has been deleted.".format(
|
||||
self.get_model_title(), instance))
|
||||
self.request.session.flash("{} has been deleted: {}".format(
|
||||
self.get_model_title(), instance_title))
|
||||
return self.redirect(self.get_after_delete_url(instance))
|
||||
|
||||
form.readonly = True
|
||||
return self.render_to_response('delete', {'instance': instance, 'form': form})
|
||||
return self.render_to_response('delete', {
|
||||
'instance': instance,
|
||||
'instance_title': instance_title,
|
||||
'form': form})
|
||||
|
||||
##############################
|
||||
# Core Stuff
|
||||
|
@ -592,7 +596,8 @@ class MasterView(View):
|
|||
kwargs.setdefault('cancel_url', self.get_index_url())
|
||||
else:
|
||||
kwargs.setdefault('cancel_url', self.get_action_url('view', instance))
|
||||
form = forms.AlchemyForm(self.request, fieldset, **kwargs)
|
||||
factory = kwargs.pop('factory', forms.AlchemyForm)
|
||||
form = factory(self.request, fieldset, **kwargs)
|
||||
form.readonly = self.viewing
|
||||
return form
|
||||
|
||||
|
|
10
tailbone/views/vendors/catalogs.py
vendored
10
tailbone/views/vendors/catalogs.py
vendored
|
@ -152,6 +152,16 @@ class VendorCatalogsView(FileBatchMasterView):
|
|||
kwargs['parsers'] = parsers
|
||||
return kwargs
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
|
||||
# fix permission group title
|
||||
config.add_tailbone_permission_group('vendorcatalogs', "Vendor Catalogs")
|
||||
|
||||
cls._filebatch_defaults(config)
|
||||
cls._batch_defaults(config)
|
||||
cls._defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
VendorCatalogsView.defaults(config)
|
||||
|
|
10
tailbone/views/vendors/invoices.py
vendored
10
tailbone/views/vendors/invoices.py
vendored
|
@ -153,6 +153,16 @@ class VendorInvoicesView(FileBatchMasterView):
|
|||
attrs['class_'] = 'warning'
|
||||
return attrs
|
||||
|
||||
@classmethod
|
||||
def defaults(cls, config):
|
||||
|
||||
# fix permission group title
|
||||
config.add_tailbone_permission_group('vendorinvoices', "Vendor Invoices")
|
||||
|
||||
cls._filebatch_defaults(config)
|
||||
cls._batch_defaults(config)
|
||||
cls._defaults(config)
|
||||
|
||||
|
||||
def includeme(config):
|
||||
VendorInvoicesView.defaults(config)
|
||||
|
|
Loading…
Reference in a new issue