Fist Commit

master
Michael Vignotto 2020-05-22 14:05:33 +02:00
commit 8a7269e591
58 changed files with 498 additions and 0 deletions

0
BoxTitoli/__init__.py Executable 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.

16
BoxTitoli/asgi.py Executable file
View File

@ -0,0 +1,16 @@
"""
ASGI config for BoxTitoli project.
It exposes the ASGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/asgi/
"""
import os
from django.core.asgi import get_asgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BoxTitoli.settings')
application = get_asgi_application()

132
BoxTitoli/settings.py Executable file
View File

@ -0,0 +1,132 @@
"""
Django settings for BoxTitoli project.
Generated by 'django-admin startproject' using Django 3.0.5.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/topics/settings/
For the full list of settings and their values, see
https://docs.djangoproject.com/en/3.0/ref/settings/
"""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))
# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/3.0/howto/deployment/checklist/
# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = '$t!m3p(mbj0z!orpai#id7t0q3p@9^1h5tp7a0b1x*8m^3jl)l'
# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True
ALLOWED_HOSTS = ['*']
# Application definition
INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'titoli',
'crispy_forms'
]
MIDDLEWARE = [
'django.middleware.security.SecurityMiddleware',
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.common.CommonMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
'django.contrib.messages.middleware.MessageMiddleware',
'django.middleware.clickjacking.XFrameOptionsMiddleware',
]
ROOT_URLCONF = 'BoxTitoli.urls'
TEMPLATES = [
{
'BACKEND': 'django.template.backends.django.DjangoTemplates',
'DIRS': [os.path.join(BASE_DIR, 'templates')],
'APP_DIRS': True,
'OPTIONS': {
'context_processors': [
'django.template.context_processors.debug',
'django.template.context_processors.request',
'django.contrib.auth.context_processors.auth',
'django.contrib.messages.context_processors.messages',
],
},
},
]
WSGI_APPLICATION = 'BoxTitoli.wsgi.application'
# Database
# https://docs.djangoproject.com/en/3.0/ref/settings/#databases
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'lordb',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '127.0.0.1',
'PORT': '8889',
}
}
# Password validation
# https://docs.djangoproject.com/en/3.0/ref/settings/#auth-password-validators
AUTH_PASSWORD_VALIDATORS = [
{
'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
},
{
'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
},
]
# Internationalization
# https://docs.djangoproject.com/en/3.0/topics/i18n/
LANGUAGE_CODE = 'it'
TIME_ZONE = 'UTC'
USE_I18N = True
USE_L10N = True
USE_TZ = True
# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/3.0/howto/static-files/
STATIC_URL = '/static/'
MEDIA_ROOT = (os.path.join(BASE_DIR, 'file'))
MEDIA_URL = '/media/'
CRISPY_TEMPLATE_PACK = 'bootstrap4'

23
BoxTitoli/urls.py Executable file
View File

@ -0,0 +1,23 @@
"""BoxTitoli URL Configuration
The `urlpatterns` list routes URLs to views. For more information please see:
https://docs.djangoproject.com/en/3.0/topics/http/urls/
Examples:
Function views
1. Add an import: from my_app import views
2. Add a URL to urlpatterns: path('', views.home, name='home')
Class-based views
1. Add an import: from other_app.views import Home
2. Add a URL to urlpatterns: path('', Home.as_view(), name='home')
Including another URLconf
1. Import the include() function: from django.urls import include, path
2. Add a URL to urlpatterns: path('blog/', include('blog.urls'))
"""
from django.contrib import admin
from django.urls import include,path
from django.conf.urls.static import settings,static
urlpatterns = [
path('admin/', admin.site.urls),
path("",include('titoli.urls'))
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)

16
BoxTitoli/wsgi.py Executable file
View File

@ -0,0 +1,16 @@
"""
WSGI config for BoxTitoli project.
It exposes the WSGI callable as a module-level variable named ``application``.
For more information on this file, see
https://docs.djangoproject.com/en/3.0/howto/deployment/wsgi/
"""
import os
from django.core.wsgi import get_wsgi_application
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BoxTitoli.settings')
application = get_wsgi_application()

21
manage.py Executable file
View File

@ -0,0 +1,21 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'BoxTitoli.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

0
random_id/__init__.py Executable file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

8
random_id/utils.py Executable file
View File

@ -0,0 +1,8 @@
import random
import string
ALPHANUMERIC_CHARS = string.ascii_lowercase + string.ascii_uppercase + string.digits
MAX_STRING_LENGTH = 11
def generate_random_string(chars=ALPHANUMERIC_CHARS,length=MAX_STRING_LENGTH):
return "".join(random.choice(chars) for _ in range(length))

