Browse Source

CRUD TextoArticulado completado.

pull/98/head
LeandroRoberto 9 years ago
parent
commit
232ae637e5
  1. 15
      compilacao/forms.py
  2. 23
      compilacao/migrations/0036_auto_20151224_1341.py
  3. 19
      compilacao/migrations/0037_auto_20151224_1348.py
  4. 24
      compilacao/migrations/0038_auto_20151224_1429.py
  5. 16
      compilacao/models.py
  6. 8
      compilacao/urls.py
  7. 34
      compilacao/views.py
  8. 2
      norma/urls.py
  9. 6
      sapl/settings.py
  10. 20
      templates/compilacao/textoarticulado_confirm_delete.html
  11. 128
      templates/compilacao/textoarticulado_detail.html
  12. 14
      templates/compilacao/textoarticulado_list.html

15
compilacao/forms.py

@ -9,6 +9,7 @@ from django.core.exceptions import NON_FIELD_ERRORS
from django.forms.models import ModelForm
from django.utils.translation import ugettext_lazy as _
from compilacao import utils, models
from compilacao.models import Dispositivo, Nota, TipoNota, TipoVide, Vide,\
TextoArticulado, TipoTextoArticulado
from compilacao.utils import to_row, to_column
@ -56,6 +57,10 @@ class TaForm(ModelForm):
widget=forms.Textarea,
error_messages=ta_error_messages,
required=False)
participacao_social = forms.NullBooleanField(
label=_('Participação Social'),
widget=forms.Select(choices=models.PARTICIPACAO_SOCIAL_CHOICES),
required=False)
class Meta:
model = TextoArticulado
@ -65,25 +70,27 @@ class TaForm(ModelForm):
'data',
'ementa',
'observacao',
'participacao_social',
]
def __init__(self, *args, **kwargs):
row1 = to_row([
('tipo_ta', 5),
('tipo_ta', 3),
('numero', 2),
('ano', 2),
('data', 3),
('data', 2),
('participacao_social', 3),
])
self.helper = FormHelper()
self.helper.layout = Layout(
row1,
Fieldset(_('Identificação Básica'), row1, css_class="large-12"),
Fieldset(_('Ementa'), Column('ementa'), css_class="large-12"),
Fieldset(
_('Observações'), Column('observacao'), css_class="large-12"),
ButtonHolder(
Submit('Save', 'Save',
Submit('submit', _('Salvar'),
css_class='radius')
)
)

23
compilacao/migrations/0036_auto_20151224_1341.py

@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('compilacao', '0035_auto_20151223_1709'),
]
operations = [
migrations.AlterModelOptions(
name='textoarticulado',
options={'verbose_name': 'Texto Articulado', 'verbose_name_plural': 'Textos Articulados', 'ordering': ['-data', '-numero']},
),
migrations.AddField(
model_name='textoarticulado',
name='participacao_social',
field=models.BooleanField(choices=[(True, 'Sim'), (False, 'Não')], verbose_name='Participação Social', default=False),
),
]

19
compilacao/migrations/0037_auto_20151224_1348.py

@ -0,0 +1,19 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('compilacao', '0036_auto_20151224_1341'),
]
operations = [
migrations.AlterField(
model_name='textoarticulado',
name='participacao_social',
field=models.NullBooleanField(verbose_name='Participação Social', choices=[(True, 'Sim'), (False, 'Não')], default=False),
),
]

24
compilacao/migrations/0038_auto_20151224_1429.py

@ -0,0 +1,24 @@
# -*- coding: utf-8 -*-
from __future__ import unicode_literals
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('compilacao', '0037_auto_20151224_1348'),
]
operations = [
migrations.AddField(
model_name='tipotextoarticulado',
name='participacao_social',
field=models.NullBooleanField(default=False, verbose_name='Participação Social', choices=[(True, 'Sim'), (False, 'Não')]),
),
migrations.AlterField(
model_name='textoarticulado',
name='participacao_social',
field=models.NullBooleanField(default=None, verbose_name='Participação Social', choices=[(None, 'Padrão definido no Tipo'), (True, 'Sim'), (False, 'Não')]),
),
]

16
compilacao/models.py

@ -61,6 +61,11 @@ class BaseModel(models.Model):
class TipoTextoArticulado(models.Model):
sigla = models.CharField(max_length=3, verbose_name=_('Sigla'))
descricao = models.CharField(max_length=50, verbose_name=_('Descrição'))
participacao_social = models.NullBooleanField(
default=False,
blank=True, null=True,
choices=utils.YES_NO_CHOICES,
verbose_name=_('Participação Social'))
class Meta:
verbose_name = _('Tipo de Texto Articulado')
@ -70,6 +75,12 @@ class TipoTextoArticulado(models.Model):
return self.descricao
PARTICIPACAO_SOCIAL_CHOICES = [
(None, _('Padrão definido no Tipo')),
(True, _('Sim')),
(False, _('Não'))]
class TextoArticulado(TimestampedMixin):
data = models.DateField(blank=True, null=True, verbose_name=_('Data'))
ementa = models.TextField(verbose_name=_('Ementa'))
@ -80,6 +91,11 @@ class TextoArticulado(TimestampedMixin):
tipo_ta = models.ForeignKey(
TipoTextoArticulado,
verbose_name=_('Tipo de Texto Articulado'))
participacao_social = models.NullBooleanField(
default=None,
blank=True, null=True,
choices=PARTICIPACAO_SOCIAL_CHOICES,
verbose_name=_('Participação Social'))
class Meta:
verbose_name = _('Texto Articulado')

