Add common logic for xref buttons, links when viewing object
about dang time for this..probaby needs improvement but a good start
This commit is contained in:
parent
2278082a4d
commit
273fa7eb55
|
@ -93,6 +93,10 @@ header .level .theme-picker {
|
||||||
* "object helper" panel
|
* "object helper" panel
|
||||||
******************************/
|
******************************/
|
||||||
|
|
||||||
|
.object-helpers .panel-heading {
|
||||||
|
white-space: nowrap;
|
||||||
|
}
|
||||||
|
|
||||||
.object-helpers a {
|
.object-helpers a {
|
||||||
white-space: nowrap;
|
white-space: nowrap;
|
||||||
}
|
}
|
||||||
|
|
|
@ -47,6 +47,35 @@
|
||||||
${instance_title}
|
${instance_title}
|
||||||
</%def>
|
</%def>
|
||||||
|
|
||||||
|
<%def name="object_helpers()">
|
||||||
|
${parent.object_helpers()}
|
||||||
|
${self.render_xref_helper()}
|
||||||
|
</%def>
|
||||||
|
|
||||||
|
<%def name="render_xref_helper()">
|
||||||
|
% if xref_buttons or xref_links:
|
||||||
|
% if use_buefy:
|
||||||
|
<nav class="panel">
|
||||||
|
<p class="panel-heading">Cross-Reference</p>
|
||||||
|
<div class="panel-block">
|
||||||
|
% for link in xref_links:
|
||||||
|
${link}
|
||||||
|
% endfor
|
||||||
|
</div>
|
||||||
|
</nav>
|
||||||
|
% else:
|
||||||
|
<div class="object-helper">
|
||||||
|
<h3>Cross-Reference</h3>
|
||||||
|
<div class="object-helper-content">
|
||||||
|
% for link in xref_links:
|
||||||
|
${link}
|
||||||
|
% endfor
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
% endif
|
||||||
|
% endif
|
||||||
|
</%def>
|
||||||
|
|
||||||
<%def name="context_menu_items()">
|
<%def name="context_menu_items()">
|
||||||
## TODO: either make this configurable, or just lose it.
|
## TODO: either make this configurable, or just lose it.
|
||||||
## nobody seems to ever find it useful in practice.
|
## nobody seems to ever find it useful in practice.
|
||||||
|
|
|
@ -2502,8 +2502,23 @@ class MasterView(View):
|
||||||
"""
|
"""
|
||||||
Method stub, so subclass can always invoke super() for it.
|
Method stub, so subclass can always invoke super() for it.
|
||||||
"""
|
"""
|
||||||
|
obj = kwargs['instance']
|
||||||
|
kwargs['xref_buttons'] = self.get_xref_buttons(obj)
|
||||||
|
kwargs['xref_links'] = self.get_xref_links(obj)
|
||||||
return kwargs
|
return kwargs
|
||||||
|
|
||||||
|
def get_xref_buttons(self, obj):
|
||||||
|
buttons = []
|
||||||
|
for supp in self.iter_view_supplements():
|
||||||
|
buttons.extend(supp.get_xref_buttons(obj))
|
||||||
|
return buttons
|
||||||
|
|
||||||
|
def get_xref_links(self, obj):
|
||||||
|
links = []
|
||||||
|
for supp in self.iter_view_supplements():
|
||||||
|
links.extend(supp.get_xref_links(obj))
|
||||||
|
return links
|
||||||
|
|
||||||
def template_kwargs_edit(self, **kwargs):
|
def template_kwargs_edit(self, **kwargs):
|
||||||
"""
|
"""
|
||||||
Method stub, so subclass can always invoke super() for it.
|
Method stub, so subclass can always invoke super() for it.
|
||||||
|
@ -5062,10 +5077,8 @@ class ViewSupplement(object):
|
||||||
|
|
||||||
def __init__(self, master):
|
def __init__(self, master):
|
||||||
self.master = master
|
self.master = master
|
||||||
|
self.request = master.request
|
||||||
@property
|
self.model = master.model
|
||||||
def model(self):
|
|
||||||
return self.master.model
|
|
||||||
|
|
||||||
def get_grid_query(self, query):
|
def get_grid_query(self, query):
|
||||||
"""
|
"""
|
||||||
|
@ -5111,6 +5124,12 @@ class ViewSupplement(object):
|
||||||
renderers, default values etc. for them.
|
renderers, default values etc. for them.
|
||||||
"""
|
"""
|
||||||
|
|
||||||
|
def get_xref_buttons(self, obj):
|
||||||
|
return []
|
||||||
|
|
||||||
|
def get_xref_links(self, obj):
|
||||||
|
return []
|
||||||
|
|
||||||
def get_version_child_classes(self):
|
def get_version_child_classes(self):
|
||||||
"""
|
"""
|
||||||
Return a list of additional "version child classes" which are
|
Return a list of additional "version child classes" which are
|
||||||
|
|
|
@ -187,27 +187,12 @@ class ProductView(MasterView):
|
||||||
self.handler = self.products_handler
|
self.handler = self.products_handler
|
||||||
|
|
||||||
def query(self, session):
|
def query(self, session):
|
||||||
user = self.request.user
|
query = super(ProductView, self).query(session)
|
||||||
if user and user not in session:
|
|
||||||
user = session.merge(user)
|
|
||||||
|
|
||||||
query = session.query(model.Product)
|
if not self.has_perm('view_deleted'):
|
||||||
# TODO: was this old `has_permission()` call here for a reason..? hope not..
|
|
||||||
# if not auth.has_permission(session, user, 'products.view_deleted'):
|
|
||||||
if not self.request.has_perm('products.view_deleted'):
|
|
||||||
query = query.filter(model.Product.deleted == False)
|
query = query.filter(model.Product.deleted == False)
|
||||||
|
|
||||||
# TODO: This used to be a good idea I thought...but in dev it didn't
|
# TODO: surely this is not always needed
|
||||||
# seem to make much difference, except with a larger (50K) data set it
|
|
||||||
# totally bogged things down instead of helping...
|
|
||||||
# query = query\
|
|
||||||
# .options(orm.joinedload(model.Product.brand))\
|
|
||||||
# .options(orm.joinedload(model.Product.department))\
|
|
||||||
# .options(orm.joinedload(model.Product.subdepartment))\
|
|
||||||
# .options(orm.joinedload(model.Product.regular_price))\
|
|
||||||
# .options(orm.joinedload(model.Product.current_price))\
|
|
||||||
# .options(orm.joinedload(model.Product.vendor))
|
|
||||||
|
|
||||||
query = query.outerjoin(model.ProductInventory)
|
query = query.outerjoin(model.ProductInventory)
|
||||||
|
|
||||||
return query
|
return query
|
||||||
|
@ -1190,6 +1175,7 @@ class ProductView(MasterView):
|
||||||
return jsdata
|
return jsdata
|
||||||
|
|
||||||
def template_kwargs_view(self, **kwargs):
|
def template_kwargs_view(self, **kwargs):
|
||||||
|
kwargs = super(ProductView, self).template_kwargs_view(**kwargs)
|
||||||
product = kwargs['instance']
|
product = kwargs['instance']
|
||||||
use_buefy = self.get_use_buefy()
|
use_buefy = self.get_use_buefy()
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue