Upload LordChannel File

master
MickSlash 2021-03-13 19:36:50 +01:00
commit 4660ed7c25
2509 changed files with 17074 additions and 0 deletions

3
.gitignore vendored Normal file
View File

@ -0,0 +1,3 @@
.vscode
.DS_Store
.idea

0
Anime/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

23
Anime/admin.py Normal file
View File

@ -0,0 +1,23 @@
from django.contrib import admin
from .models import Anime,GenereAnime,Stagioni,Episodi,CommentoAnime,SegnalazioneAnime,SpecialiVideo,Immagini
class AnimeImmagini(admin.StackedInline):
model=Immagini
class AnimeAdmin(admin.ModelAdmin):
inlines = [AnimeImmagini]
readonly_fields = ("creato_in_data", "aggiornato_in_data")
class Meta:
model=Anime
admin.site.register(GenereAnime)
admin.site.register(Stagioni)
admin.site.register(Episodi)
admin.site.register(Anime,AnimeAdmin)
admin.site.register(CommentoAnime)
admin.site.register(SegnalazioneAnime)
admin.site.register(SpecialiVideo)

5
Anime/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class AnimeConfig(AppConfig):
name = 'Anime'

66
Anime/forms.py Normal file
View File

@ -0,0 +1,66 @@
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' : ''
}

View File

@ -0,0 +1,68 @@
# Generated by Django 3.0.5 on 2020-04-24 16:01
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Anime',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('titolo', models.CharField(max_length=120)),
('descrizione', models.CharField(max_length=120)),
],
options={
'verbose_name': 'Anime',
'verbose_name_plural': 'Anime',
},
),
migrations.CreateModel(
name='GenereAnime',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('genere', models.CharField(max_length=120)),
],
options={
'verbose_name': 'Genere',
'verbose_name_plural': 'Generi',
},
),
migrations.CreateModel(
name='Stagioni',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('numero_stagione', models.IntegerField()),
('anime', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='animestagioni', to='Anime.Anime')),
],
options={
'verbose_name': 'Stagione',
'verbose_name_plural': 'Stagioni',
},
),
migrations.CreateModel(
name='Episodi',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('numero_episodio', models.IntegerField()),
('streaming_link', models.URLField()),
('stagione', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stagione', to='Anime.Stagioni')),
],
options={
'verbose_name': 'Episodio',
'verbose_name_plural': 'Episodi',
},
),
migrations.AddField(
model_name='anime',
name='genere',
field=models.ManyToManyField(to='Anime.GenereAnime'),
),
]

View File

