commit 65dccb058133ccec3c00cb38b5aa9b5caa00bed4 Author: Michael Vignotto Date: Mon May 25 11:49:36 2020 +0200 first commit diff --git a/cocktail/__init__.py b/cocktail/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cocktail/__pycache__/__init__.cpython-37.pyc b/cocktail/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..84fb04e Binary files /dev/null and b/cocktail/__pycache__/__init__.cpython-37.pyc differ diff --git a/cocktail/__pycache__/settings.cpython-37.pyc b/cocktail/__pycache__/settings.cpython-37.pyc new file mode 100644 index 0000000..ccbf891 Binary files /dev/null and b/cocktail/__pycache__/settings.cpython-37.pyc differ diff --git a/cocktail/__pycache__/urls.cpython-37.pyc b/cocktail/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..3437dc7 Binary files /dev/null and b/cocktail/__pycache__/urls.cpython-37.pyc differ diff --git a/cocktail/__pycache__/wsgi.cpython-37.pyc b/cocktail/__pycache__/wsgi.cpython-37.pyc new file mode 100644 index 0000000..649be84 Binary files /dev/null and b/cocktail/__pycache__/wsgi.cpython-37.pyc differ diff --git a/cocktail/asgi.py b/cocktail/asgi.py new file mode 100644 index 0000000..5a9bf94 --- /dev/null +++ b/cocktail/asgi.py @@ -0,0 +1,16 @@ +""" +ASGI config for cocktail 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', 'cocktail.settings') + +application = get_asgi_application() diff --git a/cocktail/cocktail_img/cocktail_img/adonis_cocktail.jpg b/cocktail/cocktail_img/cocktail_img/adonis_cocktail.jpg new file mode 100644 index 0000000..204d43d Binary files /dev/null and b/cocktail/cocktail_img/cocktail_img/adonis_cocktail.jpg differ diff --git a/cocktail/cocktail_img/cocktail_img/americano_cocktail.jpg b/cocktail/cocktail_img/cocktail_img/americano_cocktail.jpg new file mode 100644 index 0000000..0830c59 Binary files /dev/null and b/cocktail/cocktail_img/cocktail_img/americano_cocktail.jpg differ diff --git a/cocktail/cocktail_img/cocktail_img/americano_cocktail_F3UPiWj.jpg b/cocktail/cocktail_img/cocktail_img/americano_cocktail_F3UPiWj.jpg new file mode 100644 index 0000000..26259ad Binary files /dev/null and b/cocktail/cocktail_img/cocktail_img/americano_cocktail_F3UPiWj.jpg differ diff --git a/cocktail/cocktail_img/cocktail_img/americano_cocktail_uZBelie.jpg b/cocktail/cocktail_img/cocktail_img/americano_cocktail_uZBelie.jpg new file mode 100644 index 0000000..1ed49b3 Binary files /dev/null and b/cocktail/cocktail_img/cocktail_img/americano_cocktail_uZBelie.jpg differ diff --git a/cocktail/cocktail_img/cocktail_img/cuba_libre_cocktail.jpg b/cocktail/cocktail_img/cocktail_img/cuba_libre_cocktail.jpg new file mode 100644 index 0000000..c30908b Binary files /dev/null and b/cocktail/cocktail_img/cocktail_img/cuba_libre_cocktail.jpg differ diff --git a/cocktail/settings.py b/cocktail/settings.py new file mode 100644 index 0000000..1b4b7bc --- /dev/null +++ b/cocktail/settings.py @@ -0,0 +1,126 @@ +""" +Django settings for cocktail 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 = 'cx%6wl9g2)m3tq-^2$7(tyc4b99bl-a*kjseiz1s+1jb!qflkp' + +# 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', + 'cocktail_list' +] + +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 = 'cocktail.urls' + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(BASE_DIR, 'cocktail/templates'), + os.path.join(BASE_DIR, 'cocktail_list/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 = 'cocktail.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, 'cocktail/cocktail_img')) + +MEDIA_URL = "/img/" \ No newline at end of file diff --git a/cocktail/templates/base.html b/cocktail/templates/base.html new file mode 100644 index 0000000..62c919f --- /dev/null +++ b/cocktail/templates/base.html @@ -0,0 +1,28 @@ + + + + + + + + + + {% block css %} + + {% endblock css %} + {% block title %} {% endblock title %} + + +
+ {% block content %} + + {% endblock content %} +
+ + + + + + + + \ No newline at end of file diff --git a/cocktail/urls.py b/cocktail/urls.py new file mode 100644 index 0000000..8e637c4 --- /dev/null +++ b/cocktail/urls.py @@ -0,0 +1,26 @@ +"""cocktail 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 static +from django.conf import settings + +urlpatterns = [ + path('admin/', admin.site.urls), + path('', include('cocktail_list.urls')) +] + +urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) \ No newline at end of file diff --git a/cocktail/wsgi.py b/cocktail/wsgi.py new file mode 100644 index 0000000..18c6418 --- /dev/null +++ b/cocktail/wsgi.py @@ -0,0 +1,16 @@ +""" +WSGI config for cocktail 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', 'cocktail.settings') + +application = get_wsgi_application() diff --git a/cocktail_list/__init__.py b/cocktail_list/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cocktail_list/__pycache__/__init__.cpython-37.pyc b/cocktail_list/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..d88be8a Binary files /dev/null and b/cocktail_list/__pycache__/__init__.cpython-37.pyc differ diff --git a/cocktail_list/__pycache__/admin.cpython-37.pyc b/cocktail_list/__pycache__/admin.cpython-37.pyc new file mode 100644 index 0000000..1dbe7dd Binary files /dev/null and b/cocktail_list/__pycache__/admin.cpython-37.pyc differ diff --git a/cocktail_list/__pycache__/models.cpython-37.pyc b/cocktail_list/__pycache__/models.cpython-37.pyc new file mode 100644 index 0000000..2e8e74c Binary files /dev/null and b/cocktail_list/__pycache__/models.cpython-37.pyc differ diff --git a/cocktail_list/__pycache__/urls.cpython-37.pyc b/cocktail_list/__pycache__/urls.cpython-37.pyc new file mode 100644 index 0000000..e7a055e Binary files /dev/null and b/cocktail_list/__pycache__/urls.cpython-37.pyc differ diff --git a/cocktail_list/__pycache__/views.cpython-37.pyc b/cocktail_list/__pycache__/views.cpython-37.pyc new file mode 100644 index 0000000..6275efb Binary files /dev/null and b/cocktail_list/__pycache__/views.cpython-37.pyc differ diff --git a/cocktail_list/admin.py b/cocktail_list/admin.py new file mode 100644 index 0000000..5059c63 --- /dev/null +++ b/cocktail_list/admin.py @@ -0,0 +1,6 @@ +from django.contrib import admin +from .models import Ingredienti,Cocktail +# Register your models here. + +admin.site.register(Ingredienti) +admin.site.register(Cocktail) \ No newline at end of file diff --git a/cocktail_list/apps.py b/cocktail_list/apps.py new file mode 100644 index 0000000..b9d4313 --- /dev/null +++ b/cocktail_list/apps.py @@ -0,0 +1,5 @@ +from django.apps import AppConfig + + +class CocktailListConfig(AppConfig): + name = 'cocktail_list' diff --git a/cocktail_list/migrations/0001_initial.py b/cocktail_list/migrations/0001_initial.py new file mode 100644 index 0000000..e8fd78e --- /dev/null +++ b/cocktail_list/migrations/0001_initial.py @@ -0,0 +1,41 @@ +# Generated by Django 3.0.5 on 2020-05-24 15:08 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Ingredienti', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('ingrediente', models.CharField(max_length=100)), + ('quantitá', models.CharField(choices=[('5ML', '5 ml'), ('10ML', '10 ml'), ('15ML', '15 ml'), ('20ML', '20 ml'), ('25ML', '25 ml'), ('30ML', '30 ml'), ('35ML', '35 ml'), ('40ML', '40 ml'), ('45ML', '45 ml'), ('50ML', '50 ml'), ('55ML', '55 ml'), ('60ML', '60 ml'), ('65ML', '65 ml'), ('70ML', '70 ml'), ('75ML', '75 ml'), ('80ML', '80 ml'), ('85ML', '85 ml'), ('90ML', '90 ml'), ('95ML', '95 ml'), ('100ML', '100 ml'), ('1Goccia', '1 goccia'), ('2Gocce', '2 goccie'), ('3Gocce', '3 goccie'), ('4Gocce', '4 goccie'), ('5Gocce', '5 goccie'), ('Cubetti', '3 Cubetti')], default='5ML', max_length=30)), + ], + options={ + 'verbose_name': 'Ingrediente', + 'verbose_name_plural': 'Ingredienti', + }, + ), + migrations.CreateModel( + name='Cocktail', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('nome_cocktail', models.CharField(max_length=120)), + ('preparazione', models.TextField()), + ('storia', models.TextField()), + ('curiositá', models.TextField()), + ('ingredienti', models.ManyToManyField(to='cocktail_list.Ingredienti')), + ], + options={ + 'verbose_name': 'Cocktail', + 'verbose_name_plural': 'Cocktails', + }, + ), + ] diff --git a/cocktail_list/migrations/0002_cocktail_immagine_cocktail.py b/cocktail_list/migrations/0002_cocktail_immagine_cocktail.py new file mode 100644 index 0000000..070f30f --- /dev/null +++ b/cocktail_list/migrations/0002_cocktail_immagine_cocktail.py @@ -0,0 +1,18 @@ +# Generated by Django 3.0.5 on 2020-05-24 15:31 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('cocktail_list', '0001_initial'), + ] + + operations = [ + migrations.AddField( + model_name='cocktail', + name='immagine_cocktail', + field=models.ImageField(blank=True, null=True, upload_to='cocktail_img'), + ), + ] diff --git a/cocktail_list/migrations/__init__.py b/cocktail_list/migrations/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/cocktail_list/migrations/__pycache__/0001_initial.cpython-37.pyc b/cocktail_list/migrations/__pycache__/0001_initial.cpython-37.pyc new file mode 100644 index 0000000..8ec2e31 Binary files /dev/null and b/cocktail_list/migrations/__pycache__/0001_initial.cpython-37.pyc differ diff --git a/cocktail_list/migrations/__pycache__/0002_cocktail_immagine_cocktail.cpython-37.pyc b/cocktail_list/migrations/__pycache__/0002_cocktail_immagine_cocktail.cpython-37.pyc new file mode 100644 index 0000000..1a9ae88 Binary files /dev/null and b/cocktail_list/migrations/__pycache__/0002_cocktail_immagine_cocktail.cpython-37.pyc differ diff --git a/cocktail_list/migrations/__pycache__/__init__.cpython-37.pyc b/cocktail_list/migrations/__pycache__/__init__.cpython-37.pyc new file mode 100644 index 0000000..af5fb2b Binary files /dev/null and b/cocktail_list/migrations/__pycache__/__init__.cpython-37.pyc differ diff --git a/cocktail_list/models.py b/cocktail_list/models.py new file mode 100644 index 0000000..d3fdd77 --- /dev/null +++ b/cocktail_list/models.py @@ -0,0 +1,64 @@ +from django.db import models +from django.urls import reverse +# Create your models here. + + +class Ingredienti(models.Model): + ingrediente = models.CharField(max_length=100) + quantitá_scelta = [ + ('5ML', '5 ml'), + ('10ML', '10 ml'), + ('15ML', '15 ml'), + ('20ML', '20 ml'), + ('25ML', '25 ml'), + ('30ML', '30 ml'), + ('35ML', '35 ml'), + ('40ML', '40 ml'), + ('45ML', '45 ml'), + ('50ML', '50 ml'), + ('55ML', '55 ml'), + ('60ML', '60 ml'), + ('65ML', '65 ml'), + ('70ML', '70 ml'), + ('75ML', '75 ml'), + ('80ML', '80 ml'), + ('85ML', '85 ml'), + ('90ML', '90 ml'), + ('95ML', '95 ml'), + ('100ML', '100 ml'), + ('1Goccia', '1 goccia'), + ('2Gocce', '2 goccie'), + ('3Gocce', '3 goccie'), + ('4Gocce', '4 goccie'), + ('5Gocce', '5 goccie'), + ('Cubetti', '3 Cubetti'), + ] + quantitá = models.CharField(max_length=30,choices=quantitá_scelta,default="5ML") + + def __str__(self): + return self.ingrediente + + class Meta: + verbose_name = "Ingrediente" + verbose_name_plural = "Ingredienti" + + + + +class Cocktail(models.Model): + ingredienti = models.ManyToManyField(Ingredienti) + nome_cocktail = models.CharField(max_length=120) + preparazione = models.TextField() + storia = models.TextField() + curiositá = models.TextField() + immagine_cocktail = models.ImageField(upload_to="cocktail_img",blank=True,null=True) + + def __str__(self): + return self.nome_cocktail + + def get_absolute_url(self): + return reverse('cocktail', kwargs={'nome_cocktail': self.nome_cocktail}) + + class Meta: + verbose_name = "Cocktail" + verbose_name_plural = "Cocktails" diff --git a/cocktail_list/templates/cocktail.html b/cocktail_list/templates/cocktail.html new file mode 100644 index 0000000..b3f3d47 --- /dev/null +++ b/cocktail_list/templates/cocktail.html @@ -0,0 +1,32 @@ +{% extends "base.html" %} + +{% block css %} + + +{% endblock css %} + + +{% block title %} +COCKTAIL | {{ cocktail.nome_cocktail }} +{% endblock title %} + +{% block content %} +
+