45
templates/Homepage.html Executable file
View File

@ -0,0 +1,45 @@
{% extends "base.html" %}
{% block title %} LORDCHANNEL - LISTA TITOLI {% endblock title %}
{% block css %}
<style>
div.lcimg {
margin: 5px;
border: 1px solid #ccc;
float: left;
width: 200px;
height:300px;
}
div.lcimg:hover {
border: 1px solid #777;
}
div.lcimg img {
width: 100%;
height: 282px;
}
div.desc {
text-align: center;
overflow:hidden;
word-wrap: break-word;
}
</style>
{% endblock css %}
{% block content %}
<h1 class="text-center">Boxtitoli : </h1>
<div class="container">
<div class="text-center"><a href="{% url 'crea_titolo' %}">CREA UN NUOVO TITOLO</a></div>
{% for lista_titoli in titoli %}
<div class="lcimg desc">
<a href="{{ lista_titoli.get_absolute_url }}">{{ lista_titoli.titolo }}
<!-- {{ lista_titoli.slug_id }} -->
<img src="{{ lista_titoli.foto }}" alt="{{ lista_titoli.titolo }}">
</a>
</div>
{% endfor %}
</div>
{% endblock content %}

25
templates/base.html Executable file
View File

@ -0,0 +1,25 @@
<!doctype html>
<html lang="it">
<head>
<!-- Required meta tags -->
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1, shrink-to-fit=no">
<!-- Bootstrap CSS -->
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/css/bootstrap.min.css" integrity="sha384-Gn5384xqQ1aoWXA+058RXPxPg6fy4IWvTNh0E263XmFcJlSAwiGgFAW/dAiS6JXm" crossorigin="anonymous">
{% block css %} {% endblock css %}
<title> {% block title %} {% endblock title %}</title>
</head>
<body>
<div class="container">
{% block content %}
{% endblock content %}
</div>
<!-- Optional JavaScript -->
<!-- jQuery first, then Popper.js, then Bootstrap JS -->
<script src="https://code.jquery.com/jquery-3.2.1.slim.min.js" integrity="sha384-KJ3o2DKtIkvYIK3UENzmM7KCkRr/rE9/Qpg6aAZGJwFDMVNA/GpGFF93hXpG5KkN" crossorigin="anonymous"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/popper.js/1.12.9/umd/popper.min.js" integrity="sha384-ApNbgh9B+Y1QKtv3Rn7W3mgPxhU9K/ScQsAP7hUibX39j7fakFPskvXusvfa0b4Q" crossorigin="anonymous"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/4.0.0/js/bootstrap.min.js" integrity="sha384-JZR6Spejh4U02d8jOt6vLEHfe/JQGiRRSQQxSfFWpi1MquVdAyjUar5+76PVCmYl" crossorigin="anonymous"></script>
</body>
</html>

16
templates/crea_titolo.html Executable file
View File

@ -0,0 +1,16 @@
{% extends "base.html" %}
{% load crispy_forms_tags %}
{% block title %} LORDCHANNEL - CREA TITOLO {% endblock title %}
{% block content %}
<h1 class="text-center">Crea Titolo : </h1>
<div class="container">
<form method="post">
{% csrf_token %}
{{ form|crispy }}
<input type="submit" class="btn btn-danger" value="CREA">
</form>
</div>
{% endblock content %}

29
templates/streaming.html Executable file
View File

@ -0,0 +1,29 @@
{% extends "base.html" %}
{% block title %} GUARDA IN STREAMING {{ streaming.titolo }} {% endblock title %}
{% block css %}
<style>
.rectangle {
width:70%;
height:70%;
background-color: black;
border: 3px solid red;
position: absolute;
top: 15%;
left: 15%;
}
.rectangle>iframe {
display:block;
width:100%;
height:100%;
}
</style>
{% endblock css %}
{% block content %}
<body background="https://i.ibb.co/vzXbD3H/lrFfdA1.jpg">
<div class="rectangle">
<iframe src='{{ streaming.link_embedded }}' scrolling="no" frameborder="0" allowfullscreen="true" webkitallowfullscreen="true" mozallowfullscreen="true"></iframe>
</div>
</body>
{% endblock content %}

1
titoli/__init__.py Executable file
View File

@ -0,0 +1 @@
default_app_config = "titoli.apps.TitoliConfig"

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.

Binary file not shown.

Binary file not shown.

Binary file not shown.

6
titoli/admin.py Executable file
View File

@ -0,0 +1,6 @@
from django.contrib import admin
from .models import Titolo
# Register your models here.
admin.site.register(Titolo)

8
titoli/apps.py Executable file
View File

