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-helpers .panel-heading {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
||||
.object-helpers a {
|
||||
white-space: nowrap;
|
||||
}
|
||||
|
|
|
@ -47,6 +47,35 @@
|
|||
${instance_title}
|
||||
</%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()">
|
||||
## TODO: either make this configurable, or just lose it.
|
||||
## 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.
|
||||
"""
|
||||
obj = kwargs['instance']
|
||||
kwargs['xref_buttons'] = self.get_xref_buttons(obj)
|
||||
kwargs['xref_links'] = self.get_xref_links(obj)
|
||||
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):
|
||||
"""
|
||||
Method stub, so subclass can always invoke super() for it.
|
||||
|
@ -5062,10 +5077,8 @@ class ViewSupplement(object):
|
|||
|
||||
def __init__(self, master):
|
||||
self.master = master
|
||||
|
||||
@property
|
||||
def model(self):
|
||||
return self.master.model
|
||||
self.request = master.request
|
||||
self.model = master.model
|
||||
|
||||
def get_grid_query(self, query):
|
||||
"""
|
||||
|
@ -5111,6 +5124,12 @@ class ViewSupplement(object):
|
|||
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):
|
||||
"""
|
||||
Return a list of additional "version child classes" which are
|
||||
|
|
|
@ -187,27 +187,12 @@ class ProductView(MasterView):
|
|||
self.handler = self.products_handler
|
||||
|
||||
def query(self, session):
|
||||
user = self.request.user
|
||||
if user and user not in session:
|
||||
user = session.merge(user)
|
||||
query = super(ProductView, self).query(session)
|
||||
|
||||
query = session.query(model.Product)
|
||||
# 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'):
|
||||
if not self.has_perm('view_deleted'):
|
||||
query = query.filter(model.Product.deleted == False)
|
||||
|
||||
# TODO: This used to be a good idea I thought...but in dev it didn't
|
||||
# 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))
|
||||
|
||||
# TODO: surely this is not always needed
|
||||
query = query.outerjoin(model.ProductInventory)
|
||||
|
||||
return query
|
||||
|
@ -1190,6 +1175,7 @@ class ProductView(MasterView):
|
|||
return jsdata
|
||||
|
||||
def template_kwargs_view(self, **kwargs):
|
||||
kwargs = super(ProductView, self).template_kwargs_view(**kwargs)
|
||||
product = kwargs['instance']
|
||||
use_buefy = self.get_use_buefy()
|
||||
|
||||
|
|
Loading…
Reference in a new issue