From 43f69f1a12a064165c517229332fb48a73206740 Mon Sep 17 00:00:00 2001 From: LeandroRoberto Date: Fri, 4 Dec 2015 09:37:54 -0200 Subject: [PATCH] customize unique message for Vide add --- compilacao/forms.py | 21 ++++++++++++++------- compilacao/models.py | 3 ++- static/styles/compilacao.scss | 6 +++++- 3 files changed, 21 insertions(+), 9 deletions(-) diff --git a/compilacao/forms.py b/compilacao/forms.py index ff5d31c9f..9cb8617bc 100644 --- a/compilacao/forms.py +++ b/compilacao/forms.py @@ -1,6 +1,7 @@ from crispy_forms.helper import FormHelper from crispy_forms.layout import HTML, Button, Column, Div, Field, Layout, Row from django import forms +from django.core.exceptions import NON_FIELD_ERRORS from django.forms.models import ModelForm from django.utils.translation import ugettext_lazy as _ @@ -14,7 +15,7 @@ class UpLoadImportFileForm(forms.Form): required=True, label=_('Arquivo formato ODF para Importanção')) -error_messages = { +nota_error_messages = { 'required': _('Este campo é obrigatório'), 'invalid': _('URL inválida.') } @@ -37,11 +38,11 @@ class NotaForm(ModelForm): texto = forms.CharField( label='', widget=forms.Textarea, - error_messages=error_messages) + error_messages=nota_error_messages) url_externa = forms.URLField( label='', required=False, - error_messages=error_messages) + error_messages=nota_error_messages) publicidade = forms.ChoiceField( required=True, label=_('Publicidade'), @@ -60,7 +61,7 @@ class NotaForm(ModelForm): required=True, widget=forms.DateInput( format='%d/%m/%Y'), - error_messages=error_messages + error_messages=nota_error_messages ) efetividade = forms.DateField( label=_('Efetividade'), @@ -68,7 +69,7 @@ class NotaForm(ModelForm): required=True, widget=forms.DateInput( format='%d/%m/%Y'), - error_messages=error_messages) + error_messages=nota_error_messages) dispositivo = forms.ModelChoiceField(queryset=Dispositivo.objects.all(), widget=forms.HiddenInput()) pk = forms.IntegerField(widget=forms.HiddenInput(), @@ -137,12 +138,12 @@ class VideForm(ModelForm): texto = forms.CharField( label='', widget=forms.Textarea, - error_messages=error_messages, required=False) tipo = forms.ModelChoiceField( label=_('Tipo do Vide'), queryset=TipoVide.objects.all(), - required=True) + required=True, + error_messages=nota_error_messages) busca_dispositivo = forms.CharField( label=_('Buscar Dispositivo a Referenciar'), @@ -157,6 +158,12 @@ class VideForm(ModelForm): 'texto', 'tipo', 'pk'] + error_messages = { + NON_FIELD_ERRORS: { + 'unique_together': + "Ja existe um Vide deste tipo para o Dispositivo Referido ", + } + } def __init__(self, *args, **kwargs): diff --git a/compilacao/models.py b/compilacao/models.py index e6df58898..124d9af90 100644 --- a/compilacao/models.py +++ b/compilacao/models.py @@ -1,6 +1,7 @@ from datetime import datetime from django.contrib.auth.models import User +from django.core.exceptions import ValidationError from django.db import models from django.db.models import F, Q from django.db.models.aggregates import Max @@ -1048,7 +1049,7 @@ class Vide(TimestampedMixin): class Meta: verbose_name = _('Vide') verbose_name_plural = _('Vides') - unique_together = ['dispositivo_base', 'dispositivo_ref'] + unique_together = ['dispositivo_base', 'dispositivo_ref', 'tipo'] def __str__(self): return _('Vide %s') % self.texto diff --git a/static/styles/compilacao.scss b/static/styles/compilacao.scss index f51ab838a..3f5364bcb 100644 --- a/static/styles/compilacao.scss +++ b/static/styles/compilacao.scss @@ -447,7 +447,7 @@ a:link:after, a:visited:after { } .title_form { font-size: 2.5em; - padding: 0.5em 0.3em 0.2em; + padding: 0.5em 0.3em 0.3em; background: #e5e5e5; color: #777; margin-bottom: 0.4em; @@ -461,6 +461,9 @@ a:link:after, a:visited:after { border: 0px; outline:0px; } + .alert-box { + margin-bottom: 0; + } .row:first-of-type { margin-top: 1em; display: inline-block; @@ -1173,6 +1176,7 @@ a:link:after, a:visited:after { cursor: pointer; opacity: 0.7; transform: rotate(45deg); + z-index: 98; .icon-close{ background: #FFF;