Fist Commit

master
MickSlash 2020-05-07 15:12:49 +02:00
commit dc1ea062d0
40 changed files with 424 additions and 0 deletions

0
BoxTitoli/__init__.py Normal file
View File

Binary file not shown.

Binary file not shown.

Binary file not shown.

Binary file not shown.

16
BoxTitoli/asgi.py Normal 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()

128
BoxTitoli/settings.py Normal file
View File

@ -0,0 +1,128 @@
"""
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.sqlite3',
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'),
}
}
# 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 Normal 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 Normal 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()

BIN
db.sqlite3 Normal file

Binary file not shown.

21
manage.py Normal 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 Normal file
View File

Binary file not shown.

Binary file not shown.

8
random_id/utils.py Normal file
View File

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

20
templates/Homepage.html Normal file
View File

@ -0,0 +1,20 @@
{% extends "base.html" %}
{% block title %} LORDCHANNEL - LISTA TITOLI {% endblock title %}
{% 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="text-center">
<a href="{{ lista_titoli.get_absolute_url }}"><h1>{{ lista_titoli.titolo }}</h1></a>
<!-- {{ lista_titoli.slug_id }} -->
<img src="{{ lista_titoli.foto }}" class="img-fluid" alt="{{ lista_titoli.titolo }}">
</div>
<hr>
</div>
{% endfor %}
{% endblock content %}

25
templates/base.html Normal 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>

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 Normal 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 Normal 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.

6
titoli/admin.py Normal 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 Normal 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 Normal file
View File

@ -0,0 +1,9 @@
from django.forms import ModelForm
from .models import Titolo
class FormTitolo(ModelForm):
class Meta:
model = Titolo
exclude = ["slug_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

Binary file not shown.

20
titoli/models.py Normal 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 Normal 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.slug_id:
random_string = generate_random_string()
instance.slug_id = random_string

3
titoli/tests.py Normal file
View File

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

8
titoli/urls.py Normal 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/<slug_id>",guarda_streaming,name="guarda_streaming"),
path("crea_titolo/",CreateTitolo,name="crea_titolo")
]

28
titoli/views.py Normal file
View File

@ -0,0 +1,28 @@
from django.shortcuts import render,get_object_or_404
from .models import Titolo
from .forms import FormTitolo
from django.http import HttpResponse
# Create your views here.
def homepage(request):
titoli = Titolo.objects.all()
context = {"titoli":titoli}
return render(request,"Homepage.html",context)
def guarda_streaming(request,slug_id):
streaming = get_object_or_404(Titolo,slug_id=slug_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 HttpResponse("<h1>Post Creato con Successo!</h1>")
else:
form = FormTitolo()
context = {"form":form}
return render(request,"crea_titolo.html",context)