diff --git a/src/website b/src/website deleted file mode 160000 index 09982f91..00000000 --- a/src/website +++ /dev/null @@ -1 +0,0 @@ -Subproject commit 09982f911cf8802421e2062cc7ba694cf897616f diff --git a/src/website/.gitignore b/src/website/.gitignore new file mode 100644 index 00000000..d03bd089 --- /dev/null +++ b/src/website/.gitignore @@ -0,0 +1,138 @@ +# Django # +*.log +*.pot +*.pyc +__pycache__ +db.sqlite3 +media + +# Backup files # +*.bak + +# If you are using PyCharm # +# User-specific stuff +.idea/**/workspace.xml +.idea/**/tasks.xml +.idea/**/usage.statistics.xml +.idea/**/dictionaries +.idea/**/shelf + +# AWS User-specific +.idea/**/aws.xml + +# Generated files +.idea/**/contentModel.xml + +# Sensitive or high-churn files +.idea/**/dataSources/ +.idea/**/dataSources.ids +.idea/**/dataSources.local.xml +.idea/**/sqlDataSources.xml +.idea/**/dynamic.xml +.idea/**/uiDesigner.xml +.idea/**/dbnavigator.xml + +# Gradle +.idea/**/gradle.xml +.idea/**/libraries + +# File-based project format +*.iws + +# IntelliJ +out/ + +# JIRA plugin +atlassian-ide-plugin.xml + +# Python # +*.py[cod] +*$py.class + +# Distribution / packaging +.Python build/ +develop-eggs/ +dist/ +downloads/ +eggs/ +.eggs/ +lib/ +lib64/ +parts/ +sdist/ +var/ +wheels/ +*.egg-info/ +.installed.cfg +*.egg +*.manifest +*.spec + +# Installer logs +pip-log.txt +pip-delete-this-directory.txt + +# Unit test / coverage reports +htmlcov/ +.tox/ +.coverage +.coverage.* +.cache +.pytest_cache/ +nosetests.xml +coverage.xml +*.cover +.hypothesis/ + +# Jupyter Notebook +.ipynb_checkpoints + +# pyenv +.python-version + +# celery +celerybeat-schedule.* + +# SageMath parsed files +*.sage.py + +# Environments +.env +.venv +env/ +env_dj/ +venv/ +ENV/ +env.bak/ +venv.bak/ + +# mkdocs documentation +/site + +# mypy +.mypy_cache/ + +# Sublime Text # +*.tmlanguage.cache +*.tmPreferences.cache +*.stTheme.cache +*.sublime-workspace +*.sublime-project + +# sftp configuration file +sftp-config.json + +# Package control specific files Package +Control.last-run +Control.ca-list +Control.ca-bundle +Control.system-ca-bundle +GitHub.sublime-settings + +# Visual Studio Code # +.vscode/* +!.vscode/settings.json +!.vscode/tasks.json +!.vscode/launch.json +!.vscode/extensions.json +.history \ No newline at end of file diff --git a/src/website/__init__.py b/src/website/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/website/admin.py b/src/website/admin.py new file mode 100644 index 00000000..3430dfef --- /dev/null +++ b/src/website/admin.py @@ -0,0 +1,24 @@ +from django.contrib import admin +from .models import Image,Contact,Opening_hour, Gallery + + +class ImageAdmin(admin.ModelAdmin): + list_display=('id', 'gallery', 'description', 'is_first', 'show_image') + + +class GalleryAdmin(admin.ModelAdmin): + list_display=('id', 'name', 'get_images') + + +class ContactAdmin(admin.ModelAdmin): + list_display = ('id', 'phone', 'mail') + + +class OpeningHoursAdmin(admin.ModelAdmin): + list_display = ('id', 'weekdays', 'weekend', 'closing_day') + + +admin.site.register(Gallery, GalleryAdmin) +admin.site.register(Image, ImageAdmin) +admin.site.register(Contact, ContactAdmin) +admin.site.register(Opening_hour, OpeningHoursAdmin) \ No newline at end of file diff --git a/src/website/apps.py b/src/website/apps.py new file mode 100644 index 00000000..2b099b13 --- /dev/null +++ b/src/website/apps.py @@ -0,0 +1,6 @@ +from django.apps import AppConfig + + +class WebsiteConfig(AppConfig): + default_auto_field = 'django.db.models.BigAutoField' + name = 'website' diff --git a/src/website/docs/README.md b/src/website/docs/README.md new file mode 100644 index 00000000..3db6086e --- /dev/null +++ b/src/website/docs/README.md @@ -0,0 +1,64 @@ + +# Website + +The **website** app is a Django application designed to manage basic web pages within a website. + +## Quick Start + +1. Add "website" to your `INSTALLED_APPS` in your Django project's settings: + + ```python + INSTALLED_APPS = [ + ... + 'website', + ] + + ``` + + + +2. Include the website URLconf in your project urls.py like this:: +you may want to add some url path inside the '' + + > path('', include(('website.urls', 'website'), namespace="website")), + +3. Run ``python manage.py migrate website`` to create the website models. + +4. Start the development server and visit http://127.0.0.1:8000/admin/ + to create the models (you'll need the Admin app enabled). + +5. Visit http://127.0.0.1:8000 to see the website + + +----------- + +# website docs +if you want to use the article links outside the app you need to use the namespace. +it is always a good idea when having many apps inside a Django project to use the namespace. +for example: + + > + + +... + +## User Registration + +To enable user registration and authentication, follow these steps: + +1. Add `'django.contrib.auth'` and `'django.contrib.auth.urls'` to your `INSTALLED_APPS` in your Django project's settings: + + ```python + INSTALLED_APPS = [ + ... + 'django.contrib.auth', + ... + ] + +2. Include the authentication URLconf in your **project**'s urls.py: + + + >path('accounts/', include('django.contrib.auth.urls')), + + +Now, your website should have user registration and authentication functionality. For more advanced features, refer to the Django Authentication documentation. \ No newline at end of file diff --git a/src/website/forms.py b/src/website/forms.py new file mode 100644 index 00000000..ec1a2d23 --- /dev/null +++ b/src/website/forms.py @@ -0,0 +1,60 @@ +from django import forms +from .models import Image, Contact, Opening_hour, Gallery + +class ImageForm(forms.ModelForm): + class Meta: + model = Image + fields = ['gallery', 'description', 'img', 'is_first'] + widgets = { + 'description': forms.TextInput(attrs={'placeholder': 'Necessaria ad identificarla'}), + } + + +class ContactForm(forms.ModelForm): + class Meta: + model = Contact + fields = ['phone', 'mail'] + widgets = { + 'phone': forms.TextInput(attrs={'placeholder': 'Inserisci il numero di telefono'}), + 'mail': forms.TextInput(attrs={'placeholder': 'Inserisci l\'indirizzo email'}), + } + + +class OpeningHourForm(forms.ModelForm): + class Meta: + model = Opening_hour + fields = ['weekdays', 'weekend', 'closing_day'] + widgets = { + 'weekdays': forms.TextInput(attrs={'placeholder': 'Inserisci gli orari settimanali'}), + 'weekend': forms.TextInput(attrs={'placeholder': 'Inserisci gli orari del weekend'}), + 'closing_day': forms.TextInput(attrs={'placeholder': 'Inserisci un giorno della settimana'}), + } + + +class GalleryForm(forms.ModelForm): + class Meta: + model = Gallery + fields = ['name', 'images'] + widgets = { + 'name': forms.TextInput(attrs={'placeholder': 'Non usare spazi nel nome'}), + 'images': forms.SelectMultiple(attrs={'class': 'form-control'}), + } + + images = forms.ModelMultipleChoiceField( + queryset=Image.objects.filter(gallery__isnull=True), + required=False + ) + + def save(self, commit=True): + gallery = super().save(commit=False) + if commit: + gallery.save() + + # Associa le immagini selezionate alla galleria + images = self.cleaned_data.get('images') + if images: + for image in images: + image.gallery = gallery + image.save() + + return gallery \ No newline at end of file diff --git a/src/website/migrations/0001_initial.py b/src/website/migrations/0001_initial.py new file mode 100644 index 00000000..8f1f1d83 --- /dev/null +++ b/src/website/migrations/0001_initial.py @@ -0,0 +1,42 @@ +# Generated by Django 4.1.7 on 2023-09-19 15:34 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Contact', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('phone', models.CharField(blank=True, max_length=100, null=True)), + ('mail', models.CharField(blank=True, max_length=50, null=True)), + ], + ), + migrations.CreateModel( + name='Gallery_image', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('gallery_name', models.CharField(max_length=100)), + ('header', models.CharField(blank=True, default='', max_length=100, null=True)), + ('description', models.CharField(blank=True, default='', max_length=300, null=True)), + ('img', models.ImageField(blank=True, null=True, upload_to='')), + ('is_first', models.BooleanField(default=False)), + ], + ), + migrations.CreateModel( + name='Opening_hour', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('weekdays', models.CharField(blank=True, max_length=200, null=True)), + ('weekend', models.CharField(blank=True, max_length=300, null=True)), + ('closing_day', models.CharField(blank=True, max_length=200, null=True)), + ], + ), + ] diff --git a/src/website/migrations/0002_remove_gallery_image_header.py b/src/website/migrations/0002_remove_gallery_image_header.py new file mode 100644 index 00000000..80bc9c3c --- /dev/null +++ b/src/website/migrations/0002_remove_gallery_image_header.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.7 on 2023-09-27 10:10 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0001_initial'), + ] + + operations = [ + migrations.RemoveField( + model_name='gallery_image', + name='header', + ), + ] diff --git a/src/website/migrations/0003_remove_gallery_image_img.py b/src/website/migrations/0003_remove_gallery_image_img.py new file mode 100644 index 00000000..fe493f27 --- /dev/null +++ b/src/website/migrations/0003_remove_gallery_image_img.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.7 on 2023-09-28 17:33 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0002_remove_gallery_image_header'), + ] + + operations = [ + migrations.RemoveField( + model_name='gallery_image', + name='img', + ), + ] diff --git a/src/website/migrations/0004_gallery_image_img.py b/src/website/migrations/0004_gallery_image_img.py new file mode 100644 index 00000000..d6051d88 --- /dev/null +++ b/src/website/migrations/0004_gallery_image_img.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-09-28 17:35 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0003_remove_gallery_image_img'), + ] + + operations = [ + migrations.AddField( + model_name='gallery_image', + name='img', + field=models.ImageField(blank=True, null=True, upload_to=''), + ), + ] diff --git a/src/website/migrations/0005_remove_gallery_image_img.py b/src/website/migrations/0005_remove_gallery_image_img.py new file mode 100644 index 00000000..6dcdd6a9 --- /dev/null +++ b/src/website/migrations/0005_remove_gallery_image_img.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.7 on 2023-09-28 21:43 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0004_gallery_image_img'), + ] + + operations = [ + migrations.RemoveField( + model_name='gallery_image', + name='img', + ), + ] diff --git a/src/website/migrations/0006_gallery_image_img.py b/src/website/migrations/0006_gallery_image_img.py new file mode 100644 index 00000000..05435a02 --- /dev/null +++ b/src/website/migrations/0006_gallery_image_img.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-09-28 21:44 + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0005_remove_gallery_image_img'), + ] + + operations = [ + migrations.AddField( + model_name='gallery_image', + name='img', + field=models.ImageField(blank=True, null=True, upload_to=''), + ), + ] diff --git a/src/website/migrations/0007_carousel_image_delete_gallery_image.py b/src/website/migrations/0007_carousel_image_delete_gallery_image.py new file mode 100644 index 00000000..d98b5e21 --- /dev/null +++ b/src/website/migrations/0007_carousel_image_delete_gallery_image.py @@ -0,0 +1,34 @@ +# Generated by Django 4.1.7 on 2023-09-29 10:13 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0006_gallery_image_img'), + ] + + operations = [ + migrations.CreateModel( + name='Carousel', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=100)), + ], + ), + migrations.CreateModel( + name='Image', + fields=[ + ('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('description', models.CharField(blank=True, default='', max_length=300, null=True)), + ('img', models.ImageField(blank=True, null=True, upload_to='')), + ('is_first', models.BooleanField(default=False)), + ('carousel', models.ForeignKey(blank=True, null=True, on_delete=django.db.models.deletion.CASCADE, related_name='images', to='website.carousel')), + ], + ), + migrations.DeleteModel( + name='Gallery_image', + ), + ] diff --git a/src/website/migrations/0008_rename_carousel_gallery.py b/src/website/migrations/0008_rename_carousel_gallery.py new file mode 100644 index 00000000..ae98ae73 --- /dev/null +++ b/src/website/migrations/0008_rename_carousel_gallery.py @@ -0,0 +1,17 @@ +# Generated by Django 4.1.7 on 2023-09-29 10:31 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0007_carousel_image_delete_gallery_image'), + ] + + operations = [ + migrations.RenameModel( + old_name='Carousel', + new_name='Gallery', + ), + ] diff --git a/src/website/migrations/0009_rename_carousel_image_gallery.py b/src/website/migrations/0009_rename_carousel_image_gallery.py new file mode 100644 index 00000000..55c5becb --- /dev/null +++ b/src/website/migrations/0009_rename_carousel_image_gallery.py @@ -0,0 +1,18 @@ +# Generated by Django 4.1.7 on 2023-09-29 10:36 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0008_rename_carousel_gallery'), + ] + + operations = [ + migrations.RenameField( + model_name='image', + old_name='carousel', + new_name='gallery', + ), + ] diff --git a/src/website/migrations/0010_alter_gallery_options_alter_image_description_and_more.py b/src/website/migrations/0010_alter_gallery_options_alter_image_description_and_more.py new file mode 100644 index 00000000..245d4da2 --- /dev/null +++ b/src/website/migrations/0010_alter_gallery_options_alter_image_description_and_more.py @@ -0,0 +1,33 @@ +# Generated by Django 4.1.7 on 2023-09-29 16:33 + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('website', '0009_rename_carousel_image_gallery'), + ] + + operations = [ + migrations.AlterModelOptions( + name='gallery', + options={'verbose_name_plural': 'Galleries'}, + ), + migrations.AlterField( + model_name='image', + name='description', + field=models.CharField(blank=True, default='', help_text="identifica l'immagine", max_length=300, null=True), + ), + migrations.AlterField( + model_name='image', + name='gallery', + field=models.ForeignKey(blank=True, help_text='Non necessario se non deve essere inserita in una galleria', null=True, on_delete=django.db.models.deletion.CASCADE, related_name='images', to='website.gallery'), + ), + migrations.AlterField( + model_name='image', + name='is_first', + field=models.BooleanField(default=False, help_text='clicca se vuoi che sia la prima ad essere visualizzata in un eventuale galleria'), + ), + ] diff --git a/src/website/migrations/__init__.py b/src/website/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/src/website/models.py b/src/website/models.py new file mode 100644 index 00000000..9ed06a29 --- /dev/null +++ b/src/website/models.py @@ -0,0 +1,57 @@ +from django.db import models +from django.utils.html import format_html +from django.conf import settings +import os + +### information models +class Gallery(models.Model): + name = models.CharField(max_length=100) + + class Meta: + verbose_name_plural = 'Galleries' + + + def get_images(self): + return self.images.all() + + def __str__(self): + return self.name + + +class Image(models.Model): + gallery = models.ForeignKey(Gallery, on_delete=models.CASCADE, related_name='images', null=True, blank=True, help_text="Non necessario se non deve essere inserita in una galleria") + description = models.CharField(max_length=300, default="", blank=True, null=True, help_text="identifica l'immagine") + img = models.ImageField(upload_to="", blank=True, null=True) + is_first = models.BooleanField(default=False, help_text="clicca se vuoi che sia la prima ad essere visualizzata in un eventuale galleria") + + + def show_image(self): + return format_html('', self.img.url) + + def __str__(self): + return self.img.url + + def delete(self, *args, **kwargs): + # Elimina il file dal server + if self.img: + path = os.path.join(settings.MEDIA_ROOT, str(self.img)) + os.remove(path) + + super().delete(*args, **kwargs) + + +class Contact(models.Model): + phone = models.CharField(max_length=100, blank=True, null=True) + mail = models.CharField(max_length=50, blank=True, null=True) + + def __str__(self): + return "Contacts" + + +class Opening_hour(models.Model): + weekdays = models.CharField(max_length = 200, blank=True, null=True) + weekend = models.CharField(max_length=300, blank=True, null=True) + closing_day = models.CharField(max_length=200, blank=True, null=True) + + def __str__(self): + return "Opening hours" \ No newline at end of file diff --git a/src/website/static/favicon/bee.ico b/src/website/static/favicon/bee.ico new file mode 100644 index 00000000..a6dd3b58 Binary files /dev/null and b/src/website/static/favicon/bee.ico differ diff --git a/src/website/static/icons/github.svg b/src/website/static/icons/github.svg new file mode 100644 index 00000000..3b864bef --- /dev/null +++ b/src/website/static/icons/github.svg @@ -0,0 +1,6 @@ + + + + + + diff --git a/src/website/static/icons/linkedin.svg b/src/website/static/icons/linkedin.svg new file mode 100644 index 00000000..4cc45ff8 --- /dev/null +++ b/src/website/static/icons/linkedin.svg @@ -0,0 +1 @@ + \ No newline at end of file diff --git a/src/website/static/pwa/icons/Icon-512x512.png b/src/website/static/pwa/icons/Icon-512x512.png new file mode 100644 index 00000000..a5e28f0d Binary files /dev/null and b/src/website/static/pwa/icons/Icon-512x512.png differ diff --git a/src/website/static/pwa/icons/icon-256x256.png b/src/website/static/pwa/icons/icon-256x256.png new file mode 100644 index 00000000..29cad075 Binary files /dev/null and b/src/website/static/pwa/icons/icon-256x256.png differ diff --git a/src/website/static/pwa/js/service-worker.js b/src/website/static/pwa/js/service-worker.js new file mode 100644 index 00000000..d3af21d0 --- /dev/null +++ b/src/website/static/pwa/js/service-worker.js @@ -0,0 +1,22 @@ +self.addEventListener('install', (event) => { + event.waitUntil( + caches.open('my-cache').then((cache) => { + return cache.addAll([ + '/', + //'/static/css/style.css', + //'/static/js/main.js', + '/static/icons/bee.png', + // Aggiungi qui altri file che desideri siano in cache + ]); + }) + ); + }); + + self.addEventListener('fetch', (event) => { + event.respondWith( + caches.match(event.request).then((response) => { + return response || fetch(event.request); + }) + ); + }); + \ No newline at end of file diff --git a/src/website/static/pwa/manifest.json b/src/website/static/pwa/manifest.json new file mode 100644 index 00000000..044606a5 --- /dev/null +++ b/src/website/static/pwa/manifest.json @@ -0,0 +1,22 @@ +{ + "name": "Nome dell'app", + "short_name": "Nome breve", + "description": "Descrizione dell'app", + "start_url": "/", + "display": "standalone", + "background_color": "#ffffff", + "theme_color": "#000000", + "icons": [ + { + "src": "/static/pwa/icons/icon-256x256.png", + "sizes": "256x256", + "type": "image/png" + }, + { + "src": "/static/pwa/icons/icon-512x512.png", + "sizes": "512x512", + "type": "image/png" + } + ] + } + \ No newline at end of file diff --git a/src/website/templates/registration/login.html b/src/website/templates/registration/login.html new file mode 100644 index 00000000..71e11334 --- /dev/null +++ b/src/website/templates/registration/login.html @@ -0,0 +1,28 @@ +{% extends "website/base.html" %} +{% load static %} + +{% block content %} +
+
+
+
+
Login
+
+
+ {% csrf_token %} +
+ + +
+
+ + +
+ +
+
+
+
+
+
+{% endblock %} diff --git a/src/website/templates/registration/logout.html b/src/website/templates/registration/logout.html new file mode 100644 index 00000000..0824d53a --- /dev/null +++ b/src/website/templates/registration/logout.html @@ -0,0 +1,22 @@ +{% extends "website/base.html" %} + +{% block title %}Logout{% endblock %} + +{% block content %} +
+
+
+
+
Logout
+
+

