plomino / Plomino

Powerful and flexible web-based application builder
33 stars 37 forks source link

Computing a selection field to search data into ldap acl_users #578

Closed Delleyjm closed 10 years ago

Delleyjm commented 10 years ago

Hi, I would like to show in a computed selection field the list of all the "classes" in my ldap (school classes). I tryed using this script (not optimised yet !) into "myfield-settings-selection list formula" :


from Products.CMFCore.utils import getToolByName urltool = getToolByName(context, 'portal_url') portal = urltool.getPortalObject() acl = portal.restrictedTraverse('acl_users/ldap-plugin/acl_users') group_list = acl.getGroups()

cours_list = [] disciplines_list = [] classes_list = [] for group in group_list: if 'COURS' in group[1]: if filtre: if group[0].startswith(filtre): cours_list.append((group[0],group[0])) else: cours_list.append((group[0],group[0])) elif 'DISCIPLINES' in group[1]: if filtre: if group[0].startswith(filtre): disciplines_list.append((group[0],group[0])) else: disciplines_list.append((group[0],group[0])) elif 'CLASSES' in group[1]: if filtre: if group[0].startswith(filtre): classes_list.append((group[0])) else: classes_list.append((group[0]))

return classes_list

When I run the script in the ZMI, the output is : ['0', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '201', '202', '203', '204', '205', '206', '207', '208', '209', '210', '211', '212', '301', '302', '303', '304', '305', '306', '307', '308', '309', '401', '402', '403', '405', '406', '407', '408', '409', '410', 'HORS-CLASSE', '115', '404', '200Stael']

If I replace in Plomino my script by :

classes_list = ['0', '101', '102', '103', '104', '105', '106', '107', '108', '109', '110', '111', '112', '113', '114', '201', '202', '203', '204', '205', '206', '207', '208', '209', '210', '211', '212', '301', '302', '303', '304', '305', '306', '307', '308', '309', '401', '402', '403', '405', '406', '407', '408', '409', '410', 'HORS-CLASSE', '115', '404', '200Stael'] return classes_list

it's ok

but the intitial script in Plomino gives a "groupe field selection list formula failed" Something wrong specially with Plomino in my intitial script ? Any idea of the problem ? Thank you jmd

ebrehault commented 10 years ago

First thing to do is to enable the debug mode in your db settings so you can get a more interesting error message in the server log.

Second thing: I am not usre you are allowed to import getToolByName in a formula. You should try to get your portal_url by aquisition: urltool = context.portal_url

Delleyjm commented 10 years ago

Thanks Eric, it works with this :

urltool = context.portal_url portal = urltool.getPortalObject() acl = portal.restrictedTraverse('acl_users/ldap-plugin/acl_users') group_list = acl.getGroups() classes_list = [] for group in group_list: if 'CLASSES' in group[1]: classes_list.append((group[0]))
return classes_list

I still have a question : what would be the best way to use this field choice into another (?) form ?

from now, I have :

jmd

ebrehault commented 10 years ago

There are various ways, it depends on the scenario. 1 - You can pass the value as URL parameter to the second form: http://server/db/student_choice_form/OpenForm?group_choice=ABC 2 - You can use the field formula to compute its default value (so in the formula you will have to get the group doc and get its group_choice value). 3 - You can pre-generate the student doc from the group doc and initialize its group_choice value 4 - There are probably other ways...

ebrehault commented 10 years ago

same problem here: getToolByName is not safe for PythonScripts

but you can write: context.the_tool_name

On Thu, Oct 23, 2014 at 12:50 PM, Delleyjm notifications@github.com wrote:

Still trying ... and a question : I'm using with PFG this script (see below) to list all members of a ldap group, which uses getToolByName ... and it doesn't work with plomino. Why getToolByName is not working in Plomino ?

As indicated higher, I tryed to use instead something like :

"urltool = context.portal_url portal = urltool.getPortalObject() acl = portal.restrictedTraverse('acl_users/ldap-plugin/acl_users') group_list = acl.getGroups() ..."

to find a solution, but without success ...

Do you have any idea of a syntax plomino-compatible ? Thank you

jmd

Import a standard function, and get the HTML request and response objects.

from Products.PythonScripts.standard import html_quote request = container.REQUEST response = request.response on va chercher les éléments concernant l'utilisateur connecté

membership = context.portal_membership user = membership.getMemberInfo() fullname = user["fullname"]

member = membership.getAuthenticatedMember()

if not member.hasProperty('memberOf'): return [[],[],[]] gr_info = member.getProperty("memberOf")

classes = []

if not gr_info: return [[],[],[]] groupes = [] for gr in gr_info: groupes = gr.split(',') if groupes[1] == 'ou=CLASSES' and groupes[0].split('=')[1] not in classes: classes.append(groupes[0].split('=')[1]) classes.sort() ici j'ai récupéré dans gr le groupe souhaité de l'utilisateur

gr=str(classes[0])

from Products.CMFCore.utils import getToolByName urltool = getToolByName(context, 'portal_url') portal = urltool.getPortalObject() acl = portal.restrictedTraverse('acl_users/ldap-plugin/acl_users') groups_tool = getToolByName(context, 'portal_groups')

user_list = []

group = groups_tool.getGroupById(gr) if group is None: return user_list members = group.getGroupMembers()

user_list = [(m.getProperty('fullname'), m.getProperty('fullname')) for m in members] user_list.sort() return user_list

— Reply to this email directly or view it on GitHub https://github.com/plomino/Plomino/issues/578#issuecomment-60221819.