66 lines
2.9 KiB
Python
66 lines
2.9 KiB
Python
from django import forms
|
|
from .models import CommentoAnime,SegnalazioneAnime,Anime
|
|
from utils.profanity_filter import profanity_words
|
|
from django.core.validators import ValidationError
|
|
|
|
|
|
class CreaAnime(forms.ModelForm):
|
|
class Meta:
|
|
model = Anime
|
|
exclude = ['creato_in_data','aggiornato_in_data','slug','visualizzazioni','preferito','guarda_dopo']
|
|
widgets = {
|
|
'titolo' : forms.TextInput(attrs={'class' : 'form__input','placeholder': 'Titolo'}),
|
|
'immagine_poster' : forms.FileInput(attrs={'id':'form__img-upload','name':'form__img-upload'}),
|
|
'immagine_background' : forms.FileInput(attrs={'id':'form__imgbackground-upload','name':'form__imgbackground-upload'}),
|
|
'descrizione' : forms.Textarea(attrs={'class' : 'form__textarea', 'placeholder': 'Descrizione','id': 'text'}),
|
|
'genere' : forms.SelectMultiple(attrs={'class':'js-example-basic-multiple','id':'genere'}),
|
|
'qualità_video' : forms.TextInput(attrs={'class' : 'form__input','placeholder': 'Qualitá Video'}),
|
|
'età_consigliata' : forms.TextInput(attrs={'class' : 'form__input','placeholder': 'Etá Consigliata'}),
|
|
'lingua' : forms.Select(attrs={'class':' js-example-basic-single select2-hidden-accessible','id':'lingua'}),
|
|
'data_uscita' : forms.TextInput(attrs={'class' : 'form__input','placeholder': 'Data Uscita'}),
|
|
'durata' : forms.TextInput(attrs={'class' : 'form__input','placeholder': 'Durata In min'}),
|
|
'voto' : forms.NumberInput(attrs={'class' : 'form__input','placeholder': 'Voto'})
|
|
|
|
|
|
}
|
|
labels = {
|
|
'immagine_poster' : "Carica Immagine Copertina (270x400)"
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
class SearchAnimeAPI(forms.Form):
|
|
anime = forms.CharField(label="",widget=forms.TextInput(attrs={'class': 'form__input','placeholder':'Titolo Anime...'}))
|
|
|
|
class CommentiForms(forms.ModelForm):
|
|
class Meta:
|
|
model = CommentoAnime
|
|
fields = ['commento']
|
|
widgets = {
|
|
'commento' : forms.Textarea(attrs={'class': 'form__textarea','id':'text'})
|
|
}
|
|
|
|
def clean_commento(self):
|
|
super().clean()
|
|
dati = self.cleaned_data["commento"]
|
|
lista_parole_offensive = profanity_words()
|
|
for s in lista_parole_offensive:
|
|
if s in dati:
|
|
raise ValidationError("Il Contenuto Inserito viola le norme del sito! ")
|
|
return dati
|
|
|
|
class SegnalazioneAnimeForm(forms.ModelForm):
|
|
class Meta:
|
|
model = SegnalazioneAnime
|
|
exclude = ['anime']
|
|
widgets = {
|
|
'descrizione_problema' : forms.Textarea(attrs={'class': 'form__textarea','id':'text'}),
|
|
'problema_video' : forms.Select(attrs={'class':' js-example-basic-single select2-hidden-accessible','id':'segnalaproblema'})
|
|
}
|
|
labels = {
|
|
'descrizione_problema': '',
|
|
'problema_video' : ''
|
|
} |