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="title()">New ${model_title}</%def>
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
<%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>
|
</%def>
|
||||||
|
|
||||||
<ul id="context-menu">
|
<ul id="context-menu">
|
||||||
|
|
|
@ -1,7 +1,7 @@
|
||||||
## -*- coding: utf-8 -*-
|
## -*- coding: utf-8 -*-
|
||||||
<%inherit file="/base.mako" />
|
<%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()">
|
<%def name="context_menu_items()">
|
||||||
<li>${h.link_to("Back to {}".format(model_title_plural), url(route_prefix))}</li>
|
<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.cognized_by.set(label="Cognized by", renderer=forms.renderers.UserFieldRenderer)
|
||||||
fs.executed_by.set(label="Executed by", renderer=forms.renderers.UserFieldRenderer)
|
fs.executed_by.set(label="Executed by", renderer=forms.renderers.UserFieldRenderer)
|
||||||
|
|
||||||
batch = fs.model
|
if self.request.user:
|
||||||
batch.created_by_uuid = self.request.user.uuid
|
batch = fs.model
|
||||||
|
batch.created_by_uuid = self.request.user.uuid
|
||||||
|
|
||||||
def configure_fieldset(self, fs):
|
def configure_fieldset(self, fs):
|
||||||
"""
|
"""
|
||||||
|
@ -332,18 +333,39 @@ class BatchMasterView(MasterView):
|
||||||
exactly this means will depend on the type of batch etc.
|
exactly this means will depend on the type of batch etc.
|
||||||
"""
|
"""
|
||||||
batch = self.get_instance()
|
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
|
# If handler doesn't declare the need for progress indicator, things
|
||||||
# are nice and simple.
|
# are nice and simple.
|
||||||
if not self.handler.show_progress:
|
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.")
|
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))
|
return self.redirect(self.get_action_url('view', batch))
|
||||||
|
|
||||||
# Showing progress requires a separate thread; start that first.
|
# Showing progress requires a separate thread; start that first.
|
||||||
key = '{}.refresh'.format(self.model_class.__tablename__)
|
key = '{}.refresh'.format(self.model_class.__tablename__)
|
||||||
progress = SessionProgress(self.request, key)
|
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()
|
thread.start()
|
||||||
|
|
||||||
# Send user to progress page.
|
# Send user to progress page.
|
||||||
|
@ -352,6 +374,11 @@ class BatchMasterView(MasterView):
|
||||||
'cancel_url': self.get_action_url('view', batch),
|
'cancel_url': self.get_action_url('view', batch),
|
||||||
'cancel_msg': "Batch refresh was canceled.",
|
'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)
|
return render_to_response('/progress.mako', kwargs, request=self.request)
|
||||||
|
|
||||||
def refresh_data(self, session, batch, cognizer=None, progress=None):
|
def refresh_data(self, session, batch, cognizer=None, progress=None):
|
||||||
|
@ -596,7 +623,7 @@ class BatchMasterView(MasterView):
|
||||||
|
|
||||||
key = '{}.execute'.format(self.model_class.__tablename__)
|
key = '{}.execute'.format(self.model_class.__tablename__)
|
||||||
progress = SessionProgress(self.request, key)
|
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()
|
thread.start()
|
||||||
|
|
||||||
kwargs = {
|
kwargs = {
|
||||||
|
@ -606,7 +633,7 @@ class BatchMasterView(MasterView):
|
||||||
}
|
}
|
||||||
return render_to_response('/progress.mako', kwargs, request=self.request)
|
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.
|
Thread target for executing a batch with progress indicator.
|
||||||
"""
|
"""
|
||||||
|
@ -633,7 +660,7 @@ class BatchMasterView(MasterView):
|
||||||
else:
|
else:
|
||||||
if result:
|
if result:
|
||||||
batch.executed = datetime.datetime.utcnow()
|
batch.executed = datetime.datetime.utcnow()
|
||||||
batch.executed_by = session.merge(self.request.user)
|
batch.executed_by_uuid = user_uuid
|
||||||
session.commit()
|
session.commit()
|
||||||
else:
|
else:
|
||||||
session.rollback()
|
session.rollback()
|
||||||
|
|
|
@ -64,6 +64,14 @@ class CustomerGroupsView(MasterView):
|
||||||
for assignment in q:
|
for assignment in q:
|
||||||
Session.delete(assignment)
|
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):
|
def includeme(config):
|
||||||
CustomerGroupsView.defaults(config)
|
CustomerGroupsView.defaults(config)
|
||||||
|
|
|
@ -108,8 +108,8 @@ class MasterView(View):
|
||||||
self.save_create_form(form)
|
self.save_create_form(form)
|
||||||
instance = form.fieldset.model
|
instance = form.fieldset.model
|
||||||
self.after_create(instance)
|
self.after_create(instance)
|
||||||
self.request.session.flash("{} {} has been created.".format(
|
self.request.session.flash("{} has been created: {}".format(
|
||||||
self.get_model_title(), instance))
|
self.get_model_title(), self.get_instance_title(instance)))
|
||||||
return self.redirect_after_create(instance)
|
return self.redirect_after_create(instance)
|
||||||
return self.render_to_response('create', {'form': form})
|
return self.render_to_response('create', {'form': form})
|
||||||
|
|
||||||
|
@ -168,10 +168,11 @@ class MasterView(View):
|
||||||
"""
|
"""
|
||||||
self.deleting = True
|
self.deleting = True
|
||||||
instance = self.get_instance()
|
instance = self.get_instance()
|
||||||
|
instance_title = self.get_instance_title(instance)
|
||||||
|
|
||||||
if not self.deletable_instance(instance):
|
if not self.deletable_instance(instance):
|
||||||
self.request.session.flash("Deletion is not permitted for {} {}".format(
|
self.request.session.flash("Deletion is not permitted for {}: {}".format(
|
||||||
self.get_model_title(), instance))
|
self.get_model_title(), instance_title))
|
||||||
return self.redirect(self.get_action_url('view', instance))
|
return self.redirect(self.get_action_url('view', instance))
|
||||||
|
|
||||||
form = self.make_form(instance)
|
form = self.make_form(instance)
|
||||||
|
@ -185,12 +186,15 @@ class MasterView(View):
|
||||||
return result
|
return result
|
||||||
|
|
||||||
self.delete_instance(instance)
|
self.delete_instance(instance)
|
||||||
self.request.session.flash("{} {} has been deleted.".format(
|
self.request.session.flash("{} has been deleted: {}".format(
|
||||||
self.get_model_title(), instance))
|
self.get_model_title(), instance_title))
|
||||||
return self.redirect(self.get_after_delete_url(instance))
|
return self.redirect(self.get_after_delete_url(instance))
|
||||||
|
|
||||||
form.readonly = True
|
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
|
# Core Stuff
|
||||||
|
@ -592,7 +596,8 @@ class MasterView(View):
|
||||||
kwargs.setdefault('cancel_url', self.get_index_url())
|
kwargs.setdefault('cancel_url', self.get_index_url())
|
||||||
else:
|
else:
|
||||||
kwargs.setdefault('cancel_url', self.get_action_url('view', instance))
|
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
|
form.readonly = self.viewing
|
||||||
return form
|
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
|
kwargs['parsers'] = parsers
|
||||||
return kwargs
|
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):
|
def includeme(config):
|
||||||
VendorCatalogsView.defaults(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'
|
attrs['class_'] = 'warning'
|
||||||
return attrs
|
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):
|
def includeme(config):
|
||||||
VendorInvoicesView.defaults(config)
|
VendorInvoicesView.defaults(config)
|
||||||
|
|
Loading…
Reference in a new issue