@ -0,0 +1,75 @@
# Generated by Django 3.1 on 2020-08-06 15:12
import django.core.validators
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0004_profilo_colore_tema'),
('Anime', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='anime',
name='aggiornato_in_data',
field=models.DateField(auto_now=True, null=True),
),
migrations.AddField(
model_name='anime',
name='creato_in_data',
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name='anime',
name='età_consigliata',
field=models.CharField(blank=True, max_length=20, null=True),
),
migrations.AddField(
model_name='anime',
name='immagine_background',
field=models.ImageField(default='default.png', upload_to=''),
),
migrations.AddField(
model_name='anime',
name='immagine_poster',
field=models.ImageField(blank=True, null=True, upload_to=''),
),
migrations.AddField(
model_name='anime',
name='lingua',
field=models.CharField(choices=[('ITA', 'Italiano'), ('SUB-ITA', 'SUB-ITA')], default='ITA', max_length=12),
),
migrations.AddField(
model_name='anime',
name='qualità_video',
field=models.CharField(blank=True, max_length=20, null=True),
),
migrations.AddField(
model_name='anime',
name='slug',
field=models.SlugField(blank=True, null=True),
),
migrations.AddField(
model_name='anime',
name='voto',
field=models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1.0), django.core.validators.MaxValueValidator(10.0)]),
),
migrations.CreateModel(
name='CommentoAnime',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('commento', models.TextField()),
('data_commento', models.DateTimeField(auto_now_add=True)),
('anime', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commenti_anime', to='Anime.anime')),
('utente', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commenti_utente_anime', to='core.profilo')),
],
options={
'verbose_name': 'Commento',
'verbose_name_plural': 'Commenti',
},
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-08-06 15:38
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Anime', '0002_auto_20200806_1712'),
]
operations = [
migrations.AddField(
model_name='episodi',
name='nome_episodio',
field=models.CharField(default='', max_length=200),
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 3.0.7 on 2020-08-07 12:14
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Anime', '0003_episodi_nome_episodio'),
]
operations = [
migrations.RemoveField(
model_name='commentoanime',
name='anime',
),
migrations.AddField(
model_name='commentoanime',
name='media',
field=models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='commenti_anime', to='Anime.Anime'),
),
]

View File

@ -0,0 +1,29 @@
# Generated by Django 3.1 on 2020-08-17 16:07
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_profilo_colore_tema'),
('Anime', '0004_auto_20200807_1214'),
]
operations = [
migrations.AddField(
model_name='anime',
name='data_uscita',
field=models.CharField(blank=True, max_length=20, null=True),
),
migrations.AddField(
model_name='anime',
name='guarda_dopo',
field=models.ManyToManyField(blank=True, related_name='anime_watch_later', to='core.Profilo'),
),
migrations.AddField(
model_name='anime',
name='preferito',
field=models.ManyToManyField(blank=True, related_name='anime_preferiti', to='core.Profilo'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1 on 2020-08-19 09:47
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Anime', '0005_auto_20200817_1807'),
]
operations = [
migrations.AlterField(
model_name='anime',
name='descrizione',
field=models.TextField(),
),
]

View File

@ -0,0 +1,27 @@
# Generated by Django 3.0.7 on 2020-08-21 16:30
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Anime', '0006_auto_20200819_1147'),
]
operations = [
migrations.CreateModel(
name='SegnalazioneAnime',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('problema_video', models.CharField(choices=[('Link Non Funzionante', 'Link Non Funzionante'), ('Video Pessima Qualitá', 'Video Pessima Qualitá'), ('Audio Mancante', 'Audio Mancante'), ('Episodio Incompleto', 'Episodio Incompleto'), ('Altro', 'Altro')], default='Link Non Funzionante', max_length=50)),
('descrizione_problema', models.TextField()),
('anime', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='anime_segnalato', to='Anime.Anime')),
],
options={
'verbose_name': 'Segnalazione',
'verbose_name_plural': 'Segnalazioni',
},
),
]

View File

