Browse Source

customize unique message for Vide add

pull/98/head
LeandroRoberto 9 years ago
parent
commit
43f69f1a12
  1. 21
      compilacao/forms.py
  2. 3
      compilacao/models.py
  3. 6
      static/styles/compilacao.scss

21
compilacao/forms.py

@ -1,6 +1,7 @@
from crispy_forms.helper import FormHelper from crispy_forms.helper import FormHelper
from crispy_forms.layout import HTML, Button, Column, Div, Field, Layout, Row from crispy_forms.layout import HTML, Button, Column, Div, Field, Layout, Row
from django import forms from django import forms
from django.core.exceptions import NON_FIELD_ERRORS
from django.forms.models import ModelForm from django.forms.models import ModelForm
from django.utils.translation import ugettext_lazy as _ from django.utils.translation import ugettext_lazy as _
@ -14,7 +15,7 @@ class UpLoadImportFileForm(forms.Form):
required=True, required=True,
label=_('Arquivo formato ODF para Importanção')) label=_('Arquivo formato ODF para Importanção'))
error_messages = { nota_error_messages = {
'required': _('Este campo é obrigatório'), 'required': _('Este campo é obrigatório'),
'invalid': _('URL inválida.') 'invalid': _('URL inválida.')
} }
@ -37,11 +38,11 @@ class NotaForm(ModelForm):
texto = forms.CharField( texto = forms.CharField(
label='', label='',
widget=forms.Textarea, widget=forms.Textarea,
error_messages=error_messages) error_messages=nota_error_messages)
url_externa = forms.URLField( url_externa = forms.URLField(
label='', label='',
required=False, required=False,
error_messages=error_messages) error_messages=nota_error_messages)
publicidade = forms.ChoiceField( publicidade = forms.ChoiceField(
required=True, required=True,
label=_('Publicidade'), label=_('Publicidade'),
@ -60,7 +61,7 @@ class NotaForm(ModelForm):
required=True, required=True,
widget=forms.DateInput( widget=forms.DateInput(
format='%d/%m/%Y'), format='%d/%m/%Y'),
error_messages=error_messages error_messages=nota_error_messages
) )
efetividade = forms.DateField( efetividade = forms.DateField(
label=_('Efetividade'), label=_('Efetividade'),
@ -68,7 +69,7 @@ class NotaForm(ModelForm):
required=True, required=True,
widget=forms.DateInput( widget=forms.DateInput(
format='%d/%m/%Y'), format='%d/%m/%Y'),
error_messages=error_messages) error_messages=nota_error_messages)
dispositivo = forms.ModelChoiceField(queryset=Dispositivo.objects.all(), dispositivo = forms.ModelChoiceField(queryset=Dispositivo.objects.all(),
widget=forms.HiddenInput()) widget=forms.HiddenInput())
pk = forms.IntegerField(widget=forms.HiddenInput(), pk = forms.IntegerField(widget=forms.HiddenInput(),
@ -137,12 +138,12 @@ class VideForm(ModelForm):
texto = forms.CharField( texto = forms.CharField(
label='', label='',
widget=forms.Textarea, widget=forms.Textarea,
error_messages=error_messages,
required=False) required=False)
tipo = forms.ModelChoiceField( tipo = forms.ModelChoiceField(
label=_('Tipo do Vide'), label=_('Tipo do Vide'),
queryset=TipoVide.objects.all(), queryset=TipoVide.objects.all(),
required=True) required=True,
error_messages=nota_error_messages)
busca_dispositivo = forms.CharField( busca_dispositivo = forms.CharField(
label=_('Buscar Dispositivo a Referenciar'), label=_('Buscar Dispositivo a Referenciar'),
@ -157,6 +158,12 @@ class VideForm(ModelForm):
'texto', 'texto',
'tipo', 'tipo',
'pk'] 'pk']
error_messages = {
NON_FIELD_ERRORS: {
'unique_together':
"Ja existe um Vide deste tipo para o Dispositivo Referido ",
}
}
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):

3
compilacao/models.py

@ -1,6 +1,7 @@
from datetime import datetime from datetime import datetime
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.core.exceptions import ValidationError
from django.db import models from django.db import models
from django.db.models import F, Q from django.db.models import F, Q
from django.db.models.aggregates import Max from django.db.models.aggregates import Max
@ -1048,7 +1049,7 @@ class Vide(TimestampedMixin):
class Meta: class Meta:
verbose_name = _('Vide') verbose_name = _('Vide')
verbose_name_plural = _('Vides') verbose_name_plural = _('Vides')
unique_together = ['dispositivo_base', 'dispositivo_ref'] unique_together = ['dispositivo_base', 'dispositivo_ref', 'tipo']
def __str__(self): def __str__(self):
return _('Vide %s') % self.texto return _('Vide %s') % self.texto

6
static/styles/compilacao.scss

@ -447,7 +447,7 @@ a:link:after, a:visited:after {
} }
.title_form { .title_form {
font-size: 2.5em; font-size: 2.5em;
padding: 0.5em 0.3em 0.2em; padding: 0.5em 0.3em 0.3em;
background: #e5e5e5; background: #e5e5e5;
color: #777; color: #777;
margin-bottom: 0.4em; margin-bottom: 0.4em;
@ -461,6 +461,9 @@ a:link:after, a:visited:after {
border: 0px; border: 0px;
outline:0px; outline:0px;
} }
.alert-box {
margin-bottom: 0;
}
.row:first-of-type { .row:first-of-type {
margin-top: 1em; margin-top: 1em;
display: inline-block; display: inline-block;
@ -1173,6 +1176,7 @@ a:link:after, a:visited:after {
cursor: pointer; cursor: pointer;
opacity: 0.7; opacity: 0.7;
transform: rotate(45deg); transform: rotate(45deg);
z-index: 98;
.icon-close{ .icon-close{
background: #FFF; background: #FFF;

Loading…
Cancel
Save