Sei sicuro di voler effettuare il logout?

+
+ {% csrf_token %} + +
+
+
+
+
+
+{% endblock %} diff --git a/src/website/templates/registration/password_reset.html b/src/website/templates/registration/password_reset.html new file mode 100644 index 00000000..50216093 --- /dev/null +++ b/src/website/templates/registration/password_reset.html @@ -0,0 +1,24 @@ +{% extends "website/base.html" %} +{% load static %} + +{% block content %} +
+
+
+
+
Reset Password
+
+
+ {% csrf_token %} +
+ + +
+ +
+
+
+
+
+
+{% endblock %} diff --git a/src/website/templates/website/base.html b/src/website/templates/website/base.html new file mode 100644 index 00000000..6c0a2873 --- /dev/null +++ b/src/website/templates/website/base.html @@ -0,0 +1,46 @@ +{% load static %} + + + + + + + Leonardo Bitto + + + + + + + + + + + + + + + + {% include 'website/navbar.html' %} + + {% block content %} + + {% endblock content %} + + + {% include 'website/footer.html' %} + + + + + \ No newline at end of file diff --git a/src/website/templates/website/dashboard/contact_page.html b/src/website/templates/website/dashboard/contact_page.html new file mode 100644 index 00000000..101919d6 --- /dev/null +++ b/src/website/templates/website/dashboard/contact_page.html @@ -0,0 +1,34 @@ +
+ {% if messages %} + + {% endif %} +
+ + {% if not contacts %} +
+

