diff --git a/README.md b/README.md index 9c1befe..e4f0ea0 100644 --- a/README.md +++ b/README.md @@ -34,7 +34,12 @@ vagrant up Vagrant will then provision a virtual machine according to the specifications in the "Vagrantfile" file. After it's finished you -should be able to access the web page under http://localhost:8000 +should be able to access the web page under http://localhost:8080 + +To access the admin panel visit http://localhost:8080/admin the +default login is admin and the corresponding password is +"password". By default the application contains no data, you can enter +whatever you need. ### Support diff --git a/Vagrantfile b/Vagrantfile index b7f26bb..7e8c3d7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -32,29 +32,7 @@ Vagrant.configure("2") do |config| libnss-mdns libapache2-mod-wsgi-py3 python3-mysqldb python3-pip pip3 install django-extensions Pillow - - #initialize the db - mysql < /vagrant/sql/04_remove_database.sql - mysql < /vagrant/sql/01_create_database.sql - - #löschen und verlinken der HTML root damit man diese nicht manuel kopieren muss. - if ! [ -L /var/www/html ]; then - rm -rf /var/www/html - ln -s /vagrant/html /var/www/html - fi - - #Copy the apache configuration for django to the correct place - cp /vagrant/apache/000-default.conf /etc/apache2/sites-available/ - #restart the webserver - systemctl restart apache2.service - rm /vagrant/django/didgeridoo/webshop/migrations/*.py - python3 /vagrant/django/didgeridoo/manage.py makemigrations webshop - python3 /vagrant/django/didgeridoo/manage.py migrate - mysql < /vagrant/sql/02_insert_data.sql - echo "from django.contrib.auth.models import User; \ - User.objects.filter(email='admin@example.com').delete(); \ - User.objects.create_superuser('admin', 'admin@example.com', 'password')" | - python3 /vagrant/django/didgeridoo/manage.py shell + /vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh SHELL end diff --git a/ansible/roles/common/tasks/main.yml b/ansible/roles/common/tasks/main.yml index d6efaf9..3963609 100644 --- a/ansible/roles/common/tasks/main.yml +++ b/ansible/roles/common/tasks/main.yml @@ -1,7 +1,7 @@ # System Upgrade and package installation -- include: tasks/apt_update_cache.yml -- include: tasks/apt_distupgrade.yml -- include: tasks/apt_install.yml +- import_tasks: tasks/apt_update_cache.yml +- import_tasks: tasks/apt_distupgrade.yml +- import_tasks: tasks/apt_install.yml # User configuration - name: Lock root user @@ -16,7 +16,7 @@ line='{{ deploy_user_name }} ALL=(ALL) NOPASSWD: ALL' state=present" -- include: tasks/ufw_tcp.yml +- import_tasks: tasks/ufw_tcp.yml - name: Copy over the sshd_config file template: src=sshd_config.j2 dest=/etc/ssh/sshd_config owner=root group=root diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index 985c193..e956179 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -1,15 +1,36 @@ --- -- include: tasks/apt_install.yml -- include: tasks/ufw_tcp.yml +- import_tasks: tasks/apt_install.yml +- import_tasks: tasks/ufw_tcp.yml -- include: mariadb.yml +- import_tasks: mariadb.yml - name: Copy apache config copy: src=000-default.conf - dest=/etc/apache2/site-available/ + dest=/etc/apache2/sites-available/ owner=root group=root mode=655 +- name: Clone repository + git: repo=https://git.2li.ch/ibz/web_AI-5.git + dest="/vagrant" + force=yes + +- name: Set Permissions on the repository + file: + dest=/vagrant + owner=ansible group=ansible + recurse=yes + +- name: Install pip packages + pip: + name: + - django-extensions + - Pillow + executable: pip3 + +- name: Run the setup script to add some final touches + shell: "/vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh" + - name: Restart apache service service: name=apache2 state=restarted diff --git a/ansible/roles/web_AI-5/tasks/setup_script.sh b/ansible/roles/web_AI-5/tasks/setup_script.sh new file mode 100755 index 0000000..d9ed1c3 --- /dev/null +++ b/ansible/roles/web_AI-5/tasks/setup_script.sh @@ -0,0 +1,19 @@ +#initialize the db +mysql < /vagrant/sql/04_remove_database.sql +mysql < /vagrant/sql/01_create_database.sql + +#remove old migrations +rm /vagrant/django/didgeridoo/webshop/migrations/*.py + +#create and insert the new migrations +python3 /vagrant/django/didgeridoo/manage.py makemigrations webshop +python3 /vagrant/django/didgeridoo/manage.py migrate + +#insert some default data into the database +mysql < /vagrant/sql/02_insert_data.sql + +#create an admin user +echo "from django.contrib.auth.models import User; \ + User.objects.filter(email='admin@example.com').delete(); \ + User.objects.create_superuser('admin', 'admin@example.com', 'password')" | + python3 /vagrant/django/didgeridoo/manage.py shell diff --git a/ansible/roles/web_AI-5/vars/main.yml b/ansible/roles/web_AI-5/vars/main.yml index 0bd06f1..d4e69f1 100644 --- a/ansible/roles/web_AI-5/vars/main.yml +++ b/ansible/roles/web_AI-5/vars/main.yml @@ -4,6 +4,8 @@ apt_packages: - python3-django - libapache2-mod-wsgi-py3 - python3-mysqldb + - python3-pip + - git open_tcp_ports: - 80 diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index 9d51a5b..f741185 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -130,3 +130,10 @@ USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = '/vagrant/django/didgeridoo/static/' MEDIA_ROOT = '/vagrant/django/didgeridoo/media/' + + +ALLOWED_HOSTS = [ + 'localhost', + '127.0.0.1', + 'didgeridoo.ml' +] diff --git a/django/didgeridoo/webshop/admin.py b/django/didgeridoo/webshop/admin.py index 669166c..3ec97e8 100644 --- a/django/didgeridoo/webshop/admin.py +++ b/django/didgeridoo/webshop/admin.py @@ -3,8 +3,8 @@ from django.contrib.auth.admin import UserAdmin as BaseUserAdmin from django.contrib.auth.models import User # Register your models here. -from .models import (Article, Order, Person, City, Picture, OrderOfGoods, - Category, Option, Setting) +from .models import (Article, Order, OrderPosition, Person, City, Picture, + OrderOfGoods, Category, Option, Setting) class PersonInline(admin.StackedInline): @@ -17,11 +17,25 @@ class UserAdmin(BaseUserAdmin): inlines = (PersonInline,) +class OrderPositionInline(admin.StackedInline): + model = OrderPosition + can_delete = False + verbose_name_plural = 'Order Positions' + + +class OrderAdmin(admin.ModelAdmin): + list_display = ('id', 'user', 'date') + list_filter = ('date',) + date_hierarchy = 'date' + ordering = ('-date',) + inlines = (OrderPositionInline,) + + admin.site.unregister(User) admin.site.register(User, UserAdmin) admin.site.register(Article) -admin.site.register(Order) +admin.site.register(Order, OrderAdmin) admin.site.register(City) admin.site.register(Picture) admin.site.register(OrderOfGoods) diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index 62fbca5..c31c65b 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -4,6 +4,7 @@ from decimal import Decimal from django.core.validators import MinValueValidator from django.db import models from django.contrib.auth.models import User +import datetime class Option(models.Model): @@ -85,8 +86,19 @@ class Picture(models.Model): class Order(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) - article = models.ManyToManyField(Article) - order_status = models.ForeignKey(OrderStatus) + article = models.ManyToManyField(Article, through='OrderPosition') + status = models.ForeignKey(OrderStatus) + date = models.DateTimeField(default=datetime.datetime.now()) + + +class OrderPosition(models.Model): + article = models.ForeignKey(Article, on_delete=models.CASCADE) + order = models.ForeignKey(Order, on_delete=models.CASCADE) + amount = models.FloatField(max_length=5) + price_in_chf = models.DecimalField(max_digits=19, + decimal_places=2, + validators=[MinValueValidator( + Decimal('0.00'))]) class ShoppingCart(models.Model): @@ -107,6 +119,7 @@ class City(models.Model): class Meta: verbose_name_plural = "Cities" + ordering = ['zip_code'] class Salutation(models.Model):