def render(self, context): from freppledb.menu import menu try: req = context['request'] except: return '' # No request found in the context o = [] for i in menu.getMenu(req.LANGUAGE_CODE): group = [i[0], []] empty = True kept_back = None for j in i[1]: if j[2].has_permission(req.user): if j[2].separator: kept_back = (j[1], j[2], j[2].can_add(req.user)) else: if kept_back: group[1].append(kept_back) kept_back = None group[1].append((j[1], j[2], j[2].can_add(req.user))) empty = False if not empty: # At least one item of the group is visible o.append(group) context[self.varname] = o return ''
def render(self, context): from freppledb.menu import menu try: req = context['request'] except: return '' # No request found in the context o = [] for i in menu.getMenu(req.LANGUAGE_CODE): group = [i[0], [] ] empty = True kept_back = None for j in i[1]: if j[2].has_permission(req.user): if j[2].separator: kept_back = (j[1], j[2], j[2].can_add(req.user) ) else: if kept_back: group[1].append(kept_back) kept_back = None group[1].append( (j[1], j[2], j[2].can_add(req.user) ) ) empty = False if not empty: # At least one item of the group is visible o.append(group) context[self.varname] = o return ''
def render(self, context): from freppledb.menu import menu try: req = context['request'] except: return '' # No request found in the context o = [] # Find all tables with data with connections[req.database].cursor() as cursor: cursor.execute(''' select table_name from ( select table_name, query_to_xml( format('select 1 as cnt from %I.%I limit 1', table_schema, table_name), false, true, '' ) as xml_count from information_schema.tables where table_schema = 'public' ) s where xml_count is document ''') present = set([i[0] for i in cursor]) for i in menu.getMenu(req.LANGUAGE_CODE): group = [i[0], [], False] empty = True kept_back = None for j in i[1]: if j[2].has_permission(req.user): ok = True if j[2].dependencies and not (j[2].model and j[2].model._meta.db_table in present): for dep in j[2].dependencies: if dep._meta.db_table not in present: ok = False break emptytable = not j[2].model or j[ 2].model._meta.db_table in present if j[2].separator: if group[2]: kept_back = (j[1], j[2], j[2].can_add(req.user), emptytable, ok) else: if kept_back: group[1].append(kept_back) kept_back = None group[1].append((j[1], j[2], j[2].can_add(req.user), emptytable, ok)) if not group[2] and ok: group[2] = True empty = False if not empty: # At least one item of the group is visible o.append(group) context[self.varname] = o return ''
def render(self, context): from freppledb.menu import menu try: req = context["request"] except: return "" # No request found in the context o = [] for i in menu.getMenu(req.LANGUAGE_CODE): group = [i[0], []] empty = True for j in i[1]: if j[2].has_permission(req.user): empty = False group[1].append((j[1], j[2], j[2].can_add(req.user))) if not empty: # At least one item of the group is visible o.append(group) context[self.varname] = o return ""
def render(self, context): from freppledb.menu import menu try: req = context["request"] except Exception: return "" # No request found in the context o = [] # Find all tables with data with connections[req.database].cursor() as cursor: cursor.execute(""" select table_name from ( select table_name, query_to_xml( format('select 1 as cnt from %I.%I limit 1', table_schema, table_name), false, true, '' ) as xml_count from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' ) s where xml_count is document """) present = set([i[0] for i in cursor]) def generator(i): for j in i[1]: if callable(j[2].callback): # Dynamic definition of menu items with a callback function for x in j[2].callback(req): yield x else: # Static definition of the menu yield j for i in menu.getMenu(req.LANGUAGE_CODE): group = [i[0], [], False] empty = True kept_back = None for j in generator(i): if j[2].has_permission(req.user): ok = True if j[2].dependencies: for dep in j[2].dependencies: if not isinstance(dep, type) and callable(dep): ok = dep(req) if not ok: break elif dep._meta.db_table not in present: ok = False break emptytable = not j[2].model or j[ 2].model._meta.db_table in present if j[2].separator: if group[2]: kept_back = ( j[1], j[2], j[2].can_add(req.user), emptytable, ok, ) else: if kept_back: group[1].append(kept_back) kept_back = None group[1].append((j[1], j[2], j[2].can_add(req.user), emptytable, ok)) if not group[2] and ok: group[2] = True empty = False if not empty: # At least one item of the group is visible o.append(group) context[self.varname] = o return ""
def render(self, context): from freppledb.menu import menu try: req = context["request"] except: return "" # No request found in the context o = [] # Find all tables with data with connections[req.database].cursor() as cursor: cursor.execute( """ select table_name from ( select table_name, query_to_xml( format('select 1 as cnt from %I.%I limit 1', table_schema, table_name), false, true, '' ) as xml_count from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' ) s where xml_count is document """ ) present = set([i[0] for i in cursor]) for i in menu.getMenu(req.LANGUAGE_CODE): group = [i[0], [], False] empty = True kept_back = None for j in i[1]: if j[2].has_permission(req.user): ok = True if j[2].dependencies: for dep in j[2].dependencies: if isinstance(dep, list) and len(dep) == 2: # Evaluate the value try: ok = ( dep[0] .objects.using(req.database) .get(name=dep[1]) .value.lower() == "true" ) except: ok = False if ok is False: break elif dep._meta.db_table not in present: ok = False break emptytable = not j[2].model or j[2].model._meta.db_table in present if j[2].separator: if group[2]: kept_back = ( j[1], j[2], j[2].can_add(req.user), emptytable, ok, ) else: if kept_back: group[1].append(kept_back) kept_back = None group[1].append( (j[1], j[2], j[2].can_add(req.user), emptytable, ok) ) if not group[2] and ok: group[2] = True empty = False if not empty: # At least one item of the group is visible o.append(group) context[self.varname] = o return ""
def render(self, context): from freppledb.menu import menu try: req = context['request'] except: return '' # No request found in the context o = [] # Find all tables with data with connections[req.database].cursor() as cursor: cursor.execute(''' select table_name from ( select table_name, query_to_xml( format('select 1 as cnt from %I.%I limit 1', table_schema, table_name), false, true, '' ) as xml_count from information_schema.tables where table_schema = 'public' and table_type = 'BASE TABLE' ) s where xml_count is document ''') present = set([ i[0] for i in cursor]) for i in menu.getMenu(req.LANGUAGE_CODE): group = [i[0], [], False] empty = True kept_back = None for j in i[1]: if j[2].has_permission(req.user): ok = True if j[2].dependencies: for dep in j[2].dependencies: if isinstance(dep, list) and len(dep) == 2: # Evaluate the value try: ok = dep[0].objects.using(req.database).get(name=dep[1]).value.lower() == 'true' except: ok = False if ok is False: break elif dep._meta.db_table not in present: ok = False break emptytable = not j[2].model or j[2].model._meta.db_table in present if j[2].separator: if group[2]: kept_back = (j[1], j[2], j[2].can_add(req.user), emptytable, ok ) else: if kept_back: group[1].append(kept_back) kept_back = None group[1].append( (j[1], j[2], j[2].can_add(req.user), emptytable, ok ) ) if not group[2] and ok: group[2] = True empty = False if not empty: # At least one item of the group is visible o.append(group) context[self.varname] = o return ''