{{ cocktail.nome_cocktail }}

+
{{ cocktail.nome_cocktail }}
+

{{ cocktail.ingredienti.all|join:"," }}

+
+{% endblock content %} \ No newline at end of file diff --git a/cocktail_list/templates/homepage.html b/cocktail_list/templates/homepage.html new file mode 100644 index 0000000..16a80b0 --- /dev/null +++ b/cocktail_list/templates/homepage.html @@ -0,0 +1,48 @@ +{% extends "base.html" %} +{% block content %} + {% for cocktail in lista_cocktail %} + + {% block css %} + + + {% endblock css %} + {% if forloop.first %}
{% endif %} + + {% if forloop.counter|divisibleby:"3" or forloop.last %} +
+ {% endif %} + {% if forloop.counter|divisibleby:"3" and not forloop.last %} +
+ {% endif %} + {% endfor %} +{% endblock content %} \ No newline at end of file diff --git a/cocktail_list/tests.py b/cocktail_list/tests.py new file mode 100644 index 0000000..7ce503c --- /dev/null +++ b/cocktail_list/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/cocktail_list/urls.py b/cocktail_list/urls.py new file mode 100644 index 0000000..bba4c01 --- /dev/null +++ b/cocktail_list/urls.py @@ -0,0 +1,7 @@ +from django.urls import path +from .views import homepage,cocktail + +urlpatterns = [ + path("",homepage,name="Homepage"), + path("cocktail//",cocktail,name="cocktail"), +] \ No newline at end of file diff --git a/cocktail_list/views.py b/cocktail_list/views.py new file mode 100644 index 0000000..fd61734 --- /dev/null +++ b/cocktail_list/views.py @@ -0,0 +1,27 @@ +from django.shortcuts import render,get_object_or_404,redirect +from .models import Cocktail,Ingredienti + +# Create your views here. + + +def homepage(request): + lista_cocktail = Cocktail.objects.all() + context = {"lista_cocktail":lista_cocktail} + return render(request,"homepage.html",context) + + +def cocktail(request,nome_cocktail): + cocktail = get_object_or_404(Cocktail,nome_cocktail=nome_cocktail) + context = {"cocktail":cocktail} + return render(request,"cocktail.html",context) + +def cerca(request): + if "q" in request.GET: + querystring = request.GET.get("q") + if len(querystring) == 0: + return redirect("cerca/") + cocktail = Cocktail.objects.filter(nome_cocktail__icontains=querystring).order_by("-nome_cocktail") + context = {"cocktail":cocktail} + return render(request,"cerca.html",context) + else: + return render(request,"cerca.html") diff --git a/db.sqlite3 b/db.sqlite3 new file mode 100644 index 0000000..c3b4f7f Binary files /dev/null and b/db.sqlite3 differ diff --git a/manage.py b/manage.py new file mode 100755 index 0000000..5a899fa --- /dev/null +++ b/manage.py @@ -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', 'cocktail.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()