But... "any"? I need some more information about lambda I think....where to find this syntax with any? where is written what you told about evaluation? Thank you very much
Il giorno mercoledì 19 aprile 2017 17:30:06 UTC+2, Anthony ha scritto: > > First, when using auth.requires(), it is best to put the test inside a > lambda (or standard function) so it will not be evaluated until the > decorated function is actually called (otherwise, the test will be > evaluated whenever the controller file is accessed). > > Anyway, you can do something like this: > > list_of_roles = ['role1', 'role2', 'role3'] # You could get this list via > a database query > > @auth.requires(lambda: any(auth.has_membership(role) for role in > list_of_roles)) > def myfunc(): > ... > > Anthony > > On Wednesday, April 19, 2017 at 8:14:53 AM UTC-4, Andrea Fae' wrote: >> >> For example I have this type of functions: >> >> # sono autorizzati i vari manager a seconda della sede >> @auth.requires(auth.has_membership('Total-manager') | >> auth.has_membership('Conegliano-studente') | >> auth.has_membership('Pordenone-manager') | >> auth.has_membership('Pordenone-studente') | >> auth.has_membership('Udine-studente')) >> def appuntamenti_studente(): >> # recupero lo studente selezionato >> studente = request.args(0) >> # recupero il gruppo >> # query per recuperare il nome dello studente >> query_nome_studente = db.auth_user.id == studente >> # recupero nome e cognome dello studente >> row = >> db(query_nome_studente).select(db.auth_user.first_name,db.auth_user.last_name).first() >> #seleziono gli eventi dello studente >> query = (db.evento.studenti.contains(studente)) >> eventi_stud = db(query).select() >> # imposto la grid per far vedere gli eventi dello studente >> exportcls = dict(csv_with_hidden_cols=False, html=False, json=False, >> tsv_with_hidden_cols=False, tsv=False) >> # solo se lo studente corrisponde a chi si è loggato >> if (str(auth.user.id) == studente): >> #print 'sono al form normale' >> form = SQLFORM.grid(query, args=[studente], >> fields=[db.evento.titolo, >> db.evento.inizio,db.evento.fine,db.evento.risorsa, >> db.evento.materia,db.evento.docente],create=False, details=False, >> editable=False, deletable=False, maxtextlength=60, exportclasses = >> exportcls) >> else: >> redirect(URL('default','index')) >> return locals() >> >> I'm testing different "fixed" values in the @auth.requires, but they can >> be more or less depending on how many roles are in the db. I'd like to do >> this dynamically from the db, extracting and compising this @auth.requires >> line in dynamic way. Is it possible? Do you have any examples? Thank you >> > -- Resources: - http://web2py.com - http://web2py.com/book (Documentation) - http://github.com/web2py/web2py (Source code) - https://code.google.com/p/web2py/issues/list (Report Issues) --- You received this message because you are subscribed to the Google Groups "web2py-users" group. To unsubscribe from this group and stop receiving emails from it, send an email to web2py+unsubscr...@googlegroups.com. For more options, visit https://groups.google.com/d/optout.