Browse Source

Adapt subnavs for master detail crud

pull/341/head
Marcio Mazza 9 years ago
committed by LeandroRoberto
parent
commit
62f5377d1f
  1. 15
      base/templatetags/menus.py
  2. 10
      crud/masterdetail.py

15
base/templatetags/menus.py

@ -19,15 +19,20 @@ def subnav(context, path=None):
# TODO: 118n !!!!!!!!!!!!!!
# How to internationalize yaml files????
menu = None
if 'object' in context:
obj = context['object']
app = obj.__class__._meta.app_label
root_pk = context.get('root_pk', None)
if not root_pk:
obj = context.get('object', None)
if obj:
root_pk = obj.pk
if root_pk:
request = context['request']
app = request.resolver_match.app_name
default_path = '%s/subnav.yaml' % app
path = os.path.join(TEMPLATES_DIR, path or default_path)
if os.path.exists(path):
menu = yaml.load(open(path, 'r'))
resolve_urls_inplace(menu, obj.pk, app)
return dict(menu=menu)
resolve_urls_inplace(menu, root_pk, app)
return {'menu': menu}
def resolve_urls_inplace(menu, pk, app):

10
crud/masterdetail.py

@ -17,6 +17,16 @@ class MasterDetailCrud(Crud):
def create_url(self):
return self.resolve_url(CREATE, args=(self.kwargs['pk'],))
def get_context_data(self, **kwargs):
obj = getattr(self, 'object', None)
if obj:
root_pk = getattr(obj, self.crud.parent_field).pk
else:
root_pk = self.kwargs['pk'] # in list and create
kwargs.setdefault('root_pk', root_pk)
return super(MasterDetailCrud.BaseMixin,
self).get_context_data(**kwargs)
class ListView(CrudListView):
@classmethod

Loading…
Cancel
Save