def list(profil_id): profil = Profil.get_by_id(profil_id) # liste des roles lie au profil en cours attrib = ProfilRole.query( ProfilRole.profil_id == profil.key ) attrib_list = [role.role_id.get().key.id() for role in attrib] # liste des roles lie au profil en cours avec le droit d'edition edit = ProfilRole.query( ProfilRole.profil_id == profil.key, ProfilRole.edit == True ) edit_list = [role.role_id.get().key.id() for role in edit] # liste des roles lie au profil en cours avec le droit de modification delete = ProfilRole.query( ProfilRole.profil_id == profil.key, ProfilRole.delete == True ) delete_list = [role.role_id.get().key.id() for role in delete] liste_role = [] data_role = Roles.query( Roles.valeur != 'super_admin' ) for role in data_role: if not role.parent: module = {} module['titre'] = role.titre enfants = Roles.query( Roles.parent == role.key ) module['role'] = [] for enfant in enfants: rol = {} rol['id'] = enfant.key.id() rol['titre'] = enfant.titre rol['action'] = enfant.action module['role'].append(rol) liste_role.append(module) success = False if request.method == 'POST': form_attrib = request.form.getlist('attrib') form_edit = request.form.getlist('edit') form_delete = request.form.getlist('delete') # liste des roles lie au profil et supprimer ce qui ne sont plus attribue current_profil_role = ProfilRole.query( ProfilRole.profil_id == profil.key ) for current in current_profil_role: if current.role_id.get().key.id() not in form_attrib: current.key.delete() # Insertion des roles et authorisation en provenance du formulaire for attrib in form_attrib: role_form = Roles.get_by_id(int(attrib)) profil_role_exist = ProfilRole.query( ProfilRole.role_id == role_form.key, ProfilRole.profil_id == profil.key ).get() if profil_role_exist: if attrib in form_edit: profil_role_exist.edit = True else: profil_role_exist.edit = False if attrib in form_delete: profil_role_exist.delete = True else: profil_role_exist.delete = False profil_role_exist.put() else: profil_role_create = ProfilRole() profil_role_create.role_id = role_form.key profil_role_create.profil_id = profil.key if attrib in form_edit: profil_role_create.edit = True else: profil_role_create.edit = False if attrib in form_delete: profil_role_create.delete = True else: profil_role_create.delete = False profil_role_create.put() flash('Enregistement effectue avec succes', 'success') success = True return render_template('profil/list.html', **locals())
def list(profil_id): profil = Profil.objects.get(id=profil_id) # liste des roles lie au profil en cours attrib = ProfilRole.objects(profil_id=profil.id) attrib_list = [role.role_id.id for role in attrib] # liste des roles lie au profil en cours avec le droit d'edition edit = ProfilRole.objects(Q(profil_id=profil.id) & Q(edit=True)) edit_list = [role.role_id.id for role in edit] # liste des roles lie au profil en cours avec le droit de modification delete = ProfilRole.objects(Q(profil_id=profil.id) & Q(deleted=True)) delete_list = [role.role_id.id for role in delete] liste_role = [] data_role = Roles.objects(valeur__ne='super_admin') for role in data_role: if not role.parent: module = {} module['titre'] = role.titre enfants = Roles.objects(parent=role.id) module['role'] = [] for enfant in enfants: rol = {} rol['id'] = enfant.id rol['titre'] = enfant.titre rol['action'] = enfant.action module['role'].append(rol) liste_role.append(module) success = False if request.method == 'POST': form_attrib = request.form.getlist('attrib') form_edit = request.form.getlist('edit') form_delete = request.form.getlist('delete') # liste des roles lie au profil et supprimer ce qui ne sont plus attribue current_profil_role = ProfilRole.objects(profil_id=profil.id) for current in current_profil_role: if current.role_id.id not in form_attrib: current.delete() # Insertion des roles et authorisation en provenance du formulaire for attrib in form_attrib: role_form = Roles.objects.get(id=attrib) profil_role_exist = ProfilRole.objects( Q(role_id=role_form.id) & Q(profil_id=profil.id)).first() if profil_role_exist: if attrib in form_edit: profil_role_exist.edit = True else: profil_role_exist.edit = False if attrib in form_delete: profil_role_exist.deleted = True else: profil_role_exist.deleted = False profil_role_exist.save() else: profil_role_create = ProfilRole() profil_role_create.role_id = role_form profil_role_create.profil_id = profil if attrib in form_edit: profil_role_create.edit = True else: profil_role_create.edit = False if attrib in form_delete: profil_role_create.deleted = True else: profil_role_create.deleted = False profil_role_create.save() flash('Enregistement effectue avec succes', 'success') success = True return render_template('profil/list.html', **locals())
def list(profil_id): from ..user.models_user import Users profil = Profil.get_by_id(profil_id) # liste des roles lie au profil en cours attrib = ProfilRole.query(ProfilRole.profil_id == profil.key) attrib_list = [role.role_id.get().key.id() for role in attrib] # liste des roles lie au profil en cours avec le droit d'edition edit = ProfilRole.query(ProfilRole.profil_id == profil.key, ProfilRole.edit == True) edit_list = [role.role_id.get().key.id() for role in edit] # liste des roles lie au profil en cours avec le droit de modification delete = ProfilRole.query(ProfilRole.profil_id == profil.key, ProfilRole.delete == True) delete_list = [role.role_id.get().key.id() for role in delete] liste_role = [] data_role = Roles.query(Roles.valeur != 'super_admin') for role in data_role: if not role.parent: module = {} module['titre'] = role.titre enfants = Roles.query(Roles.parent == role.key) module['role'] = [] for enfant in enfants: rol = {} rol['id'] = enfant.key.id() rol['titre'] = enfant.titre rol['action'] = enfant.action module['role'].append(rol) liste_role.append(module) success = False if request.method == 'POST': form_attrib = request.form.getlist('attrib') form_edit = request.form.getlist('edit') form_delete = request.form.getlist('delete') # liste des roles lie au profil et supprimer ce qui ne sont plus attribue current_profil_role = ProfilRole.query( ProfilRole.profil_id == profil.key) user_profil = Users.query(Users.profil_id == profil.key).count() view_succes = True if not user_profil: for current in current_profil_role: if current.role_id.get().key.id() not in form_attrib: current.key.delete() else: view_succes = False # Insertion des roles et authorisation en provenance du formulaire for attrib in form_attrib: role_form = Roles.get_by_id(int(attrib)) profil_role_exist = ProfilRole.query( ProfilRole.role_id == role_form.key, ProfilRole.profil_id == profil.key).get() if profil_role_exist: if attrib in form_edit: profil_role_exist.edit = True else: profil_role_exist.edit = False if attrib in form_delete: profil_role_exist.delete = True else: profil_role_exist.delete = False profil_role_exist.put() else: profil_role_create = ProfilRole() profil_role_create.role_id = role_form.key profil_role_create.profil_id = profil.key if attrib in form_edit: profil_role_create.edit = True else: profil_role_create.edit = False if attrib in form_delete: profil_role_create.delete = True else: profil_role_create.delete = False profil_role_create.put() if view_succes: flash('Enregistement effectue avec succes', 'success') else: flash( 'Impossible de vider ce profil en role car il est utilise par un utilisateur', 'warning') success = True return render_template('profil/list.html', **locals())