8
compilacao/urls.py

@ -3,19 +3,17 @@ from django.conf.urls import include, url
from compilacao import views
urlpatterns_compilacao = [
url(r'^$', views.TaListView.as_view(), name='ta_list'),
url(r'^create$', views.TaCreateView.as_view(), name='ta_create'),
url(r'^(?P<pk>[0-9]+)$', views.TaDetailView.as_view(), name='ta_detail'),
url(r'^(?P<pk>[0-9]+)/edit$',
views.TaUpdateView.as_view(), name='ta_edit'),
url(r'^(?P<pk>[0-9]+)/delete$',
views.TaDeleteView.as_view(), name='ta_delete'),
]
urlpatterns = [
url(r'^ta/', include(urlpatterns_compilacao)),
]

34
compilacao/views.py

@ -2,6 +2,7 @@ from collections import OrderedDict
from datetime import datetime, timedelta
from os.path import sys
from braces.views import FormMessagesMixin
from django.contrib.auth.decorators import login_required
from django.contrib.messages.api import success
from django.core.signing import Signer
@ -16,7 +17,8 @@ from django.utils.functional import cached_property
from django.utils.translation import ugettext_lazy as _
from django.views.generic.base import TemplateView
from django.views.generic.detail import DetailView
from django.views.generic.edit import FormMixin, UpdateView, CreateView
from django.views.generic.edit import FormMixin, UpdateView, CreateView,\
DeleteView
from django.views.generic.list import ListView
from compilacao import forms, utils
@ -42,7 +44,9 @@ DISPOSITIVO_SELECT_RELATED = (
class TaListView(ListView):
model = TextoArticulado
paginate_by = 10
title = TextoArticulado._meta.verbose_name_plural
verbose_name = model._meta.verbose_name
title = model._meta.verbose_name_plural
create_url = reverse_lazy('ta_create')
def get_context_data(self, **kwargs):
context = super(TaListView, self).get_context_data(**kwargs)
@ -61,6 +65,17 @@ class TaDetailView(DetailView):
return self.get_object()
class TaCreateView(FormMessagesMixin, CreateView):
model = TextoArticulado
form_class = forms.TaForm
template_name = "compilacao/form.html"
form_valid_message = _('Registro criado com sucesso!')
form_invalid_message = _('O registro não foi criado.')
def get_success_url(self):
return reverse_lazy('ta_detail', kwargs={'pk': self.object.id})
class TaUpdateView(UpdateView):
model = TextoArticulado
form_class = forms.TaForm
@ -72,3 +87,18 @@ class TaUpdateView(UpdateView):
def get_success_url(self):
return reverse_lazy('ta_detail', kwargs={'pk': self.kwargs['pk']})
class TaDeleteView(DeleteView):
model = TextoArticulado
@property
def title(self):
return self.get_object()
@property
def detail_url(self):
return reverse_lazy('ta_detail', kwargs={'pk': self.kwargs['pk']})
def get_success_url(self):
return reverse_lazy('ta_list')

2
norma/urls.py

@ -5,7 +5,7 @@ from norma.views import (NormaIncluirView, assunto_norma_crud,
norma_temporario_crud, tipo_norma_crud)
norma_url_patterns = norma_temporario_crud.urlpatterns
norma_url_patterns = norma_temporario_crud.urlpatterns + __url__compilacao
# norma_url_patterns = norma_crud.urlpatterns + []
urlpatterns = [

6
sapl/settings.py

@ -59,8 +59,8 @@ INSTALLED_APPS = (
'crispy_forms_foundation',
'sass_processor',
)
if DEBUG:
INSTALLED_APPS += ('debug_toolbar',)
# if DEBUG:
# INSTALLED_APPS += ('debug_toolbar',)
MIDDLEWARE_CLASSES = (
'django.contrib.sessions.middleware.SessionMiddleware',
@ -117,7 +117,7 @@ DATABASES = {
# https://docs.djangoproject.com/en/1.8/topics/i18n/
LANGUAGE_CODE = 'pt-br'
TIME_ZONE = 'America/Sao_Paulo'
USE_I18N = False
USE_I18N = True
USE_L10N = False
USE_TZ = True
# DATE_FORMAT = 'N j, Y'

20
templates/compilacao/textoarticulado_confirm_delete.html

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% load i18n %}
{% block base_content %}
<form action="" method="post">{% csrf_token %}
<div class="callout panel text-center radius clearfix">
<p>
{% blocktrans %}
Confirma exclusão de <br/> "{{ object }}"?
{% endblocktrans %}
</p>
<div class="button-group">
<a href="{{ view.detail_url }}" class="button button radius alert">{% trans 'Cancelar' %}</a>
<input name="submit" value="{% trans 'Confirmar' %}" class="submit button button radius success" type="submit"></li>
</div>
</div>
</form>
{% endblock %}

128
templates/compilacao/textoarticulado_detail.html

@ -1,71 +1,61 @@
{% extends "base.html" %}
{% load i18n %}
{% load compilacao_filters %}
{% block base_content %}
{# FIXME is this the best markup to use? #}
<div class="clearfix">
{% extends "base.html" %} {% load i18n %} {% load compilacao_filters %} {% block base_content %} {# FIXME is this the best markup to use? #}
<div class="clearfix">
{% block actions %}
<dl class="sub-nav right">
<dl class="sub-nav right">
<dd><a href="{% url 'ta_edit' object.pk %}" class="button">{% trans 'Editar' %}</a></dd>
<dd><a href="" class="button alert">{% trans 'Excluir' %}</a></dd>
</dl>
{% endblock actions %}
{% block sections_nav %}{% endblock %}
</div>
{% block detail_content %}
{# TODO replace fieldset for something semantically correct, but with similar visual grouping style #}
<fieldset>
<legend>{%trans 'Identificação Básica'%}</legend>
<div class="row">
<div class="columns large-5">
<div id="div_id_tipo" class="holder">
<label>{% verbose_name object 'tipo_ta' %}</label>
<p>{{ object.tipo_ta}}</p>
</div>
</div>
<div class="columns large-2">
<div id="div_id_numero" class="holder">
<label>{% verbose_name object 'numero' %}</label>
<p>{{ object.numero}}</p>
</div>
</div>
<div class="columns large-2">
<div id="div_id_ano" class="holder">
<label>{% verbose_name object 'ano' %}</label>
<p>{{ object.ano}}</p>
</div>
</div>
<div class="columns large-3">
<div id="div_id_data" class="holder">
<label>{% verbose_name object 'data' %}</label>
<p>{{ object.data}}</p>
</div>
</div>
</div>
<div class="row">
<div class="columns large-12">
<div id="div_id_ementa" class="holder">
<label>{% verbose_name object 'ementa' %}</label>
<p>{{ object.ementa|safe}}</p>
</div>
</div>
</div>
</fieldset>
{% endblock detail_content %}
{% endblock base_content %}
<dd><a href="{% url 'ta_delete' object.pk %}" class="button alert">{% trans 'Excluir' %}</a></dd>
</dl>
{% endblock actions %} {% block sections_nav %}{% endblock %}
</div>
{% block detail_content %} {# TODO replace fieldset for something semantically correct, but with similar visual grouping style #}
<fieldset>
<legend>{%trans 'Identificação Básica'%}</legend>
<div class="row">
<div class="columns large-4">
<div id="div_id_tipo" class="holder">
<label>{% verbose_name object 'tipo_ta' %}</label>
<p>{{ object.tipo_ta}}</p>
</div>
</div>
<div class="columns large-3">
<div id="div_id_numero" class="holder">
<label>{% verbose_name object 'numero' %}</label>
<p>{{ object.numero}}</p>
</div>
</div>
<div class="columns large-2">
<div id="div_id_ano" class="holder">
<label>{% verbose_name object 'ano' %}</label>
<p>{{ object.ano}}</p>
</div>
</div>
<div class="columns large-3">
<div id="div_id_data" class="holder">
<label>{% verbose_name object 'data' %}</label>
<p>{{ object.data}}</p>
</div>
</div>
</div>
<br>
<div class="row">
<div class="columns large-12">
<div id="div_id_ementa" class="holder">
<label>{% verbose_name object 'ementa' %}</label>
<p>{{ object.ementa|safe}}</p>
</div>
</div>
</div>
</fieldset>
{% endblock detail_content %} {% endblock base_content %}

14
templates/compilacao/textoarticulado_list.html

@ -1,5 +1,17 @@
{% extends "base.html" %} {% load i18n %} {% block base_content %}
{# FIXME is this the best markup to use? #}
<dl class="sub-nav">
<dd><a href="{{ view.create_url }}">
{% blocktrans with verbose_name=view.verbose_name %} Adicionar {{ verbose_name }} {% endblocktrans %}
</a></dd>
{% block more_buttons %}
{% endblock more_buttons %}
</dl>
<table class="table table-hover">
<thead>
<tr>
@ -17,7 +29,7 @@
<td>{{ ta.numero }}</td>
<td>{{ ta.ano }}</td>
<td>{{ ta.data }}</td>
<td>{{ ta.ementa }}</td>
<td>{{ ta.ementa|safe }}</td>
</tr>
{% endfor %}
</tbody>

Loading…
Cancel
Save