@ -0,0 +1,23 @@
# Generated by Django 3.1 on 2020-08-23 14:19
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Anime', '0007_segnalazioneanime'),
]
operations = [
migrations.AddField(
model_name='anime',
name='visualizzazioni',
field=models.IntegerField(default=0),
),
migrations.AlterField(
model_name='anime',
name='lingua',
field=models.CharField(choices=[('ITA', 'Italiano'), ('SUB-ITA', 'Sottotitolato In Italiano')], default='ITA', max_length=12),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1 on 2020-09-18 18:00
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Anime', '0008_auto_20200823_1619'),
]
operations = [
migrations.AddField(
model_name='anime',
name='durata',
field=models.CharField(blank=True, max_length=20, null=True),
),
]

View File

@ -0,0 +1,35 @@
# Generated by Django 3.1.1 on 2020-10-10 12:29
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('Anime', '0009_anime_durata'),
]
operations = [
migrations.CreateModel(
name='SpecialiVideo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('titolo', models.CharField(max_length=120)),
('streaming_link', models.URLField()),
('stagione', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='stagione_speciali', to='Anime.stagioni')),
],
options={
'verbose_name': 'Speciale',
'verbose_name_plural': 'Speciali',
},
),
migrations.CreateModel(
name='Immagini',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('immagini', models.ImageField(blank=True, null=True, upload_to='')),
('anime', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='immagini_serietv', to='Anime.anime')),
],
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 3.1.1 on 2020-10-10 12:50
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Anime', '0010_immagini_specialivideo'),
]
operations = [
migrations.AlterModelOptions(
name='stagioni',
options={'ordering': ['numero_stagione'], 'verbose_name': 'Stagione', 'verbose_name_plural': 'Stagioni'},
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1.2 on 2020-11-09 16:50
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Anime', '0011_auto_20201010_1450'),
]
operations = [
migrations.AddField(
model_name='anime',
name='trailer',
field=models.URLField(blank=True, null=True),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.1.2 on 2020-11-09 19:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Anime', '0012_anime_trailer'),
]
operations = [
migrations.AlterField(
model_name='anime',
name='aggiornato_in_data',
field=models.DateTimeField(auto_now=True, null=True),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.1.2 on 2020-11-09 20:11
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Anime', '0013_auto_20201109_1943'),
]
operations = [
migrations.AlterField(
model_name='anime',
name='aggiornato_in_data',
field=models.DateTimeField(auto_now=True, default=None),
preserve_default=False,
),
]

View File

Binary file not shown.

Binary file not shown.

139
Anime/models.py Normal file
View File

@ -0,0 +1,139 @@
from django.db import models
from django.urls import reverse
from django.contrib.auth.models import User
from django.core.validators import MinValueValidator,MaxValueValidator
from django.utils.text import slugify
from core.models import Profilo
# Create your models here.
class GenereAnime(models.Model):
genere = models.CharField(max_length=120)
def __str__(self):
return self.genere
class Meta:
verbose_name = "Genere"
verbose_name_plural = "Generi"
def get_absolute_url(self):
return reverse('anime_genere', kwargs={'genere': self.genere})
class Anime(models.Model):
titolo = models.CharField(max_length=120)
descrizione = models.TextField()
immagine_poster = models.ImageField(null=True,blank=True)
qualità_video = models.CharField(max_length=20,null=True,blank=True)
età_consigliata = models.CharField(max_length=20,null=True,blank=True)
immagine_background = models.ImageField(default='default.png')
genere = models.ManyToManyField(GenereAnime)
LINGUE = [
('ITA', "Italiano"),
('SUB-ITA', "Sottotitolato In Italiano"),
]
lingua = models.CharField(max_length=12,choices=LINGUE,default="ITA")
voto = models.FloatField(validators=[MinValueValidator(1.0),MaxValueValidator(10.0)],null=True,blank=True)
creato_in_data = models.DateTimeField(auto_now_add=True,null=True,blank=True)
aggiornato_in_data = models.DateTimeField(auto_now=True)
slug = models.SlugField(null=True,blank=True)
preferito = models.ManyToManyField(Profilo,related_name="anime_preferiti",blank=True)
guarda_dopo = models.ManyToManyField(Profilo,related_name="anime_watch_later",blank=True)
data_uscita = models.CharField(max_length=20,null=True,blank=True)
visualizzazioni = models.IntegerField(default=0)
durata = models.CharField(max_length=20,null=True,blank=True)
trailer = models.URLField(null=True,blank=True)
def save(self, *args, **kwargs):
self.slug = slugify(self.titolo)
return super(Anime,self).save(*args, **kwargs)
def __str__(self):
return self.titolo
class Meta:
verbose_name = "Anime"
verbose_name_plural = "Anime"
def get_absolute_url(self):
return reverse('anime-detail', kwargs={'slug': self.slug})
class Stagioni(models.Model):
numero_stagione = models.IntegerField()
anime = models.ForeignKey(Anime,on_delete=models.CASCADE,related_name="animestagioni")
def __str__(self):
return f"{self.anime.titolo} - Stagione {self.numero_stagione}"
class Meta:
verbose_name = "Stagione"
verbose_name_plural = "Stagioni"
ordering = ['numero_stagione']
class Episodi(models.Model):
stagione = models.ForeignKey(Stagioni,on_delete=models.CASCADE,related_name="stagione")
numero_episodio = models.IntegerField()
nome_episodio = models.CharField(max_length=200,default="")
streaming_link = models.URLField()
def __str__(self):
return f"{self.stagione.anime.titolo} S{self.stagione.numero_stagione} E{self.numero_episodio}"
class Meta:
verbose_name = "Episodio"
verbose_name_plural = "Episodi"
class CommentoAnime(models.Model):
utente = models.ForeignKey(Profilo,on_delete=models.CASCADE,related_name="commenti_utente_anime")
commento = models.TextField()
data_commento = models.DateTimeField(auto_now_add=True)
media = models.ForeignKey(Anime,on_delete=models.CASCADE,related_name="commenti_anime",blank=True,null=True)
class Meta:
verbose_name = "Commento"
verbose_name_plural = "Commenti"
def __str__(self):
return f"{self.utente.user} ha scritto un commento sull'Anime {self.media.titolo}"
class SegnalazioneAnime(models.Model):
LISTA_PROBLEMI_VIDEO = [
('Link Non Funzionante', 'Link Non Funzionante'),
('Video Pessima Qualitá', 'Video Pessima Qualitá'),
('Audio Mancante', 'Audio Mancante'),
('Episodio Incompleto', 'Episodio Incompleto'),
('Altro', 'Altro'),
]
problema_video = models.CharField(
max_length=50,
choices=LISTA_PROBLEMI_VIDEO,
default='Link Non Funzionante',
)
descrizione_problema = models.TextField()
anime = models.ForeignKey(Anime,on_delete=models.CASCADE,related_name="anime_segnalato")
class Meta:
verbose_name = "Segnalazione"
verbose_name_plural = "Segnalazioni"
def __str__(self):
return f"Hanno Segnalato un Problema sull'Anime {self.anime.titolo}"
class SpecialiVideo(models.Model):
stagione = models.ForeignKey(Stagioni,on_delete=models.CASCADE,related_name="stagione_speciali")
titolo = models.CharField(max_length=120)
streaming_link = models.URLField()
def __str__(self):
return f" {self.stagione.anime.titolo} - {self.titolo}"
class Meta:
verbose_name = "Speciale"
verbose_name_plural = "Speciali"
class Immagini(models.Model):
anime = models.ForeignKey(Anime,on_delete=models.CASCADE,related_name="immagini_serietv")
immagini = models.ImageField(null=True,blank=True)
def __str__(self):
return f"Immagini dell'Anime {self.anime.titolo}"

3
Anime/tests.py Normal file
View File

@ -0,0 +1,3 @@
from django.test import TestCase
# Create your tests here.

17
Anime/urls.py Normal file
View File

@ -0,0 +1,17 @@
from django.urls import path
from .views import anime_detail,anime_ita,anime_subita,salva_anime,add_anime_api,preferiti,guarda_dopo,lista_generi,anime_genere,DeleteComment
urlpatterns = [
path("anime-ita/",anime_ita,name="lista-anime-ita"),
path("anime-sub-ita/",anime_subita,name="lista-anime-sub-ita"),
path('aggiungi_anime/',add_anime_api,name='aggiungi_anime'),
path("generi/",lista_generi,name="anime_generi"),
# path("<slug>/",serietv_detail,name="serietvdetail"),
path('anime/<titolo>/<descrizione>/<generi>/<int:stagioni>/<path:poster>/',salva_anime,name='salva_anime'),
path("<slug>/",anime_detail,name="anime-detail"),
path('<slug>/aggiungi_preferiti/',preferiti,name="anime_preferiti"),
path('<slug>/aggiungi_guarda_dopo/',guarda_dopo,name="anime_guarda_dopo"),
path('<slug>/elimina-commento/<int:pk>/',DeleteComment.as_view(),name="elimina_commento_anime"),
path('genere/<genere>',anime_genere,name="anime_genere")
]

207
Anime/views.py Normal file
View File

@ -0,0 +1,207 @@
from django.shortcuts import render,get_object_or_404,redirect,HttpResponseRedirect
from django.core.paginator import Paginator
from django.contrib import messages
from django.views.generic.edit import DeleteView
from django.urls.base import reverse, reverse_lazy
from .models import Anime,Episodi,Stagioni,GenereAnime,CommentoAnime,SegnalazioneAnime,Immagini
from .forms import SearchAnimeAPI,CommentiForms,SegnalazioneAnimeForm
from core.models import Profilo
from django.http import HttpResponse
from utils.thetvdbapi import search_tv_show,get_tvshow_info,image_Endpoint
from utils.download_image import get_image
from utils.english_genres_to_italian import englishgenres
from django.contrib.admin.views.decorators import staff_member_required
import random
import re
# Create your views here.
def lista_generi(request):
generi_anime = GenereAnime.objects.all()
context = {"generi_anime":generi_anime}
return render(request,'lista_generi_anime.html',context)
def anime_genere(request,genere):
genere_anime = get_object_or_404(GenereAnime,genere=genere)
anime = Anime.objects.filter(genere=genere_anime)
context = {"genere":genere_anime,"anime":anime}
return render(request,'anime_genere.html',context)
def anime_youmightlike(genres,anime):
random_picked_genre = random.sample(genres,1)
anime_same_genres = Anime.objects.filter(genere__in=random_picked_genre).values("titolo")
current_anime = anime.titolo
anime_with_same_genre = Anime.objects.exclude(titolo=current_anime)
number_anime_with_same_genre = Anime.objects.filter(genere__in=random_picked_genre).count()
# random_anime_list = random.randint(1,number_anime_with_same_genre)
# rand_anime = random.sample(list(anime_with_same_genre),min(random_anime_list, len(anime_with_same_genre))) # comportamento precedente
rand_anime = random.sample(list(anime_with_same_genre), number_anime_with_same_genre if number_anime_with_same_genre < 8 else 8) # seleziona casualmente degli elementi univoci nel database
return rand_anime
def anime_subita(request):
sub_ita = "SUB-ITA"
anime_sub_ita_filter = Anime.objects.filter(lingua=sub_ita).order_by('-creato_in_data')
generi = GenereAnime.objects.all()
paginator = Paginator(anime_sub_ita_filter, 100)
numero_pagina = request.GET.get('pagina')
anime_sub_ita = paginator.get_page(numero_pagina)
context = {"anime_sub_ita":anime_sub_ita,"generi":generi}
return render(request,"anime_sub_ita.html",context)
def anime_ita(request):
ita = "ITA"
anime_ita_filter = Anime.objects.filter(lingua=ita).order_by('-creato_in_data')
generi = GenereAnime.objects.all()
paginator = Paginator(anime_ita_filter, 100)
numero_pagina = request.GET.get('pagina')
anime_ita = paginator.get_page(numero_pagina)
context = {"anime_ita":anime_ita,"generi":generi}
return render(request,"anime_ita.html",context)
def anime_detail(request,slug):
anime = get_object_or_404(Anime,slug=slug)
anime.visualizzazioni += 1
anime.save()
immagini_anime = Immagini.objects.filter(anime=anime)
genres = list(anime.genere.all())
anime_chetipotrebberopiacere = anime_youmightlike(genres,anime)
commenti = CommentoAnime.objects.filter(media=anime).order_by("-data_commento")
is_favorite = False
watch_later = False
if request.user.is_authenticated:
profilo = get_object_or_404(Profilo,user=request.user)
preferito = anime.preferito.filter(user=profilo.user)
guarda = anime.guarda_dopo.filter(user=profilo.user)
if preferito.exists():
is_favorite = True
if guarda.exists():
watch_later = True
else:
is_favorite = False
watch_later = False
if request.method == "POST":
commenti_form = CommentiForms(request.POST or None)
if commenti_form.is_valid():
commenti_form.save(commit=False)
commenti_form.instance.media = anime
profilo = Profilo.objects.get(user=request.user)
commenti_form.instance.utente = profilo
commenti_form.save()
return HttpResponseRedirect(anime.get_absolute_url())
else:
commenti_form = CommentiForms()
if request.method == "POST":
segnala_anime_form = SegnalazioneAnimeForm(request.POST)
if segnala_anime_form.is_valid():
segnala_anime_form.save(commit=False)
segnala_anime_form.instance.anime = anime
segnala_anime_form.save()
return HttpResponseRedirect(anime.get_absolute_url())
else:
segnala_anime_form = SegnalazioneAnimeForm()
context = {"anime":anime,"anime_chetipotrebberopiacere":anime_chetipotrebberopiacere,"is_favorite":is_favorite,"watch_later":watch_later,"segnala_anime_form":segnala_anime_form,"commenti_form":commenti_form,"commenti":commenti,"immagini_anime":immagini_anime}
return render(request,"anime_template.html",context)
@staff_member_required
def add_anime_api(request):
if request.method == "GET":
form = SearchAnimeAPI(request.GET or None)
if form.is_valid():
serie = form.cleaned_data["anime"]
data_tv_show = search_tv_show(serie)
tv_genre,tv_show_info = get_tvshow_info(data_tv_show)
titolo = data_tv_show['data'][0]['seriesName']
descrizione = data_tv_show['data'][0]['overview']
immagini = data_tv_show['data'][0]['poster']
img_path = image_Endpoint() + immagini
generi = tv_genre['data']['genre']
lista_generi = ", ".join(generi)
stagioni = tv_genre['data']['season']
# for generi in data_tv_show['data'][0]['genre']:
# print(generi)
anime = {"titolo":titolo,"descrizione":descrizione,"poster":img_path,"lista_generi":lista_generi,"stagioni":stagioni,"generi":generi}
return render(request,'visualizza_risultatianime.html',anime)
else:
form = SearchAnimeAPI()
context = {"form":form}
return render(request,'aggiungi_anime_api.html',context)
@staff_member_required
def salva_anime(request,titolo,descrizione,generi,stagioni,poster):
if request.method == "GET":
print(titolo,descrizione,generi)
data_tv_show = search_tv_show(titolo)
tv_genre,tv_show_info = get_tvshow_info(data_tv_show)
background = tv_genre['data']['fanart']
background_path = 'https://artworks.thetvdb.com/banners/' + background
data_uscita = data_tv_show["data"][0]["firstAired"]
data_rilascio = re.search('(^.{4})',data_uscita)
year = data_rilascio.group(1)
anime = Anime()
if Anime.objects.filter(titolo=titolo).exists():
return HttpResponse('Anime giá presente nel DB!')
else:
anime.titolo = titolo
anime.descrizione = descrizione
anime.immagine_poster = get_image(poster)
anime.immagine_background = get_image(background_path)
anime.data_uscita = year
anime.save()
generi = list(generi.split(", "))
lista_generi_ita = englishgenres(generi)
for genre in lista_generi_ita:
if GenereAnime.objects.filter(genere=genre).exists():
genere = GenereAnime.objects.get(genere=genre)
anime.genere.add(genere)
else:
GenereAnime.objects.get_or_create(genere=genre)
genere = GenereAnime.objects.get(genere=genre)
anime.genere.add(genere)
if stagioni == 1:
season = Stagioni.objects.create(numero_stagione=stagioni,anime=anime)
for episodes in tv_show_info['data']:
if season.numero_stagione == episodes['airedSeason']:
numero_stagione = Stagioni.objects.get(numero_stagione=season.numero_stagione,anime=season.anime)
print(numero_stagione)
Episodi.objects.create(stagione=numero_stagione,numero_episodio=episodes['airedEpisodeNumber'],streaming_link="",nome_episodio=episodes['episodeName'])
else:
for seasons in range(1,(stagioni+1)):
season = Stagioni.objects.create(numero_stagione=seasons,anime=anime)
for episodes in tv_show_info['data']:
if season.numero_stagione == episodes['airedSeason']:
numero_stagione = Stagioni.objects.get(numero_stagione=season.numero_stagione,anime=season.anime)
Episodi.objects.create(stagione=numero_stagione,numero_episodio=episodes['airedEpisodeNumber'],streaming_link="",nome_episodio=episodes['episodeName'])
return redirect(anime.get_absolute_url())
def preferiti(request,slug):
anime = get_object_or_404(Anime,slug=slug)
user = request.user
profilo = get_object_or_404(Profilo,user=user)
preferito = anime.preferito.filter(user=profilo.user)
if preferito.exists(): # Controllo se il ManyToManyField esiste filtrandolo con l'id dell'utente che esegue la richiesta
anime.preferito.remove(profilo) # Se esiste rimuovo dai preferiti
messages.error(request, 'Film tolto dai preferiti correttamente!') # Mostro il messaggio
else:
anime.preferito.add(profilo) # Se il ManyToManyField non esiste lo creo aggiungendo ai preferiti l'id dell'utente che esegue la richiesta
messages.success(request, 'Film aggiunto ai preferiti correttamente!') # Mostro il messaggio
return HttpResponseRedirect(anime.get_absolute_url()) # Ritorno l'absolute url del film
def guarda_dopo(request,slug):
anime = get_object_or_404(Anime,slug=slug)
user = request.user
profilo = get_object_or_404(Profilo,user=user)
guarda_dopo = anime.guarda_dopo.filter(user=profilo.user)
if guarda_dopo.exists():
anime.guarda_dopo.remove(profilo)
else:
anime.guarda_dopo.add(profilo)
return HttpResponseRedirect(anime.get_absolute_url())
class DeleteComment(DeleteView):
model = CommentoAnime
def get_success_url(self):
anime = self.get_object().media
return reverse_lazy('anime-detail', kwargs={'slug': anime.slug})

0
Film/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

19
Film/admin.py Normal file
View File

@ -0,0 +1,19 @@
from django.contrib import admin
from .models import GenereFilm,Film,Commento,SegnalazioneFilm,Immagini
class FilmImmagini(admin.StackedInline):
model=Immagini
class FilmAdmin(admin.ModelAdmin):
inlines = [FilmImmagini]
readonly_fields = ("creato_in_data", "aggiornato_in_data")
class Meta:
model=Film
admin.site.register(GenereFilm)
admin.site.register(Commento)
admin.site.register(SegnalazioneFilm)
admin.site.register(Film,FilmAdmin)

5
Film/apps.py Normal file
View File

@ -0,0 +1,5 @@
from django.apps import AppConfig
class FilmConfig(AppConfig):
name = 'Film'

60
Film/forms.py Normal file
View File

@ -0,0 +1,60 @@
from django import forms
from .models import Commento,SegnalazioneFilm,Film
from utils.profanity_filter import profanity_words
from django.core.validators import ValidationError
class CreaFilm(forms.ModelForm):
class Meta:
model = Film
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'}),
'streaming_url' : forms.URLInput(attrs={'class' : 'form__input','placeholder': 'Streaming URL'}),
'voto' : forms.NumberInput(attrs={'class' : 'form__input','placeholder': 'Voto'})
}
labels = {
'immagine_poster' : "Carica Immagine Copertina (270x400)"
}
class CommentiForms(forms.ModelForm):
class Meta:
model = Commento
fields = ['commento']
widgets = {
'commento' : forms.Textarea(attrs={'class': 'form__textarea','id':'text'})
}
def clean_commento(self):
super().clean()
dati = self.cleaned_data["commento"]
print(f" Hai scritto la parola : {dati}")
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 SegnalazioneFilmForm(forms.ModelForm):
class Meta:
model = SegnalazioneFilm
exclude = ['film']
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' : ''
}

View File

@ -0,0 +1,39 @@
# Generated by Django 3.0.7 on 2020-06-17 16:34
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='GenereFilm',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('genere', models.CharField(max_length=120)),
],
options={
'verbose_name': 'Genere',
'verbose_name_plural': 'Generi',
},
),
migrations.CreateModel(
name='Film',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('titolo', models.CharField(max_length=200)),
('descrizione', models.CharField(max_length=200)),
('immagine_url', models.URLField(blank=True, null=True)),
('generi', models.ManyToManyField(blank=True, to='Film.GenereFilm')),
],
options={
'verbose_name': 'Film',
'verbose_name_plural': 'Film',
},
),
]