@ -0,0 +1,8 @@
from django.apps import AppConfig
class TitoliConfig(AppConfig):
name = 'titoli'
def ready(self):
import titoli.signals

9
titoli/forms.py Executable file
View File

@ -0,0 +1,9 @@
from django.forms import ModelForm
from .models import Titolo
class FormTitolo(ModelForm):
class Meta:
model = Titolo
exclude = ["id"]

View File

@ -0,0 +1,28 @@
# Generated by Django 3.0.5 on 2020-05-05 13:37
from django.db import migrations, models
class Migration(migrations.Migration):
initial = True
dependencies = [
]
operations = [
migrations.CreateModel(
name='Titolo',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('titolo', models.CharField(max_length=300)),
('slug_id', models.CharField(max_length=11)),
('link_embedded', models.URLField()),
('foto', models.URLField()),
],
options={
'verbose_name': 'Titolo',
'verbose_name_plural': 'Titoli',
},
),
]

View File

@ -0,0 +1,17 @@
# Generated by Django 3.0.5 on 2020-05-16 17:42
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('titoli', '0001_initial'),
]
operations = [
migrations.AlterModelOptions(
name='titolo',
options={'managed': False, 'verbose_name': 'Boxtitolo', 'verbose_name_plural': 'Boxtitoli'},
),
]

0
titoli/migrations/__init__.py Executable file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

28
titoli/models.py Normal file
View File

@ -0,0 +1,28 @@
# This is an auto-generated Django model module.
# You'll have to do the following manually to clean this up:
# * Rearrange models' order
# * Make sure each model has one field with primary_key=True
# * Make sure each ForeignKey and OneToOneField has `on_delete` set to the desired behavior
# * Remove `managed = False` lines if you wish to allow Django to create, modify, and delete the table
# Feel free to rename the models, but don't rename db_table values or field names.
from django.db import models
from django.urls import reverse
class Titolo(models.Model):
titolo = models.TextField()
id = models.TextField()
unico = models.AutoField(primary_key=True)
link_embedded = models.TextField(db_column='link embedded') # Field renamed to remove unsuitable characters.
foto = models.TextField()
def get_absolute_url(self):
return reverse('guarda_streaming',kwargs={"id":self.id})
def __str__(self):
return self.titolo
class Meta:
managed = False
db_table = 'tbl_episode'
verbose_name = "Boxtitolo"
verbose_name_plural = "Boxtitoli"

20
titoli/models_backup.py Executable file
View File

@ -0,0 +1,20 @@
from django.db import models
from django.urls import reverse
# Create your models here.
class Titolo(models.Model):
titolo = models.CharField(max_length=300)
slug_id = models.CharField(max_length=11,null=True,blank=True)
link_embedded = models.URLField()
foto = models.URLField()
def __str__(self):
return self.titolo
def get_absolute_url(self):
return reverse('guarda_streaming',kwargs={"slug_id":self.slug_id})
class Meta:
verbose_name = "Titolo"
verbose_name_plural = "Titoli"

11
titoli/signals.py Executable file
View File

@ -0,0 +1,11 @@
from django.db.models.signals import pre_save
from django.dispatch import receiver
from random_id.utils import generate_random_string
from .models import Titolo
@receiver(pre_save, sender=Titolo)
def add_slug_to_id(sender, instance, *args, **kwargs):
if instance and not instance.id:
random_string = generate_random_string()
instance.id = random_string

3
titoli/tests.py Executable file
View File

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

8
titoli/urls.py Executable file
View File

@ -0,0 +1,8 @@
from django.urls import path
from .views import homepage,guarda_streaming,CreateTitolo
urlpatterns = [
path("",homepage,name="Homepage"),
path("guarda_streaming/<id>",guarda_streaming,name="guarda_streaming"),
path("crea_titolo/",CreateTitolo,name="crea_titolo")
]

28
titoli/views.py Executable file
View File

@ -0,0 +1,28 @@
from django.shortcuts import render,get_object_or_404,redirect
from .models import Titolo
from .forms import FormTitolo
from django.http import HttpResponse
# Create your views here.
def homepage(request):
titoli = Titolo.objects.all().order_by("-unico")
context = {"titoli":titoli}
return render(request,"Homepage.html",context)
def guarda_streaming(request,id):
streaming = get_object_or_404(Titolo,id=id)
context = {"streaming":streaming}
return render(request,"streaming.html",context)
def CreateTitolo(request):
if request.method == "POST":
form = FormTitolo(request.POST)
if form.is_valid():
new_title = form.save()
return redirect("Homepage")
else:
form = FormTitolo()
context = {"form":form}
return render(request,"crea_titolo.html",context)