Aggiungi Contatto

+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+ {% else %} + + +
+

Contatti

+

Telefono: {{ contacts.0.phone }}

+

Email: {{ contacts.0.mail }}

+
+ {% csrf_token %} + +
+
+ {% endif %} +
+
diff --git a/src/website/templates/website/dashboard/dashboard.html b/src/website/templates/website/dashboard/dashboard.html new file mode 100644 index 00000000..9bfca4b9 --- /dev/null +++ b/src/website/templates/website/dashboard/dashboard.html @@ -0,0 +1,57 @@ +{% extends "website/base.html" %} +{% load static %} + +{% block content %} +

Dashboard

+
+
+ + +
+ +
+
+
+{% endblock content %} + + diff --git a/src/website/templates/website/dashboard/gallery_page.html b/src/website/templates/website/dashboard/gallery_page.html new file mode 100644 index 00000000..41e616a1 --- /dev/null +++ b/src/website/templates/website/dashboard/gallery_page.html @@ -0,0 +1,74 @@ +
+ + + + + +
+
+ {% csrf_token add_gallery_csrf_token %} + {{ form.as_p }} + +
+
+ + + +
+ diff --git a/src/website/templates/website/dashboard/image_page.html b/src/website/templates/website/dashboard/image_page.html new file mode 100644 index 00000000..a6168cf6 --- /dev/null +++ b/src/website/templates/website/dashboard/image_page.html @@ -0,0 +1,53 @@ +
+ + + + + +
+
+ {% csrf_token add_image_csrf_token %} + {{ form.as_p }} + +
+
+ + +
+ {% if images %} +

