# Path: wh.py
# def xlt(s): # translate
#   return s
#   t=wx.GetTranslation(s)
#   # if dict set and t == s: log untranslated
#   return t
# 
# def YesNo(b):
#   if b:
#     return xlt("Yes")
#   else:
#     return xlt("No")
# 
# def prettyDate(val, long=True):
#   if isinstance(val, datetime.datetime):
#     val=val.timetuple()
#   if not isinstance(val, time.struct_time):
#     val=time.localtime(val)
#   if long:
#     return time.strftime("%Y-%m-%d %H:%M:%S", val)
#   else:
#     return time.strftime("%Y-%m-%d", val)


import adm
from wh import xlt, YesNo, prettyDate
# The Admin4 Project
# (c) 2013-2014 Andreas Pflug
#
# Licensed under the Apache License, 
# see LICENSE.TXT for conditions of usage



class Role(adm.Node):
  typename=xlt("Role")
  shortname=xlt("Role")
  
  @staticmethod
  def GetInstances(parentNode):
    instances=[]
    set=parentNode.GetConnection().GetCursor().ExecuteSet("""
      SELECT rolname as name, *,
        (SELECT array_agg(rolname) FROM pg_roles r JOIN pg_auth_members m on r.oid=m.member WHERE m.roleid=u.oid) AS members,
        (SELECT array_agg(rolname) FROM pg_roles r JOIN pg_auth_members m on r.oid=m.roleid WHERE m.member=u.oid) AS memberof
        FROM pg_roles u ORDER BY rolname""")
    if set:
      for row in set:
        if not row:

# Path: wh.py
# def xlt(s): # translate
#   return s
#   t=wx.GetTranslation(s)
#   # if dict set and t == s: log untranslated
#   return t
# 
# def YesNo(b):
#   if b:
#     return xlt("Yes")
#   else:
#     return xlt("No")
# 
# def prettyDate(val, long=True):
#   if isinstance(val, datetime.datetime):
#     val=val.timetuple()
#   if not isinstance(val, time.struct_time):
#     val=time.localtime(val)
#   if long:
#     return time.strftime("%Y-%m-%d %H:%M:%S", val)
#   else:
#     return time.strftime("%Y-%m-%d", val)


# Path: modPg/Role.py
import adm
from wh import xlt, YesNo, prettyDate

# The Admin4 Project
# (c) 2013-2014 Andreas Pflug
#
# Licensed under the Apache License, 
# see LICENSE.TXT for conditions of usage



class Role(adm.Node):
  typename=xlt("Role")
  shortname=xlt("Role")
  
  @staticmethod
  def GetInstances(parentNode):
    instances=[]
    set=parentNode.GetConnection().GetCursor().ExecuteSet("""
      SELECT rolname as name, *,
        (SELECT array_agg(rolname) FROM pg_roles r JOIN pg_auth_members m on r.oid=m.member WHERE m.roleid=u.oid) AS members,
        (SELECT array_agg(rolname) FROM pg_roles r JOIN pg_auth_members m on r.oid=m.roleid WHERE m.member=u.oid) AS memberof
        FROM pg_roles u ORDER BY rolname""")
    if set:
      for row in set:
        if not row:

          break