From 621ad13f737c8b4ecb5f4ba5645673e995ca1c6c Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Mon, 7 Mar 2016 10:23:20 -0300 Subject: [PATCH] =?UTF-8?q?Setar=20dispositivo=20de=20vig=C3=AAncia?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- compilacao/forms.py | 26 +++++++++++++++++ compilacao/templatetags/compilacao_filters.py | 2 +- compilacao/urls.py | 3 ++ compilacao/views.py | 28 +++++++++++++------ static/js/compilacao_edit.js | 7 +++++ templates/compilacao/publicacao_list.html | 3 -- templates/compilacao/text_edit_bloco.html | 23 +++++++++------ .../compilacao/textoarticulado_detail.html | 2 +- 8 files changed, 71 insertions(+), 23 deletions(-) diff --git a/compilacao/forms.py b/compilacao/forms.py index 68d74191e..1b8d39c9f 100644 --- a/compilacao/forms.py +++ b/compilacao/forms.py @@ -136,6 +136,17 @@ class TaForm(ModelForm): ) super(TaForm, self).__init__(*args, **kwargs) + instance = getattr(self, 'instance', None) + if instance and instance.pk: + self.fields['tipo_ta'].widget.attrs['disabled'] = True + self.fields['tipo_ta'].required = False + + def clean_tipo_ta(self): + instance = getattr(self, 'instance', None) + if instance and instance.pk: + return instance.tipo_ta + else: + return self.cleaned_data['tipo_ta'] class NotaForm(ModelForm): @@ -451,3 +462,18 @@ class PublicacaoForm(ModelForm): super(PublicacaoForm, self).__init__(*args, **kwargs) pass + + +class DispositivoForm(ModelForm): + + class Meta: + model = Dispositivo + fields = [] + + def __init__(self, *args, **kwargs): + self.helper = FormHelper() + """self.helper.layout = SaplFormLayout( + Fieldset(Publicacao._meta.verbose_name, + row1, row2, row3, css_class="col-md-12"))""" + + super(PublicacaoForm, self).__init__(*args, **kwargs) diff --git a/compilacao/templatetags/compilacao_filters.py b/compilacao/templatetags/compilacao_filters.py index ac5bc4297..6372ba127 100644 --- a/compilacao/templatetags/compilacao_filters.py +++ b/compilacao/templatetags/compilacao_filters.py @@ -93,7 +93,7 @@ def isinst(value, class_str): @register.filter def render_actions_head(view, d_atual): - if view.__class__.__name__ != 'DispositivoEditView': + if view.__class__.__name__ != 'DispositivoSimpleEditView': return False # Menu diff --git a/compilacao/urls.py b/compilacao/urls.py index b3329a16d..0a2948be8 100644 --- a/compilacao/urls.py +++ b/compilacao/urls.py @@ -31,6 +31,9 @@ urlpatterns_compilacao = [ views.DispositivoView.as_view(), name='dispositivo'), url(r'^(?P[0-9]+)/text/(?P[0-9]+)/refresh', + views.DispositivoSimpleEditView.as_view(), name='dispositivo_refresh'), + + url(r'^(?P[0-9]+)/text/(?P[0-9]+)/edit', views.DispositivoEditView.as_view(), name='dispositivo_edit'), url(r'^(?P[0-9]+)/text/(?P[0-9]+)/actions', diff --git a/compilacao/views.py b/compilacao/views.py index 222935674..557ae2c49 100644 --- a/compilacao/views.py +++ b/compilacao/views.py @@ -1,6 +1,6 @@ -import sys from collections import OrderedDict from datetime import datetime, timedelta +import sys from braces.views import FormMessagesMixin from django import forms @@ -21,7 +21,7 @@ from django.views.generic.edit import CreateView, DeleteView, UpdateView from django.views.generic.list import ListView from compilacao.forms import (NotaForm, PublicacaoForm, TaForm, TipoTaForm, - VideForm) + VideForm, DispositivoForm) from compilacao.models import (Dispositivo, Nota, PerfilEstruturalTextoArticulado, Publicacao, TextoArticulado, TipoDispositivo, TipoNota, @@ -29,6 +29,7 @@ from compilacao.models import (Dispositivo, Nota, VeiculoPublicacao, Vide) from crud.base import Crud, CrudListView, make_pagination + DISPOSITIVO_SELECT_RELATED = ( 'tipo_dispositivo', 'ta_publicado', @@ -162,7 +163,7 @@ class TipoTaListView(ListView): class TipoTaCreateView(FormMessagesMixin, CreateView): model = TipoTextoArticulado form_class = TipoTaForm - template_name = "compilacao/form.html" + template_name = "crud/form.html" form_valid_message = _('Registro criado com sucesso!') form_invalid_message = _('O registro não foi criado.') @@ -191,7 +192,7 @@ class TipoTaDetailView(CompMixin, DetailView): class TipoTaUpdateView(CompMixin, UpdateView): model = TipoTextoArticulado form_class = TipoTaForm - template_name = "compilacao/form.html" + template_name = "crud/form.html" def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -264,7 +265,7 @@ class TaDetailView(DetailView): class TaCreateView(FormMessagesMixin, CreateView): model = TextoArticulado form_class = TaForm - template_name = "compilacao/form.html" + template_name = "crud/form.html" form_valid_message = _('Registro criado com sucesso!') form_invalid_message = _('O registro não foi criado.') @@ -280,7 +281,7 @@ class TaCreateView(FormMessagesMixin, CreateView): class TaUpdateView(CompMixin, UpdateView): model = TextoArticulado form_class = TaForm - template_name = "compilacao/form.html" + template_name = "crud/form.html" def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -662,7 +663,7 @@ class TextEditView(ListView, CompMixin): request.session['perfil_estrutural'] = perfis[0].pk -class DispositivoEditView(TextEditView): +class DispositivoSimpleEditView(TextEditView): template_name = 'compilacao/text_edit_bloco.html' def post(self, request, *args, **kwargs): @@ -1012,6 +1013,9 @@ class ActionsEditMixin: action = getattr(self, context['action']) return JsonResponse(action(context), safe=False) + def set_dvt(self, context): + return {} + def delete_item_dispositivo(self, context): return self.delete_bloco_dispositivo(context, bloco=False) @@ -1911,7 +1915,7 @@ class PublicacaoListView(ListView): class PublicacaoCreateView(FormMessagesMixin, CreateView): model = Publicacao form_class = PublicacaoForm - template_name = "compilacao/form.html" + template_name = "crud/form.html" form_valid_message = _('Registro criado com sucesso!') form_invalid_message = _('O registro não foi criado.') @@ -1939,7 +1943,7 @@ class PublicacaoDetailView(CompMixin, DetailView): class PublicacaoUpdateView(CompMixin, UpdateView): model = Publicacao form_class = PublicacaoForm - template_name = "compilacao/form.html" + template_name = "crud/form.html" def get(self, request, *args, **kwargs): self.object = self.get_object() @@ -1974,3 +1978,9 @@ class PublicacaoDeleteView(CompMixin, DeleteView): def get_success_url(self): return reverse_lazy('compilacao:ta_pub_list', kwargs={'ta_id': self.kwargs['ta_id']}) + + +class DispositivoEditView(CompMixin, UpdateView): + model = Dispositivo + form_class = DispositivoForm + template_name = "crud/form.html" diff --git a/static/js/compilacao_edit.js b/static/js/compilacao_edit.js index 0e04d15b7..e23e547d6 100644 --- a/static/js/compilacao_edit.js +++ b/static/js/compilacao_edit.js @@ -105,6 +105,13 @@ var clickUpdateDispositivo = function(event, __pk_refresh, __pk_edit, __action, $("#message_block").css("display", "block"); + } + else if (_action.startsWith('set_')) { + + url = pk_refresh+'/actions?action='+_action; + + $("#message_block").css("display", "block"); + } else if (_action.startsWith('delete_')) { var r = confirm("Confirma Exclusão deste dispositivo?"); diff --git a/templates/compilacao/publicacao_list.html b/templates/compilacao/publicacao_list.html index fb80695b6..1c56a343a 100644 --- a/templates/compilacao/publicacao_list.html +++ b/templates/compilacao/publicacao_list.html @@ -9,9 +9,6 @@ {% trans 'Adicionar'%} {%model_verbose_name 'compilacao.models.Publicacao'%} - - {% trans 'Voltar' %} - {% if not object_list %} diff --git a/templates/compilacao/text_edit_bloco.html b/templates/compilacao/text_edit_bloco.html index cf4b0544d..30bc6a2d5 100644 --- a/templates/compilacao/text_edit_bloco.html +++ b/templates/compilacao/text_edit_bloco.html @@ -9,7 +9,7 @@ {% close_div view.flag_nivel_old dpt.nivel 0 %} {% endif%} - {% if forloop.first and view|isinst:'DispositivoEditView' %} + {% if forloop.first and view|isinst:'DispositivoSimpleEditView' %} {% else %}
{% endif%} @@ -25,13 +25,18 @@
  • E*
  • C
  • + {% endblock %}