Lista delle immagini

+ + {% else %} +

Non sono presenti immagini al momento.

+ {% endif %} +
+ + + +
diff --git a/src/website/templates/website/dashboard/opening_hours_page.html b/src/website/templates/website/dashboard/opening_hours_page.html new file mode 100644 index 00000000..93739843 --- /dev/null +++ b/src/website/templates/website/dashboard/opening_hours_page.html @@ -0,0 +1,36 @@ +
+ {% if messages %} + + {% endif %} +
+ {% if not opening_hours %} + +
+

Aggiungi Orario Apertura

+
+ {% csrf_token %} + {{ form.as_p }} + +
+
+ {% else %} + +
+

Orario Apertura

+

Settimana: {{ opening_hours.0.weekdays }}

+

Weekend: {{ opening_hours.0.weekend }}

+

Giorno di Chiusura: {{ opening_hours.0.closing_day }}

+ +
+ {% csrf_token %} + +
+
+ {% endif %} +
+
+ diff --git a/src/website/templates/website/footer.html b/src/website/templates/website/footer.html new file mode 100644 index 00000000..0606de8c --- /dev/null +++ b/src/website/templates/website/footer.html @@ -0,0 +1,71 @@ + + + + \ No newline at end of file diff --git a/src/website/templates/website/landing.html b/src/website/templates/website/landing.html new file mode 100644 index 00000000..f75d772f --- /dev/null +++ b/src/website/templates/website/landing.html @@ -0,0 +1,8 @@ +{% extends "website/base.html" %} +{% load static %} +{% block content %} + + + + +{% endblock %} \ No newline at end of file diff --git a/src/website/templates/website/navbar.html b/src/website/templates/website/navbar.html new file mode 100644 index 00000000..edda918c --- /dev/null +++ b/src/website/templates/website/navbar.html @@ -0,0 +1,24 @@ + \ No newline at end of file diff --git a/src/website/tests.py b/src/website/tests.py new file mode 100644 index 00000000..7ce503c2 --- /dev/null +++ b/src/website/tests.py @@ -0,0 +1,3 @@ +from django.test import TestCase + +# Create your tests here. diff --git a/src/website/urls.py b/src/website/urls.py new file mode 100644 index 00000000..e08c5333 --- /dev/null +++ b/src/website/urls.py @@ -0,0 +1,21 @@ +from django.urls import path +from . import views + +app_name="website" +urlpatterns = [ + path('', views.base, name="home"), + path('dashboard/', views.dashboard, name='dashboard'), + + path('dashboard/image/', views.image_page, name='image_page'), + path('dashboard/contact/', views.contact_page, name='contact_page'), + path('dashboard/opening_hours/', views.opening_hours_page, name='opening_hours_page'), + path('dashboard/gallery', views.gallery_page, name='gallery_page'), + path('dashboard/add_image/', views.add_image, name='add_image'), + path('dashboard/add_contact/', views.add_contact, name='add_contact'), + path('dashboard/add_opening_hour/', views.add_opening_hour, name='add_opening_hour'), + path('dashboard/add_gallery/', views.add_gallery, name='add_gallery'), + path('delete_image//', views.delete_image, name='delete_image'), + path('delete_contact//', views.delete_contact, name='delete_contact'), + path('delete_opening_hours//', views.delete_opening_hour, name='delete_opening_hour'), + path('delete_gallery//', views.delete_gallery, name='delete_gallery'), +] \ No newline at end of file diff --git a/src/website/views.py b/src/website/views.py new file mode 100644 index 00000000..def7db49 --- /dev/null +++ b/src/website/views.py @@ -0,0 +1,177 @@ +from django.shortcuts import render, redirect, get_object_or_404 +from django.contrib.auth.decorators import login_required +from .models import Image, Contact, Opening_hour, Gallery +from .forms import ImageForm, ContactForm, OpeningHourForm, GalleryForm +from django.contrib import messages + +# this is the part of the website accessible only to admin +@login_required +def dashboard(request): + + # Recupera tutte le istanze dei modelli + gallery_images = Image.objects.all() + contacts = Contact.objects.all() + opening_hours = Opening_hour.objects.all() + gallery = Gallery.objects.all() + + context = { + 'gallery_images': gallery_images, + 'contacts': contacts, + 'opening_hours': opening_hours, + 'gallery': gallery, + } + + return render(request, 'website/dashboard/dashboard.html', context) + +@login_required +def image_page(request): + images = Image.objects.all() + form = ImageForm() + + context = { + 'images': images, + 'form': form, + } + + return render(request, 'website/dashboard/image_page.html', context) + +@login_required +def add_image(request): + print(request) + if request.method == 'POST': + form = ImageForm(request.POST, request.FILES) + if form.is_valid(): + form.save() + messages.success(request, 'Immagine aggiunta con successo.') + return redirect('website:dashboard') + else: + messages.error(request, 'Si è verificato un errore. Si prega di correggere il modulo.') + else: + form = ImageForm() + + return render(request, 'website/dashboard/image_page.html', {'form': form}) + +@login_required +def delete_image(request, image_id): + # Trova l'immagine nel database + image = get_object_or_404(Image, id=image_id) + + # Elimina l'immagine + image.delete() + messages.success(request, 'Immagine eliminata con successo.') + return redirect('website:dashboard') + +@login_required +def gallery_page(request): + galleries = Gallery.objects.all() + form = GalleryForm() + + context = { + 'galleries': galleries, + 'form': form, + } + + return render(request, 'website/dashboard/gallery_page.html', context) + +@login_required +def add_gallery(request): + print(request) + if request.method == 'POST': + form = GalleryForm(request.POST, request.FILES) + if form.is_valid(): + form.save() + messages.success(request, 'Galleria aggiunta con successo.') + return redirect('website:dashboard') + else: + messages.error(request, 'Si è verificato un errore. Si prega di correggere il modulo.') + else: + form = ImageForm() + + return render(request, 'website/dashboard/gallery_page.html', {'form': form}) + +@login_required +def delete_gallery(request, gallery_id): + # Trova l'immagine nel database + gallery = get_object_or_404(Gallery, id=gallery_id) + + # Elimina l'immagine + gallery.delete() + messages.success(request, 'Galleria eliminata con successo.') + return redirect('website:dashboard') + + +@login_required +def contact_page(request): + contacts = Contact.objects.all() + form = ContactForm() + context = { + 'contacts': contacts, + 'form':form, + } + + return render(request, 'website/dashboard/contact_page.html', context) + +@login_required +def add_contact(request): + if request.method == 'POST': + form = ContactForm(request.POST) + if form.is_valid(): + form.save() + messages.success(request, 'Contatto aggiunto con successo.') + return redirect('website:contact_page') + else: + messages.error(request, 'Si è verificato un errore. Si prega di correggere il modulo.') + else: + form = ContactForm() + + return render(request, 'website/dashboard/contact_page.html', {'form': form}) + +@login_required +def delete_contact(request, contact_id): + contact = get_object_or_404(Contact, pk=contact_id) + contact.delete() + messages.success(request, 'Contatto eliminato con successo.') + return redirect('website:dashboard') + + +@login_required +def opening_hours_page(request): + opening_hours = Opening_hour.objects.all() + form = OpeningHourForm() + context = { + 'opening_hours': opening_hours, + 'form':form, + } + + return render(request, 'website/dashboard/opening_hours_page.html', context) + +@login_required +def add_opening_hour(request): + if request.method == 'POST': + form = OpeningHourForm(request.POST) + if form.is_valid(): + form.save() + messages.success(request, 'Orario aggiunto con successo. Ricorda di cambiare gli orari anche su Google.') + return redirect('website:opening_hours_page') + else: + messages.error(request, 'Si è verificato un errore. Si prega di correggere il modulo.') + else: + form = OpeningHourForm() + + return render(request, 'website/dashboard/opening_hours_page.html', {'form': form}) + +@login_required +def delete_opening_hour(request, opening_hour_id): + hours = get_object_or_404(Opening_hour, pk=opening_hour_id) + hours.delete() + messages.success(request, 'Orario eliminato con successo.') + return redirect('website:dashboard') + + + +# this is part of the website accessible to everyone +def base(request): + + context = {} + + return render(request, 'website/landing.html', context) \ No newline at end of file