def edit_right(request, id_egroup, id_right): lists = dict() lists['id_egroup'] = id_egroup try: # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() user_group = client.create_grupo_usuario().listar() if request.method == 'POST': form = UserEquipGroupForm(user_group, request.POST) lists['ugroup_form'] = form if form.is_valid(): update = convert_boolean_to_int(form.cleaned_data['update']) delete = convert_boolean_to_int(form.cleaned_data['delete']) read = convert_boolean_to_int(form.cleaned_data['read']) write = convert_boolean_to_int(form.cleaned_data['write']) client.create_direito_grupo_equipamento().alterar( id_right, read, write, update, delete) messages.add_message(request, messages.SUCCESS, equip_group_messages.get( "sucess_group_user_equip_edit")) # Redirect to list_all action return redirect('equip-group.list', id_egroup, 1) else: lists['open_form'] = "True" # Get Requisition else: # Get Group Equipament by ID from NetworkAPI egroup = client.create_grupo_equipamento().search( id_egroup)['group_equipament'] right = client.create_direito_grupo_equipamento().buscar_por_id( id_right).get('direito_grupo_equipamento') write = convert_int_to_boolean(right.get('escrita')) update = convert_int_to_boolean(right.get('alterar_config')) read = convert_int_to_boolean(right.get('leitura')) delete = convert_int_to_boolean(right.get('exclusao')) lists['ugroup_form'] = UserEquipGroupForm(user_group, initial={"id_egroup": id_egroup, "egroup": egroup.get('nome'), "delete": delete, "update": update, "write": write, "read": read, 'ugroup': right.get("id_grupo_usuario")}) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e)
def add_right(request, id_egroup): lists = dict() lists['id_egroup'] = id_egroup try: # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() user_group = client.create_grupo_usuario().listar() if request.method == 'POST': form = UserEquipGroupForm(user_group, request.POST) lists['ugroup_form'] = form if form.is_valid(): id_ugroup = form.cleaned_data['ugroup'] id_egroup = form.cleaned_data['id_egroup'] update = convert_boolean_to_int(form.cleaned_data['update']) delete = convert_boolean_to_int(form.cleaned_data['delete']) read = convert_boolean_to_int(form.cleaned_data['read']) write = convert_boolean_to_int(form.cleaned_data['write']) client.create_direito_grupo_equipamento().inserir( id_ugroup, id_egroup, read, write, update, delete) messages.add_message( request, messages.SUCCESS, equip_group_messages.get("sucess_group_user_equip")) # Redirect to list_all action return redirect('equip-group.list', id_egroup, 1) else: lists['open_form'] = "True" except DireitoGrupoEquipamentoDuplicadoError, e: logger.error(e) lists['open_form'] = "True" messages.add_message(request, messages.ERROR, equip_group_messages.get("duplicated_error"))
def add_right(request, id_egroup): lists = dict() lists['id_egroup'] = id_egroup try: # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() user_group = client.create_grupo_usuario().listar() if request.method == 'POST': form = UserEquipGroupForm(user_group, request.POST) lists['ugroup_form'] = form if form.is_valid(): id_ugroup = form.cleaned_data['ugroup'] id_egroup = form.cleaned_data['id_egroup'] update = convert_boolean_to_int(form.cleaned_data['update']) delete = convert_boolean_to_int(form.cleaned_data['delete']) read = convert_boolean_to_int(form.cleaned_data['read']) write = convert_boolean_to_int(form.cleaned_data['write']) client.create_direito_grupo_equipamento().inserir( id_ugroup, id_egroup, read, write, update, delete) messages.add_message( request, messages.SUCCESS, equip_group_messages.get("sucess_group_user_equip")) # Redirect to list_all action return redirect('equip-group.list', id_egroup, 1) else: lists['open_form'] = "True" except DireitoGrupoEquipamentoDuplicadoError, e: logger.error(e) lists['open_form'] = "True" messages.add_message( request, messages.ERROR, equip_group_messages.get("duplicated_error"))
def add_form(request, id_egroup): try: form = EquipGroupForm() equipment = None # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() # Get Group Equipament by ID from NetworkAPI egroup = client.create_grupo_equipamento().search( id_egroup)['group_equipament'] if request.method == "POST": form = EquipGroupForm(request.POST) if form.is_valid(): id_egroup = form.cleaned_data['id_egroup'] equip_name = form.cleaned_data['equip_name'] client_equip = client.create_equipamento() # Get equipment by name from NetworkAPI equipment = client_equip.listar_por_nome( equip_name)['equipamento'] try: client_equip.associar_grupo(equipment['id'], id_egroup) messages.add_message( request, messages.SUCCESS, equip_group_messages.get("success_insert")) form = EquipGroupForm(initial={ 'id_egroup': egroup['id'], 'egroup': egroup['nome'] }) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) else:
def add_form(request, id_egroup): try: form = EquipGroupForm() equipment = None # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() # Get Group Equipament by ID from NetworkAPI egroup = client.create_grupo_equipamento().search( id_egroup)['group_equipament'] if request.method == "POST": form = EquipGroupForm(request.POST) if form.is_valid(): id_egroup = form.cleaned_data['id_egroup'] equip_name = form.cleaned_data['equip_name'] client_equip = client.create_equipamento() # Get equipment by name from NetworkAPI equipment = client_equip.listar_por_nome( equip_name)['equipamento'] try: client_equip.associar_grupo(equipment['id'], id_egroup) messages.add_message( request, messages.SUCCESS, equip_group_messages.get("success_insert")) form = EquipGroupForm( initial={'id_egroup': egroup['id'], 'egroup': egroup['nome']}) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) else:
def delete_all(request, id_egroup): if request.method == 'POST': form = DeleteForm(request.POST) if form.is_valid(): # Get user auth = AuthSession(request.session) client_equipament = auth.get_clientFactory().create_equipamento() # All ids to be deleted ids = split_to_array(form.cleaned_data['ids']) # All messages to display error_list = list() # Control others exceptions have_errors = False # For each equipment selected to remove for id_equip in ids: try: # Execute in NetworkAPI client_equipament.remover_grupo(id_equip, id_egroup) except EquipmentDontRemoveError, e: # If isn't possible, add in error list error_list.append(id_equip) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) have_errors = True break # If can't remove some if len(error_list) > 0: list_equipment = cache_list_equipment_all(client_equipament) msg = "" for id_error in error_list: for equip in list_equipment: if equip['id'] == id_error: msg = msg + equip['nome'] + ", " break msg = equip_group_messages.get("can_not_remove") % msg[:-2] messages.add_message(request, messages.WARNING, msg) # If all have been removed elif have_errors == False: messages.add_message( request, messages.SUCCESS, equip_group_messages.get("success_remove")) else: messages.add_message( request, messages.SUCCESS, error_messages.get("can_not_remove_error"))
def delete_right(request, id_egroup): if request.method == 'POST': form = DeleteFormAux(request.POST) if form.is_valid(): # Get user auth = AuthSession(request.session) client_equipament = auth.get_clientFactory( ).create_direito_grupo_equipamento() # All ids to be deleted ids = split_to_array(form.cleaned_data['ids_aux']) # All messages to display error_list = list() # Control others exceptions have_errors = False # For each script selected to remove for id_right in ids: try: # Execute in NetworkAPI client_equipament.remover(id_right) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) have_errors = True break # If cant remove nothing if len(error_list) == len(ids): messages.add_message( request, messages.ERROR, error_messages.get("can_not_remove_all")) # If cant remove someones elif len(error_list) > 0: msg = "" for id_error in error_list: msg = msg + id_error + ", " msg = error_messages.get("can_not_remove") % msg[:-2] messages.add_message(request, messages.WARNING, msg) # If all has ben removed elif have_errors == False: messages.add_message( request, messages.SUCCESS, equip_group_messages.get("sucesso_user_equip_remove")) else: messages.add_message( request, messages.SUCCESS, error_messages.get("can_not_remove_error")) else: messages.add_message( request, messages.ERROR, error_messages.get("select_one"))
def delete_right(request, id_egroup): if request.method == 'POST': form = DeleteFormAux(request.POST) if form.is_valid(): # Get user auth = AuthSession(request.session) client_equipament = auth.get_clientFactory( ).create_direito_grupo_equipamento() # All ids to be deleted ids = split_to_array(form.cleaned_data['ids_aux']) # All messages to display error_list = list() # Control others exceptions have_errors = False # For each script selected to remove for id_right in ids: try: # Execute in NetworkAPI client_equipament.remover(id_right) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e) have_errors = True break # If cant remove nothing if len(error_list) == len(ids): messages.add_message(request, messages.ERROR, error_messages.get("can_not_remove_all")) # If cant remove someones elif len(error_list) > 0: msg = "" for id_error in error_list: msg = msg + id_error + ", " msg = error_messages.get("can_not_remove") % msg[:-2] messages.add_message(request, messages.WARNING, msg) # If all has ben removed elif have_errors == False: messages.add_message( request, messages.SUCCESS, equip_group_messages.get("sucesso_user_equip_remove")) else: messages.add_message( request, messages.SUCCESS, error_messages.get("can_not_remove_error")) else: messages.add_message(request, messages.ERROR, error_messages.get("select_one"))
def edit_right(request, id_egroup, id_right): lists = dict() lists['id_egroup'] = id_egroup try: # Get user auth = AuthSession(request.session) client = auth.get_clientFactory() user_group = client.create_grupo_usuario().listar() if request.method == 'POST': form = UserEquipGroupForm(user_group, request.POST) lists['ugroup_form'] = form if form.is_valid(): update = convert_boolean_to_int(form.cleaned_data['update']) delete = convert_boolean_to_int(form.cleaned_data['delete']) read = convert_boolean_to_int(form.cleaned_data['read']) write = convert_boolean_to_int(form.cleaned_data['write']) client.create_direito_grupo_equipamento().alterar( id_right, read, write, update, delete) messages.add_message( request, messages.SUCCESS, equip_group_messages.get("sucess_group_user_equip_edit")) # Redirect to list_all action return redirect('equip-group.list', id_egroup, 1) else: lists['open_form'] = "True" # Get Requisition else: # Get Group Equipament by ID from NetworkAPI egroup = client.create_grupo_equipamento().search( id_egroup)['group_equipament'] right = client.create_direito_grupo_equipamento().buscar_por_id( id_right).get('direito_grupo_equipamento') write = convert_int_to_boolean(right.get('escrita')) update = convert_int_to_boolean(right.get('alterar_config')) read = convert_int_to_boolean(right.get('leitura')) delete = convert_int_to_boolean(right.get('exclusao')) lists['ugroup_form'] = UserEquipGroupForm( user_group, initial={ "id_egroup": id_egroup, "egroup": egroup.get('nome'), "delete": delete, "update": update, "write": write, "read": read, 'ugroup': right.get("id_grupo_usuario") }) except NetworkAPIClientError, e: logger.error(e) messages.add_message(request, messages.ERROR, e)