From ffbd1eb2dcf7d19314ae99d5733a7878ffe1bdfb Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Tue, 18 Oct 2016 14:35:44 -0200 Subject: [PATCH 1/3] Ajuste cad de Autor com funcionalidades para admin --- sapl/base/forms.py | 109 ++++++++++++++++++++++-------------- sapl/base/views.py | 12 +++- sapl/static/js/app.js | 12 ++++ sapl/static/styles/app.scss | 33 +++++++++++ 4 files changed, 123 insertions(+), 43 deletions(-) diff --git a/sapl/base/forms.py b/sapl/base/forms.py index 3fa1f456d..437616bf8 100644 --- a/sapl/base/forms.py +++ b/sapl/base/forms.py @@ -152,15 +152,6 @@ class AutorForm(ModelForm): choices=ACTION_CREATE_USERS_AUTOR_CHOICE, widget=forms.RadioSelect()) - status_user = forms.ChoiceField( - label=_('Bloqueio do Usuário Existente'), - choices=STATUS_USER_CHOICE, - widget=forms.RadioSelect(), - required=False, - help_text=_('Se vc está trocando ou removendo o usuário deste Autor, ' - 'como o Sistema deve proceder com o usuário que está sendo' - ' desvinculado?')) - class Meta: model = Autor fields = ['tipo', @@ -205,13 +196,17 @@ class AutorForm(ModelForm): to_column(('confirma_email', 3)), css_class='new_user_fields hidden') - row4 = Row(to_column((Div(InlineRadios('status_user'), - css_class='radiogroup-status hidden'), 12))) + row4 = Row(to_column(( + Div(InlineRadios('status_user'), + css_class='radiogroup-status hidden'), + 12))) if 'status_user' in self.Meta.fields else None - controle_acesso = Fieldset( - _('Controle de Acesso do Autor'), - row2, row3, row4 - ) + controle_acesso = [row2, row3] + + if row4: + controle_acesso.append(row4) + controle_acesso = Fieldset(_('Controle de Acesso do Autor'), + *controle_acesso) self.helper = FormHelper() self.helper.layout = SaplFormLayout(autor_select, controle_acesso) @@ -227,26 +222,30 @@ class AutorForm(ModelForm): self.instance.autor_related)] self.fields['q'].initial = '' - self.fields[ - 'autor_related'].initial = self.instance.autor_related + self.fields['autor_related'].initial = self.instance.autor_related if self.instance.user: self.fields['username'].initial = self.instance.user.username self.fields['action_user'].initial = 'A' - self.fields['status_user'].initial = 'R' + self.fields['username'].label = string_concat( self.fields['username'].label, ' (', self.instance.user.username, ')') - self.fields['status_user'].label = string_concat( - self.fields['status_user'].label, - ' (', self.instance.user.username, ')') + + if 'status_user' in self.Meta.fields: + self.fields['status_user'].initial = 'R' + self.fields['status_user'].label = string_concat( + self.fields['status_user'].label, + ' (', self.instance.user.username, ')') + self.fields['username'].widget.attrs.update({ 'data': self.instance.user.username if self.instance.user else ''}) - self.fields['status_user'].widget.attrs.update({ - 'data': self.instance.user.username - if self.instance.user else ''}) + if 'status_user' in self.Meta.fields: + self.fields['status_user'].widget.attrs.update({ + 'data': self.instance.user.username + if self.instance.user else ''}) def valida_igualdade(self, texto1, texto2, msg): if texto1 != texto2: @@ -261,13 +260,14 @@ class AutorForm(ModelForm): raise ValidationError(_('Informe se o Autor terá usuário ' 'vinculado para acesso ao Sistema.')) - if self.instance.pk and self.instance.user_id: - if self.instance.user.username != cd['username']: - if 'status_user' not in cd or not cd['status_user']: - raise ValidationError( - _('Foi trocado ou removido o usuário deste Autor, ' - 'mas não foi informado como se deve proceder com o ' - 'usuário que está sendo desvinculado?')) + if 'status_user' in self.Meta.fields: + if self.instance.pk and self.instance.user_id: + if self.instance.user.username != cd['username']: + if 'status_user' not in cd or not cd['status_user']: + raise ValidationError( + _('Foi trocado ou removido o usuário deste Autor, ' + 'mas não foi informado como se deve proceder ' + 'com o usuário que está sendo desvinculado?')) qs_user = User.objects.all() qs_autor = Autor.objects.all() @@ -406,23 +406,48 @@ class AutorForm(ModelForm): user_old.groups.remove(grupo) else: - if 'status_user' in self.cleaned_data and user_old: - if self.cleaned_data['status_user'] == 'X': - user_old.delete() - - elif self.cleaned_data['status_user'] == 'D': - user_old.groups.remove(grupo) - user_old.is_active = False - user_old.save() - - elif self.cleaned_data['status_user'] == 'R': + if 'status_user' in self.Meta.fields: + if 'status_user' in self.cleaned_data and user_old: + if self.cleaned_data['status_user'] == 'X': + user_old.delete() + + elif self.cleaned_data['status_user'] == 'D': + user_old.groups.remove(grupo) + user_old.is_active = False + user_old.save() + + elif self.cleaned_data['status_user'] == 'R': + user_old.groups.remove(grupo) + elif user_old: user_old.groups.remove(grupo) - elif user_old: + else: user_old.groups.remove(grupo) return autor +class AutorFormForAdmin(AutorForm): + status_user = forms.ChoiceField( + label=_('Bloqueio do Usuário Existente'), + choices=STATUS_USER_CHOICE, + widget=forms.RadioSelect(), + required=False, + help_text=_('Se vc está trocando ou removendo o usuário deste Autor, ' + 'como o Sistema deve proceder com o usuário que está sendo' + ' desvinculado?')) + + class Meta: + model = Autor + fields = ['tipo', + 'nome', + 'cargo', + 'autor_related', + 'q', + 'action_user', + 'username', + 'status_user'] + + class RelatorioAtasFilterSet(django_filters.FilterSet): filter_overrides = {models.DateField: { diff --git a/sapl/base/views.py b/sapl/base/views.py index 89aaec991..83cc776f1 100644 --- a/sapl/base/views.py +++ b/sapl/base/views.py @@ -13,7 +13,7 @@ from django.utils.translation import ugettext_lazy as _ from django.views.generic.base import TemplateView from django_filters.views import FilterView -from sapl.base.forms import AutorForm, TipoAutorForm +from sapl.base.forms import AutorForm, TipoAutorForm, AutorFormForAdmin from sapl.base.models import Autor, TipoAutor from sapl.crud.base import CrudAux from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa @@ -69,6 +69,11 @@ class AutorCrud(CrudAux): # devido a implement do form o form_valid do Crud deve ser pulado return super(CrudAux.UpdateView, self).form_valid(form) + def get(self, request, *args, **kwargs): + if request.user.is_superuser: + self.form_class = AutorFormForAdmin + return CrudAux.UpdateView.get(self, request, *args, **kwargs) + def get_success_url(self): # FIXME try except - testar envio de emails @@ -115,6 +120,11 @@ class AutorCrud(CrudAux): # devido a implement do form o form_valid do Crud deve ser pulado return super(CrudAux.CreateView, self).form_valid(form) + def get(self, request, *args, **kwargs): + if request.user.is_superuser: + self.form_class = AutorFormForAdmin + return CrudAux.CreateView.get(self, request, *args, **kwargs) + def get_success_url(self): pk_autor = self.object.id try: diff --git a/sapl/static/js/app.js b/sapl/static/js/app.js index 15e744fd6..380b55c9a 100644 --- a/sapl/static/js/app.js +++ b/sapl/static/js/app.js @@ -150,9 +150,21 @@ function autorModal() { get_nome_autor("#id_autoria__autor");*/ } + +var customsFront = function() { + $('[type=radio], [type=checkbox]').each(function() { + var $controls = $(this).closest('.controls') + $controls && !$controls.hasClass('controls-radio-checkbox') && $controls.addClass('controls-radio-checkbox') + }); + +} + $(document).ready(function(){ refreshDatePicker(); refreshMask(); autorModal(); initTinymce("texto-rico"); + + + customsFront(); }); diff --git a/sapl/static/styles/app.scss b/sapl/static/styles/app.scss index ac0390bc3..0a32a7ac4 100644 --- a/sapl/static/styles/app.scss +++ b/sapl/static/styles/app.scss @@ -113,6 +113,39 @@ h6, .h6 { } } +.controls-radio-checkbox { + padding: 0px; + border: 1px solid #d6e1e5; + border-radius: 4px; + .help-block { + margin: $grid-gutter-width / 2; + padding: $grid-gutter-width / 2; + border: 2px dashed #d6e1e5; + } + + label { + padding: 5px; + .icons { + top: 5px; + left: 8px; + } + &.checkbox-inline, &.radio-inline { + padding: 8px; + padding-left: 36px; + .icons { + top: 8px; + left: 8px; + } + } + } + .checkbox, .radio, .checkbox-inline, .radio-inline { + margin: 0; + &:hover { + background-color: #d6e1e5;; + } + } +} + // #### CRUD DETAIL ######################################## p.control-label { From 5145f32aa52968184fc003f6741827a350865da2 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Tue, 18 Oct 2016 14:37:29 -0200 Subject: [PATCH 2/3] =?UTF-8?q?Ajuste=20na=20caixa=20de=20sele=C3=A7=C3=A3?= =?UTF-8?q?o=20de=20possiveis=20autores?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- sapl/static/styles/app.scss | 1 + 1 file changed, 1 insertion(+) diff --git a/sapl/static/styles/app.scss b/sapl/static/styles/app.scss index 0a32a7ac4..8db570b01 100644 --- a/sapl/static/styles/app.scss +++ b/sapl/static/styles/app.scss @@ -117,6 +117,7 @@ h6, .h6 { padding: 0px; border: 1px solid #d6e1e5; border-radius: 4px; + min-height: 20px; .help-block { margin: $grid-gutter-width / 2; padding: $grid-gutter-width / 2; From 26a3ee8656f9e91f4c0706f7a7762c879f047672 Mon Sep 17 00:00:00 2001 From: Leandro Roberto da Silva Date: Tue, 18 Oct 2016 16:59:06 -0200 Subject: [PATCH 3/3] Incl biblioteca pre-requisito p acesso ao SAPL 2.5 --- README.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/README.rst b/README.rst index c245a89aa..6a7a74b91 100644 --- a/README.rst +++ b/README.rst @@ -31,7 +31,7 @@ Instalar as seguintes dependências do sistema:: sudo apt-get install git nginx python3-dev libpq-dev graphviz-dev graphviz \ pkg-config postgresql postgresql-contrib pgadmin3 python-psycopg2 \ software-properties-common build-essential libxml2-dev libjpeg-dev \ - libssl-dev libffi-dev libxslt1-dev python3-setuptools curl + libmysqlclient-dev libssl-dev libffi-dev libxslt1-dev python3-setuptools curl sudo easy_install3 pip lxml