def salvar(request, hash): from emensageriapro.settings import VERSAO_EMENSAGERIA, VERSAO_MODELO, TP_AMB db_slug = 'default' try: usuario_id = request.user.id dict_hash = get_hash_url(hash) s2206_evtaltcontratual_id = int(dict_hash['id']) if 'tab' not in dict_hash.keys(): dict_hash['tab'] = '' for_print = int(dict_hash['print']) except: usuario_id = False return redirect('login') usuario = get_object_or_404(Usuarios.objects.using(db_slug), excluido=False, id=usuario_id) pagina = ConfigPaginas.objects.using(db_slug).get( excluido=False, endereco='s2206_evtaltcontratual') permissao = ConfigPermissoes.objects.using(db_slug).get( excluido=False, config_paginas=pagina, config_perfis=usuario.config_perfis) if s2206_evtaltcontratual_id: s2206_evtaltcontratual = get_object_or_404( s2206evtAltContratual.objects.using(db_slug), excluido=False, id=s2206_evtaltcontratual_id) dict_permissoes = json_to_dict(usuario.config_perfis.permissoes) paginas_permitidas_lista = usuario.config_perfis.paginas_permitidas modulos_permitidos_lista = usuario.config_perfis.modulos_permitidos if s2206_evtaltcontratual_id: if s2206_evtaltcontratual.status != 0: dict_permissoes['s2206_evtaltcontratual_apagar'] = 0 dict_permissoes['s2206_evtaltcontratual_editar'] = 0 if permissao.permite_visualizar: mensagem = None if s2206_evtaltcontratual_id: s2206_evtaltcontratual_form = form_s2206_evtaltcontratual( request.POST or None, instance=s2206_evtaltcontratual, slug=db_slug) else: s2206_evtaltcontratual_form = form_s2206_evtaltcontratual( request.POST or None, slug=db_slug, initial={ 'versao': VERSAO_MODELO, 'processamento_codigo_resposta': 0, 'tpamb': TP_AMB, 'procemi': 1, 'verproc': VERSAO_EMENSAGERIA }) if request.method == 'POST': if s2206_evtaltcontratual_form.is_valid(): dados = s2206_evtaltcontratual_form.cleaned_data import json from django.forms.models import model_to_dict if s2206_evtaltcontratual_id: if s2206_evtaltcontratual.status == 0: dados['modificado_por_id'] = usuario_id dados['modificado_em'] = datetime.datetime.now() #s2206_evtaltcontratual_campos_multiple_passo1 s2206evtAltContratual.objects.using(db_slug).filter( id=s2206_evtaltcontratual_id).update(**dados) obj = s2206evtAltContratual.objects.using(db_slug).get( id=s2206_evtaltcontratual_id) #s2206_evtaltcontratual_editar_custom #s2206_evtaltcontratual_campos_multiple_passo2 messages.success(request, 'Alterado com sucesso!') gravar_auditoria( json.dumps(model_to_dict(s2206_evtaltcontratual), indent=4, sort_keys=True, default=str), json.dumps(model_to_dict(obj), indent=4, sort_keys=True, default=str), 's2206_evtaltcontratual', s2206_evtaltcontratual_id, usuario_id, 2) else: messages.error( request, 'Não é possível salvar o evento, pois o mesmo não está com o status "Cadastrado"!' ) else: dados['arquivo_original'] = 0 dados['criado_por_id'] = usuario_id dados['criado_em'] = datetime.datetime.now() dados['excluido'] = False #s2206_evtaltcontratual_cadastrar_campos_multiple_passo1 obj = s2206evtAltContratual(**dados) obj.save(using=db_slug) #s2206_evtaltcontratual_cadastrar_custom #s2206_evtaltcontratual_cadastrar_campos_multiple_passo2 identidade_evento(obj.id, db_slug) messages.success(request, 'Cadastrado com sucesso!') gravar_auditoria( '{}', json.dumps(model_to_dict(obj), indent=4, sort_keys=True, default=str), 's2206_evtaltcontratual', obj.id, usuario_id, 1) if request.session['retorno_pagina'] not in ( 's2206_evtaltcontratual_apagar', 's2206_evtaltcontratual_salvar', 's2206_evtaltcontratual'): return redirect(request.session['retorno_pagina'], hash=request.session['retorno_hash']) if s2206_evtaltcontratual_id != obj.id: url_hash = base64.urlsafe_b64encode( '{"print": "0", "id": "%s"}' % (obj.id)) return redirect('s2206_evtaltcontratual_salvar', hash=url_hash) else: messages.error(request, 'Erro ao salvar!') s2206_evtaltcontratual_form = disabled_form_fields( s2206_evtaltcontratual_form, permissao.permite_editar) if s2206_evtaltcontratual_id: if s2206_evtaltcontratual.status != 0: s2206_evtaltcontratual_form = disabled_form_fields( s2206_evtaltcontratual_form, False) #s2206_evtaltcontratual_campos_multiple_passo3 for field in s2206_evtaltcontratual_form.fields.keys(): s2206_evtaltcontratual_form.fields[field].widget.attrs[ 'ng-model'] = 's2206_evtaltcontratual_' + field if int(dict_hash['print']): s2206_evtaltcontratual_form = disabled_form_for_print( s2206_evtaltcontratual_form) s2206_infoceletista_form = None s2206_infoceletista_lista = None s2206_infoestatutario_form = None s2206_infoestatutario_lista = None s2206_localtrabgeral_form = None s2206_localtrabgeral_lista = None s2206_localtrabdom_form = None s2206_localtrabdom_lista = None s2206_horcontratual_form = None s2206_horcontratual_lista = None s2206_filiacaosindical_form = None s2206_filiacaosindical_lista = None s2206_alvarajudicial_form = None s2206_alvarajudicial_lista = None s2206_observacoes_form = None s2206_observacoes_lista = None s2206_servpubl_form = None s2206_servpubl_lista = None if s2206_evtaltcontratual_id: s2206_evtaltcontratual = get_object_or_404( s2206evtAltContratual.objects.using(db_slug), excluido=False, id=s2206_evtaltcontratual_id) s2206_infoceletista_form = form_s2206_infoceletista( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_infoceletista_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_infoceletista_lista = s2206infoCeletista.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_infoestatutario_form = form_s2206_infoestatutario( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_infoestatutario_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_infoestatutario_lista = s2206infoEstatutario.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_localtrabgeral_form = form_s2206_localtrabgeral( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_localtrabgeral_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_localtrabgeral_lista = s2206localTrabGeral.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_localtrabdom_form = form_s2206_localtrabdom( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_localtrabdom_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_localtrabdom_lista = s2206localTrabDom.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_horcontratual_form = form_s2206_horcontratual( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_horcontratual_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_horcontratual_lista = s2206horContratual.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_filiacaosindical_form = form_s2206_filiacaosindical( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_filiacaosindical_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_filiacaosindical_lista = s2206filiacaoSindical.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_alvarajudicial_form = form_s2206_alvarajudicial( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_alvarajudicial_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_alvarajudicial_lista = s2206alvaraJudicial.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_observacoes_form = form_s2206_observacoes( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_observacoes_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_observacoes_lista = s2206observacoes.objects.using( db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_servpubl_form = form_s2206_servpubl( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}, slug=db_slug) s2206_servpubl_form.fields['s2206_evtaltcontratual'].widget.attrs[ 'readonly'] = True s2206_servpubl_lista = s2206servPubl.objects.using(db_slug).filter( excluido=False, s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() else: s2206_evtaltcontratual = None #s2206_evtaltcontratual_salvar_custom_variaveis# tabelas_secundarias = [] #[FUNCOES_ESPECIAIS_SALVAR] if 's2206_evtaltcontratual'[1] == '5': evento_totalizador = True else: evento_totalizador = False if not evento_totalizador: s2206_evtaltcontratual_form.fields['tpamb'].widget.attrs[ 'disabled'] = True s2206_evtaltcontratual_form.fields['tpamb'].widget.attrs[ 'readonly'] = True s2206_evtaltcontratual_form.fields['tpamb'].value = TP_AMB s2206_evtaltcontratual_form.fields['procemi'].widget.attrs[ 'disabled'] = True s2206_evtaltcontratual_form.fields['procemi'].widget.attrs[ 'readonly'] = True s2206_evtaltcontratual_form.fields['procemi'].value = 1 s2206_evtaltcontratual_form.fields['verproc'].widget.attrs[ 'readonly'] = True s2206_evtaltcontratual_form.fields[ 'verproc'].value = VERSAO_EMENSAGERIA if dict_hash['tab'] or 's2206_evtaltcontratual' in request.session[ 'retorno_pagina']: request.session["retorno_hash"] = hash request.session["retorno_pagina"] = 's2206_evtaltcontratual_salvar' controle_alteracoes = Auditoria.objects.using(db_slug).filter( identidade=s2206_evtaltcontratual_id, tabela='s2206_evtaltcontratual').all() context = { 'evento_totalizador': evento_totalizador, 'controle_alteracoes': controle_alteracoes, 's2206_evtaltcontratual': s2206_evtaltcontratual, 's2206_evtaltcontratual_form': s2206_evtaltcontratual_form, 'mensagem': mensagem, 's2206_evtaltcontratual_id': int(s2206_evtaltcontratual_id), 'usuario': usuario, 'hash': hash, 's2206_infoceletista_form': s2206_infoceletista_form, 's2206_infoceletista_lista': s2206_infoceletista_lista, 's2206_infoestatutario_form': s2206_infoestatutario_form, 's2206_infoestatutario_lista': s2206_infoestatutario_lista, 's2206_localtrabgeral_form': s2206_localtrabgeral_form, 's2206_localtrabgeral_lista': s2206_localtrabgeral_lista, 's2206_localtrabdom_form': s2206_localtrabdom_form, 's2206_localtrabdom_lista': s2206_localtrabdom_lista, 's2206_horcontratual_form': s2206_horcontratual_form, 's2206_horcontratual_lista': s2206_horcontratual_lista, 's2206_filiacaosindical_form': s2206_filiacaosindical_form, 's2206_filiacaosindical_lista': s2206_filiacaosindical_lista, 's2206_alvarajudicial_form': s2206_alvarajudicial_form, 's2206_alvarajudicial_lista': s2206_alvarajudicial_lista, 's2206_observacoes_form': s2206_observacoes_form, 's2206_observacoes_lista': s2206_observacoes_lista, 's2206_servpubl_form': s2206_servpubl_form, 's2206_servpubl_lista': s2206_servpubl_lista, 'modulos_permitidos_lista': modulos_permitidos_lista, 'paginas_permitidas_lista': paginas_permitidas_lista, 'permissao': permissao, 'data': datetime.datetime.now(), 'pagina': pagina, 'dict_permissoes': dict_permissoes, 'for_print': int(dict_hash['print']), 'tabelas_secundarias': tabelas_secundarias, 'tab': dict_hash['tab'], #s2206_evtaltcontratual_salvar_custom_variaveis_context# } if for_print in (0, 1): return render(request, 's2206_evtaltcontratual_salvar.html', context) elif for_print == 2: from wkhtmltopdf.views import PDFTemplateResponse response = PDFTemplateResponse( request=request, template='s2206_evtaltcontratual_salvar.html', filename="s2206_evtaltcontratual.pdf", context=context, show_content_in_browser=True, cmd_options={ 'margin-top': 10, 'margin-bottom': 10, 'margin-right': 10, 'margin-left': 10, 'zoom': 1, 'dpi': 72, 'orientation': 'Landscape', "viewport-size": "1366 x 513", 'javascript-delay': 1000, 'footer-center': '[page]/[topage]', "no-stop-slow-scripts": True }, ) return response elif for_print == 3: from django.shortcuts import render_to_response response = render_to_response('s2206_evtaltcontratual_salvar.html', context) filename = "s2206_evtaltcontratual.xls" response[ 'Content-Disposition'] = 'attachment; filename=' + filename response[ 'Content-Type'] = 'application/vnd.ms-excel; charset=UTF-8' return response else: context = { 'usuario': usuario, 'modulos_permitidos_lista': modulos_permitidos_lista, 'paginas_permitidas_lista': paginas_permitidas_lista, 'permissao': permissao, 'data': datetime.datetime.now(), 'pagina': pagina, 'dict_permissoes': dict_permissoes, } return render(request, 'permissao_negada.html', context)
def salvar(request, pk=None, tab='master', output=None): from emensageriapro.esocial.models import STATUS_EVENTO_CADASTRADO from emensageriapro.settings import VERSAO_EMENSAGERIA, VERSAO_LAYOUT_ESOCIAL TP_AMB = config.ESOCIAL_TP_AMB if pk: s2206_evtaltcontratual = get_object_or_404(s2206evtAltContratual, id=pk) if request.user.has_perm('esocial.can_see_s2206evtAltContratual'): if pk: s2206_evtaltcontratual_form = form_s2206_evtaltcontratual( request.POST or None, instance=s2206_evtaltcontratual, initial={'ativo': True}) else: s2206_evtaltcontratual_form = form_s2206_evtaltcontratual( request.POST or None, initial={ 'versao': VERSAO_LAYOUT_ESOCIAL, 'status': STATUS_EVENTO_CADASTRADO, 'tpamb': TP_AMB, 'procemi': 1, 'verproc': VERSAO_EMENSAGERIA, 'ativo': True }) if request.method == 'POST': if s2206_evtaltcontratual_form.is_valid(): obj = s2206_evtaltcontratual_form.save(request=request) messages.success(request, u'Salvo com sucesso!') if not pk: from emensageriapro.functions import identidade_evento identidade_evento(obj, 'esocial') if 'return_page' in request.session and request.session[ 'return_page'] and 's2206-evtaltcontratual' not in request.session[ 'return_page']: return HttpResponseRedirect(request.session['return_page']) if pk != obj.id: return redirect('s2206_evtaltcontratual_salvar', pk=obj.id) else: messages.error(request, u'Erro ao salvar!') s2206_evtaltcontratual_form = disabled_form_fields( s2206_evtaltcontratual_form, request.user.has_perm('esocial.change_s2206evtAltContratual')) if pk: if s2206_evtaltcontratual.status != 0: s2206_evtaltcontratual_form = disabled_form_fields( s2206_evtaltcontratual_form, False) for field in s2206_evtaltcontratual_form.fields.keys(): s2206_evtaltcontratual_form.fields[field].widget.attrs[ 'ng-model'] = 's2206_evtaltcontratual_' + field if output: s2206_evtaltcontratual_form = disabled_form_for_print( s2206_evtaltcontratual_form) s2206_infoceletista_lista = None s2206_infoceletista_form = None s2206_infoestatutario_lista = None s2206_infoestatutario_form = None s2206_localtrabgeral_lista = None s2206_localtrabgeral_form = None s2206_localtrabdom_lista = None s2206_localtrabdom_form = None s2206_horcontratual_lista = None s2206_horcontratual_form = None s2206_filiacaosindical_lista = None s2206_filiacaosindical_form = None s2206_alvarajudicial_lista = None s2206_alvarajudicial_form = None s2206_observacoes_lista = None s2206_observacoes_form = None s2206_servpubl_lista = None s2206_servpubl_form = None if pk: s2206_evtaltcontratual = get_object_or_404(s2206evtAltContratual, id=pk) s2206_infoceletista_form = form_s2206_infoceletista( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_infoceletista_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_infoceletista_lista = s2206infoCeletista.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_infoestatutario_form = form_s2206_infoestatutario( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_infoestatutario_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_infoestatutario_lista = s2206infoEstatutario.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_localtrabgeral_form = form_s2206_localtrabgeral( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_localtrabgeral_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_localtrabgeral_lista = s2206localTrabGeral.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_localtrabdom_form = form_s2206_localtrabdom( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_localtrabdom_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_localtrabdom_lista = s2206localTrabDom.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_horcontratual_form = form_s2206_horcontratual( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_horcontratual_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_horcontratual_lista = s2206horContratual.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_filiacaosindical_form = form_s2206_filiacaosindical( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_filiacaosindical_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_filiacaosindical_lista = s2206filiacaoSindical.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_alvarajudicial_form = form_s2206_alvarajudicial( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_alvarajudicial_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_alvarajudicial_lista = s2206alvaraJudicial.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_observacoes_form = form_s2206_observacoes( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_observacoes_form.fields[ 's2206_evtaltcontratual'].widget.attrs['readonly'] = True s2206_observacoes_lista = s2206observacoes.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() s2206_servpubl_form = form_s2206_servpubl( initial={'s2206_evtaltcontratual': s2206_evtaltcontratual}) s2206_servpubl_form.fields['s2206_evtaltcontratual'].widget.attrs[ 'readonly'] = True s2206_servpubl_lista = s2206servPubl.objects.\ filter(s2206_evtaltcontratual_id=s2206_evtaltcontratual.id).all() else: s2206_evtaltcontratual = None tabelas_secundarias = [] controle_alteracoes = Auditoria.objects.filter( identidade=pk, tabela='s2206_evtaltcontratual').all() if not request.POST: request.session['return_page'] = request.META.get('HTTP_REFERER') context = { 'usuario': Usuarios.objects.get(user_id=request.user.id), 'pk': pk, 'output': output, 'evento_totalizador': False, 'controle_alteracoes': controle_alteracoes, 's2206_evtaltcontratual': s2206_evtaltcontratual, 's2206_evtaltcontratual_form': s2206_evtaltcontratual_form, 's2206_infoceletista_form': s2206_infoceletista_form, 's2206_infoceletista_lista': s2206_infoceletista_lista, 's2206_infoestatutario_form': s2206_infoestatutario_form, 's2206_infoestatutario_lista': s2206_infoestatutario_lista, 's2206_localtrabgeral_form': s2206_localtrabgeral_form, 's2206_localtrabgeral_lista': s2206_localtrabgeral_lista, 's2206_localtrabdom_form': s2206_localtrabdom_form, 's2206_localtrabdom_lista': s2206_localtrabdom_lista, 's2206_horcontratual_form': s2206_horcontratual_form, 's2206_horcontratual_lista': s2206_horcontratual_lista, 's2206_filiacaosindical_form': s2206_filiacaosindical_form, 's2206_filiacaosindical_lista': s2206_filiacaosindical_lista, 's2206_alvarajudicial_form': s2206_alvarajudicial_form, 's2206_alvarajudicial_lista': s2206_alvarajudicial_lista, 's2206_observacoes_form': s2206_observacoes_form, 's2206_observacoes_lista': s2206_observacoes_lista, 's2206_servpubl_form': s2206_servpubl_form, 's2206_servpubl_lista': s2206_servpubl_lista, 'data': datetime.datetime.now(), 'modulos': [ 'esocial', ], 'paginas': [ 's2206_evtaltcontratual', ], 'tabelas_secundarias': tabelas_secundarias, 'tab': tab, } if output == 'pdf': response = PDFTemplateResponse( request=request, template='s2206_evtaltcontratual_salvar.html', filename="s2206_evtaltcontratual.pdf", context=context, show_content_in_browser=True, cmd_options={ 'margin-top': 10, 'margin-bottom': 10, 'margin-right': 10, 'margin-left': 10, 'zoom': 1, 'dpi': 72, 'orientation': 'Landscape', "viewport-size": "1366 x 513", 'javascript-delay': 1000, 'footer-center': '[page]/[topage]', "no-stop-slow-scripts": True }, ) return response elif output == 'xls': response = render_to_response('s2206_evtaltcontratual_salvar.html', context) filename = "s2206_evtaltcontratual.xls" response[ 'Content-Disposition'] = 'attachment; filename=' + filename response[ 'Content-Type'] = 'application/vnd.ms-excel; charset=UTF-8' return response else: return render(request, 's2206_evtaltcontratual_salvar.html', context) else: context = { 'usuario': Usuarios.objects.get(user_id=request.user.id), 'pk': pk, 'tab': tab, 'output': output, 'modulos': [ 'esocial', ], 'paginas': [ 's2206_evtaltcontratual', ], 'data': datetime.datetime.now(), } return render(request, 'permissao_negada.html', context)