Browse Source

Ajuste cad de Autor com funcionalidades para admin

pull/752/head
LeandroRoberto 8 years ago
parent
commit
ffbd1eb2dc
  1. 65
      sapl/base/forms.py
  2. 12
      sapl/base/views.py
  3. 12
      sapl/static/js/app.js
  4. 33
      sapl/static/styles/app.scss

65
sapl/base/forms.py

@ -152,15 +152,6 @@ class AutorForm(ModelForm):
choices=ACTION_CREATE_USERS_AUTOR_CHOICE, choices=ACTION_CREATE_USERS_AUTOR_CHOICE,
widget=forms.RadioSelect()) 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: class Meta:
model = Autor model = Autor
fields = ['tipo', fields = ['tipo',
@ -205,13 +196,17 @@ class AutorForm(ModelForm):
to_column(('confirma_email', 3)), to_column(('confirma_email', 3)),
css_class='new_user_fields hidden') css_class='new_user_fields hidden')
row4 = Row(to_column((Div(InlineRadios('status_user'), row4 = Row(to_column((
css_class='radiogroup-status hidden'), 12))) Div(InlineRadios('status_user'),
css_class='radiogroup-status hidden'),
12))) if 'status_user' in self.Meta.fields else None
controle_acesso = Fieldset( controle_acesso = [row2, row3]
_('Controle de Acesso do Autor'),
row2, row3, row4 if row4:
) controle_acesso.append(row4)
controle_acesso = Fieldset(_('Controle de Acesso do Autor'),
*controle_acesso)
self.helper = FormHelper() self.helper = FormHelper()
self.helper.layout = SaplFormLayout(autor_select, controle_acesso) self.helper.layout = SaplFormLayout(autor_select, controle_acesso)
@ -227,23 +222,27 @@ class AutorForm(ModelForm):
self.instance.autor_related)] self.instance.autor_related)]
self.fields['q'].initial = '' self.fields['q'].initial = ''
self.fields[ self.fields['autor_related'].initial = self.instance.autor_related
'autor_related'].initial = self.instance.autor_related
if self.instance.user: if self.instance.user:
self.fields['username'].initial = self.instance.user.username self.fields['username'].initial = self.instance.user.username
self.fields['action_user'].initial = 'A' self.fields['action_user'].initial = 'A'
self.fields['status_user'].initial = 'R'
self.fields['username'].label = string_concat( self.fields['username'].label = string_concat(
self.fields['username'].label, self.fields['username'].label,
' (', self.instance.user.username, ')') ' (', 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 = string_concat(
self.fields['status_user'].label, self.fields['status_user'].label,
' (', self.instance.user.username, ')') ' (', self.instance.user.username, ')')
self.fields['username'].widget.attrs.update({ self.fields['username'].widget.attrs.update({
'data': self.instance.user.username 'data': self.instance.user.username
if self.instance.user else ''}) if self.instance.user else ''})
if 'status_user' in self.Meta.fields:
self.fields['status_user'].widget.attrs.update({ self.fields['status_user'].widget.attrs.update({
'data': self.instance.user.username 'data': self.instance.user.username
if self.instance.user else ''}) if self.instance.user else ''})
@ -261,13 +260,14 @@ class AutorForm(ModelForm):
raise ValidationError(_('Informe se o Autor terá usuário ' raise ValidationError(_('Informe se o Autor terá usuário '
'vinculado para acesso ao Sistema.')) 'vinculado para acesso ao Sistema.'))
if 'status_user' in self.Meta.fields:
if self.instance.pk and self.instance.user_id: if self.instance.pk and self.instance.user_id:
if self.instance.user.username != cd['username']: if self.instance.user.username != cd['username']:
if 'status_user' not in cd or not cd['status_user']: if 'status_user' not in cd or not cd['status_user']:
raise ValidationError( raise ValidationError(
_('Foi trocado ou removido o usuário deste Autor, ' _('Foi trocado ou removido o usuário deste Autor, '
'mas não foi informado como se deve proceder com o ' 'mas não foi informado como se deve proceder '
'usuário que está sendo desvinculado?')) 'com o usuário que está sendo desvinculado?'))
qs_user = User.objects.all() qs_user = User.objects.all()
qs_autor = Autor.objects.all() qs_autor = Autor.objects.all()
@ -406,6 +406,7 @@ class AutorForm(ModelForm):
user_old.groups.remove(grupo) user_old.groups.remove(grupo)
else: else:
if 'status_user' in self.Meta.fields:
if 'status_user' in self.cleaned_data and user_old: if 'status_user' in self.cleaned_data and user_old:
if self.cleaned_data['status_user'] == 'X': if self.cleaned_data['status_user'] == 'X':
user_old.delete() user_old.delete()
@ -419,10 +420,34 @@ class AutorForm(ModelForm):
user_old.groups.remove(grupo) user_old.groups.remove(grupo)
elif user_old: elif user_old:
user_old.groups.remove(grupo) user_old.groups.remove(grupo)
else:
user_old.groups.remove(grupo)
return autor 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): class RelatorioAtasFilterSet(django_filters.FilterSet):
filter_overrides = {models.DateField: { filter_overrides = {models.DateField: {

12
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.views.generic.base import TemplateView
from django_filters.views import FilterView 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.base.models import Autor, TipoAutor
from sapl.crud.base import CrudAux from sapl.crud.base import CrudAux
from sapl.materia.models import MateriaLegislativa, TipoMateriaLegislativa 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 # devido a implement do form o form_valid do Crud deve ser pulado
return super(CrudAux.UpdateView, self).form_valid(form) 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): def get_success_url(self):
# FIXME try except - testar envio de emails # 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 # devido a implement do form o form_valid do Crud deve ser pulado
return super(CrudAux.CreateView, self).form_valid(form) 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): def get_success_url(self):
pk_autor = self.object.id pk_autor = self.object.id
try: try:

12
sapl/static/js/app.js

@ -150,9 +150,21 @@ function autorModal() {
get_nome_autor("#id_autoria__autor");*/ 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(){ $(document).ready(function(){
refreshDatePicker(); refreshDatePicker();
refreshMask(); refreshMask();
autorModal(); autorModal();
initTinymce("texto-rico"); initTinymce("texto-rico");
customsFront();
}); });

33
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 ######################################## // #### CRUD DETAIL ########################################
p.control-label { p.control-label {

Loading…
Cancel
Save