View File

@ -0,0 +1,34 @@
# Generated by Django 3.0.7 on 2020-07-28 10:08
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0001_initial'),
]
operations = [
migrations.AddField(
model_name='film',
name='aggiornato_in_data',
field=models.DateField(auto_now=True, null=True),
),
migrations.AddField(
model_name='film',
name='creato_in_data',
field=models.DateTimeField(auto_now_add=True, null=True),
),
migrations.AddField(
model_name='film',
name='immagine_locale',
field=models.ImageField(blank=True, null=True, upload_to=''),
),
migrations.AddField(
model_name='film',
name='voto',
field=models.PositiveSmallIntegerField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1), django.core.validators.MaxValueValidator(10)]),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-07-28 11:43
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0002_auto_20200728_1008'),
]
operations = [
migrations.AlterField(
model_name='film',
name='descrizione',
field=models.CharField(max_length=500),
),
]

View File

@ -0,0 +1,19 @@
# Generated by Django 3.0.7 on 2020-07-28 11:45
import django.core.validators
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0003_auto_20200728_1143'),
]
operations = [
migrations.AlterField(
model_name='film',
name='voto',
field=models.FloatField(blank=True, null=True, validators=[django.core.validators.MinValueValidator(1.0), django.core.validators.MaxValueValidator(10.0)]),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-07-28 11:46
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0004_auto_20200728_1145'),
]
operations = [
migrations.AlterField(
model_name='film',
name='descrizione',
field=models.TextField(),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-07-28 11:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0005_auto_20200728_1146'),
]
operations = [
migrations.AddField(
model_name='film',
name='slug',
field=models.SlugField(blank=True, null=True, verbose_name='djangodbmodelsfieldscharfield'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-07-28 12:02
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0006_film_slug'),
]
operations = [
migrations.AlterField(
model_name='film',
name='slug',
field=models.SlugField(unique=True),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-07-28 12:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0007_auto_20200728_1202'),
]
operations = [
migrations.AlterField(
model_name='film',
name='slug',
field=models.SlugField(blank=True, null=True, unique=True),
),
]

View File

@ -0,0 +1,28 @@
# Generated by Django 3.0.7 on 2020-07-28 12:20
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0008_auto_20200728_1203'),
]
operations = [
migrations.AddField(
model_name='film',
name='età_consigliata',
field=models.CharField(blank=True, max_length=20, null=True),
),
migrations.AddField(
model_name='film',
name='immagine_background',
field=models.ImageField(blank=True, null=True, upload_to=''),
),
migrations.AddField(
model_name='film',
name='qualità_video',
field=models.CharField(blank=True, max_length=20, null=True),
),
]

View File

@ -0,0 +1,30 @@
# Generated by Django 3.0.7 on 2020-07-31 13:03
from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('Film', '0009_auto_20200728_1220'),
]
operations = [
migrations.CreateModel(
name='Commento',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('commento', models.TextField()),
('data_commento', models.DateTimeField(auto_now_add=True)),
('film', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commenti_film', to='Film.Film')),
('utente', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commenti_user', to=settings.AUTH_USER_MODEL)),
],
options={
'verbose_name': 'Commento',
'verbose_name_plural': 'Commenti',
},
),
]

View File

@ -0,0 +1,20 @@
# Generated by Django 3.0.7 on 2020-08-01 14:52
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0001_initial'),
('Film', '0010_commento'),
]
operations = [
migrations.AlterField(
model_name='commento',
name='utente',
field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='commenti_user', to='core.Profilo'),
),
]

View File

@ -0,0 +1,24 @@
# Generated by Django 3.0.7 on 2020-08-04 10:57
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('core', '0004_profilo_colore_tema'),
('Film', '0011_auto_20200801_1452'),
]
operations = [
migrations.AddField(
model_name='film',
name='guarda_dopo',
field=models.ManyToManyField(blank=True, related_name='watch_later', to='core.Profilo'),
),
migrations.AddField(
model_name='film',
name='preferito',
field=models.ManyToManyField(blank=True, related_name='preferiti', to='core.Profilo'),
),
]

View File

@ -0,0 +1,18 @@
# Generated by Django 3.0.7 on 2020-08-07 12:09
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Film', '0012_auto_20200804_1057'),
]
operations = [
migrations.RenameField(
model_name='commento',
old_name='film',
new_name='media',
),
]

