diff --git a/compilacao/forms.py b/compilacao/forms.py index f6d333309..e98b5cc53 100644 --- a/compilacao/forms.py +++ b/compilacao/forms.py @@ -264,87 +264,28 @@ class NotaForm(ModelForm): super(NotaForm, self).__init__(*args, **kwargs) -class DispositivoSearchFragmentForm(ModelForm): - - tipo_ta = forms.ModelChoiceField( - label=_('Tipo do Texto Articulado'), - queryset=TipoTextoArticulado.objects.all(), - required=False) - - tipo_model = forms.ChoiceField( - choices=[], - label=_('Tipos de...'), required=False) - - num_ta = forms.IntegerField( - label=_('Número'), required=False) - ano_ta = forms.IntegerField( - label=_('Ano'), required=False) - - rotulo_dispositivo = forms.CharField( - label=_('Rótulo'), - required=False) - - texto_dispositivo = forms.CharField( - label=_('Pesquisa Textual'), - required=False) - - def __init__(self, *args, **kwargs): - - if 'fields_search' in kwargs: - fields_search = kwargs['fields_search'].fields - - fields_search.append(Fieldset( - _('Busca por um Dispositivo'), - Row( - to_column(('num_ta', 6)), - to_column(('ano_ta', 6))), - Row( - to_column(('tipo_ta', 6)), - to_column(('tipo_model', 6))), - Row(to_column(('rotulo_dispositivo', 3)), - to_column((FieldWithButtons( - Field( - 'texto_dispositivo', - placeholder=_('Digite palavras, letras, ' - 'números ou algo' - ' que estejam no texto.')), - StrictButton(_('Buscar'), css_class='btn-busca')), 9))) - )) - - fields_search.append( - Row(to_column( - (Div(css_class='result-busca-dispositivo'), 12)))) - kwargs.pop('fields_search') - - if 'choice_model_type_foreignkey_in_extenal_views' in kwargs: - ch = kwargs.pop('choice_model_type_foreignkey_in_extenal_views') - if 'data' in kwargs: - choice = ch(kwargs['data']['tipo_ta']) - self.base_fields['tipo_model'].choices = choice - elif 'instance' in kwargs and\ - isinstance(kwargs['instance'], Dispositivo): - choice = ch(kwargs['instance'].ta.tipo_ta_id) - self.base_fields['tipo_model'].choices = choice - - super(DispositivoSearchFragmentForm, self).__init__(*args, **kwargs) - - -class VideForm(DispositivoSearchFragmentForm): +class VideForm(ModelForm): dispositivo_base = forms.ModelChoiceField( queryset=Dispositivo.objects.all(), widget=forms.HiddenInput()) + dispositivo_ref = forms.ModelChoiceField( - queryset=Dispositivo.objects.all(), - widget=forms.HiddenInput()) + label=Vide._meta.get_field( + 'dispositivo_ref').verbose_name, + queryset=Dispositivo.objects.all()) tipo = forms.ModelChoiceField( label=TipoVide._meta.verbose_name, queryset=TipoVide.objects.all(), required=True, error_messages=error_messages) + texto = forms.CharField( + required=False, + label=Vide._meta.get_field( + 'texto').verbose_name, + widget=forms.Textarea()) - pk = forms.IntegerField(widget=forms.HiddenInput(), - required=False) + pk = forms.IntegerField(widget=forms.HiddenInput(), required=False) class Meta: model = Vide @@ -371,26 +312,34 @@ class VideForm(DispositivoSearchFragmentForm): css_class='btn-primary pull-right') ) - fields_form = Div( + dispositivo_ref = Field( + 'dispositivo_ref', + data_sapl_ta='DispositivoSearch', + data_field='dispositivo_ref', + data_type_selection='radio', + template="compilacao/layout/dispositivo_radio.html") + + fields_form = [] + fields_form.append(Div( Row(to_column((Field( 'tipo', placeholder=_('Selecione um Tipo de Vide')), 12))), + Row(to_column((dispositivo_ref, 12))), + Row(to_column((buttons, 12))))) + + fields_form.append(Div( Row(to_column((Field( 'texto', - placeholder=_('Texto Adicional ao Vide')), 12))), - Row(to_column((buttons, 12)))) - - kwargs['fields_search'] = fields_search = Div() + placeholder=_('Texto Adicional ao Vide')), 12))))) self.helper = FormHelper() self.helper.layout = Layout( Div( Div(HTML(_('Vides')), css_class='panel-heading'), Div( - to_column(( - fields_form, 4)), - to_column(( - fields_search, 8)), css_class="panel-body" + to_column((fields_form[0], 6)), + to_column((fields_form[1], 6)), + css_class="panel-body" ), css_class="panel panel-primary" ) @@ -398,6 +347,12 @@ class VideForm(DispositivoSearchFragmentForm): super(VideForm, self).__init__(*args, **kwargs) + self.fields['dispositivo_ref'].choices = [] + if self.instance and self.instance.dispositivo_ref_id: + self.fields['dispositivo_ref'].choices = [ + (self.instance.dispositivo_ref.pk, + self.instance.dispositivo_ref)] + class PublicacaoForm(ModelForm): diff --git a/compilacao/views.py b/compilacao/views.py index 1f14f9685..582c4ca70 100644 --- a/compilacao/views.py +++ b/compilacao/views.py @@ -400,8 +400,7 @@ class VideMixin(DispositivoSuccessUrlMixin): def get_initial(self): dispositivo_base = get_object_or_404( Dispositivo, pk=self.kwargs.get('dispositivo_id')) - - initial = {'dispositivo_base': dispositivo_base} + initial = {'dispositivo_base': dispositivo_base, } if 'pk' in self.kwargs: initial['pk'] = self.kwargs.get('pk') @@ -440,7 +439,7 @@ class VideCreateView(VideMixin, CreateView): self.object = None form = self.get_form() return self.render_to_response(self.get_context_data(form=form)) - +""" def get_form_kwargs(self): kwargs = super(VideCreateView, self).get_form_kwargs() @@ -451,7 +450,7 @@ class VideCreateView(VideMixin, CreateView): choice_model_type_foreignkey_in_extenal_views }) - return kwargs + return kwargs""" class VideEditView(VideMixin, UpdateView): diff --git a/materia/test_materia_urls.py b/materia/test_materia_urls.py index 0ff4aba0e..9814612a7 100644 --- a/materia/test_materia_urls.py +++ b/materia/test_materia_urls.py @@ -1,6 +1,5 @@ import pytest from django.core.urlresolvers import reverse -import pytest @pytest.mark.parametrize("test_input,kwargs,expected", [ diff --git a/static/js/compilacao.js b/static/js/compilacao.js index 058801b65..22093eed5 100644 --- a/static/js/compilacao.js +++ b/static/js/compilacao.js @@ -57,7 +57,7 @@ function DispostivoSearch(opts) { var dpts = field.find('input'); dpts.off() dpts.attr('type', 'hidden'); - $('') + $('') .insertBefore(dpts) .append($('')) .on('click', function() { diff --git a/static/js/compilacao_notas.js b/static/js/compilacao_notas.js index 47409054a..487cfb5ec 100644 --- a/static/js/compilacao_notas.js +++ b/static/js/compilacao_notas.js @@ -23,9 +23,11 @@ function onEventsDneExec(pk, model) { }); } else if (model == 'vide') { - configFormSearchTA('#dne'+pk, 'radio', 'select_for_vide'); - onChangeParamTA(); + DispostivoSearch({ + 'url_form': '/ta/search_form', + 'text_button': 'Definir Dispositivo' + }); } } @@ -38,7 +40,7 @@ var onSubmitEditNVForm = function(event) { var id_dispositivo = $('#id_dispositivo').val(); if (id_dispositivo == null) { // trata-se de um vide - $('#id_dispositivo_ref').remove(); + //$('#id_dispositivo_ref').remove(); id_dispositivo = $('#id_dispositivo_base').val(); model='vide'; } diff --git a/static/js/compilacao_view.js b/static/js/compilacao_view.js index 83303432c..0c15435dd 100644 --- a/static/js/compilacao_view.js +++ b/static/js/compilacao_view.js @@ -136,9 +136,13 @@ $(document).ready(function() { setTimeout(function() { var href = location.href.split('#') if (href.length == 2) { - $('html, body').animate({ - scrollTop: $('#dptt' + href[1] ).offset().top - window.innerHeight / 9 - }, 0); + try { + $('html, body').animate({ + scrollTop: $('#dptt' + href[1] ).offset().top - window.innerHeight / 9 + }, 0); + } + catch(err) { + } } }, 100); diff --git a/templates/compilacao/layout/dispositivo_checkbox_old.html b/templates/compilacao/layout/dispositivo_checkbox_old.html deleted file mode 100644 index ec994877d..000000000 --- a/templates/compilacao/layout/dispositivo_checkbox_old.html +++ /dev/null @@ -1,54 +0,0 @@ -{% load crispy_forms_filters %} -{% load i18n compilacao_filters common_tags%} - - -
- {% include 'bootstrap/layout/field_errors_block.html' %} - - - - - {% for choice, dpt in field.field.choices %} - {% ifchanged dpt.ta%} - {% if not forloop.first %}{% endif %} - {% endif %} - {% endfor %} - - - - {% include 'bootstrap/layout/help_text.html' %} -