View File

@ -0,0 +1,22 @@
# Generated by Django 3.0.7 on 2020-08-07 12:24
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('Film', '0013_auto_20200807_1209'),
]
operations = [
migrations.RenameField(
model_name='film',
old_name='immagine_locale',
new_name='immagine_poster',
),
migrations.RemoveField(
model_name='film',
name='immagine_url',
),
]

View File

@ -0,0 +1,29 @@
# Generated by Django 3.1 on 2020-08-09 14:44
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('core', '0004_profilo_colore_tema'),
('Film', '0014_auto_20200807_1224'),
]
operations = [
migrations.CreateModel(
name='SegnalazioneFilm',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('problema_video', models.CharField(choices=[('Link Non Funzionante', 'Link non Funzionante'), ('Video Pessima Qualitá', 'Video Pessima Qualitá'), ('Audio Mancante', 'Audio Mancante'), ('Film Incompleto', 'Film Incompleto'), ('Altro', 'Altro')], default='Link Non Funzionante', max_length=50)),
('descrizione_problema', models.TextField()),
('film', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='film_segnalato', to='Film.film')),
('utente', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='segnalazione_utente', to='core.profilo')),
],
options={
'verbose_name': 'Segnalazione',
'verbose_name_plural': 'Segnalazioni',
},
),
]

View File

@ -0,0 +1,22 @@
# Generated by Django 3.0.7 on 2020-08-11 15:03
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('Film', '0015_segnalazionefilm'),
]
operations = [
migrations.RemoveField(
model_name='segnalazionefilm',
name='utente',
),
migrations.AlterField(
model_name='segnalazionefilm',
name='problema_video',
field=models.CharField(choices=[('Link Non Funzionante', 'Link Non Funzionante'), ('Video Pessima Qualitá', 'Video Pessima Qualitá'), ('Audio Mancante', 'Audio Mancante'), ('Film Incompleto', 'Film Incompleto'), ('Altro', 'Altro')], default='Link Non Funzionante', max_length=50),
),
]

Some files were not shown because too many files have changed in this diff Show More