From 7b3ecdf5f549a20916cc48986e0ff43713df63d4 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Wed, 20 Dec 2017 19:48:12 +0100 Subject: [PATCH 01/16] update readme with more up to date information --- README.md | 7 ++++++- 1 file changed, 6 insertions(+), 1 deletion(-) 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 From 991fbfc6f5399a25850271bece24db1b1f070f74 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Wed, 20 Dec 2017 19:51:49 +0100 Subject: [PATCH 02/16] sort city outputs by zip code --- django/didgeridoo/webshop/models.py | 1 + 1 file changed, 1 insertion(+) diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index 185abd4..484a5a3 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -115,6 +115,7 @@ class City(models.Model): class Meta: verbose_name_plural = "Cities" + ordering = ['zip_code'] class Salutation(models.Model): From 3dc9aa33bb736963aa4b4378c445fbcb2b0f3e51 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Thu, 21 Dec 2017 23:05:10 +0100 Subject: [PATCH 03/16] add a date field to the orders class In order to be able to identify the correct customer order it's necessary to have the date of the order available. --- django/didgeridoo/webshop/models.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index 484a5a3..6c87815 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): @@ -95,6 +96,7 @@ class Order(models.Model): user = models.ForeignKey(User, on_delete=models.CASCADE) article = models.ManyToManyField(Article) order_status = models.ForeignKey(OrderStatus) + date = models.DateTimeField(default=datetime.datetime.now()) class ShoppingCart(models.Model): From f4aa223135d9e7b9805af915d37a58c5476f077f Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Thu, 21 Dec 2017 23:06:09 +0100 Subject: [PATCH 04/16] add an intermediate class between order and article Because we need additional fields in an order it's necessary to add an additional class where the information gets stored. --- django/didgeridoo/webshop/models.py | 14 ++++++++++++-- 1 file changed, 12 insertions(+), 2 deletions(-) diff --git a/django/didgeridoo/webshop/models.py b/django/didgeridoo/webshop/models.py index 6c87815..b2bfa91 100644 --- a/django/didgeridoo/webshop/models.py +++ b/django/didgeridoo/webshop/models.py @@ -94,11 +94,21 @@ 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): name = models.CharField(max_length=200) user = models.ForeignKey(User, on_delete=models.CASCADE) From 0ef5cdff800ea57048e51799daf884c738c053dd Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Thu, 21 Dec 2017 23:07:58 +0100 Subject: [PATCH 05/16] extend the admin interface for the order class In order to be able to correctly edit the an order we need the information of the induvidual order positions. In addition a better layout is required to better find the information. --- django/didgeridoo/webshop/admin.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) 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) From 49ac7f71a3de35c4ad9bf450397dc125397fc080 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:31:47 +0100 Subject: [PATCH 06/16] change ansible includes to import_tasks --- ansible/roles/common/tasks/main.yml | 8 ++++---- ansible/roles/web_AI-5/tasks/main.yml | 6 +++--- 2 files changed, 7 insertions(+), 7 deletions(-) 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..52c8c01 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -1,8 +1,8 @@ --- -- 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 From 054909b145ecce6606ce2c9c37dc8385c2710e46 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:32:07 +0100 Subject: [PATCH 07/16] add a list of allowed hosts to the django settings --- django/didgeridoo/didgeridoo/settings.py | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index 682b4be..155ca3d 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -129,3 +129,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' +] From ee449c4176860c4f0b990ddadcda50305e28593f Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:32:24 +0100 Subject: [PATCH 08/16] add missing packages to the ansible role --- ansible/roles/web_AI-5/vars/main.yml | 2 ++ 1 file changed, 2 insertions(+) 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 From ba2776336e9088ad4f4673199a48049316ef0657 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:32:37 +0100 Subject: [PATCH 09/16] fix a typo in the ansbible role --- ansible/roles/web_AI-5/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index 52c8c01..be8054d 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -6,7 +6,7 @@ - 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 From 6fdad5704fff5c61d33d85d5a5e789ec743f1bda Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:33:01 +0100 Subject: [PATCH 10/16] add the repository to the ansible role --- ansible/roles/web_AI-5/tasks/main.yml | 11 +++++++++++ 1 file changed, 11 insertions(+) diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index be8054d..d6425a2 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -11,5 +11,16 @@ 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: Restart apache service service: name=apache2 state=restarted From 058dc79beff03c7b7163bd45ca6ddd3afb360c3b Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:33:17 +0100 Subject: [PATCH 11/16] add a pip install routine to the ansible role --- ansible/roles/web_AI-5/tasks/main.yml | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index d6425a2..03d2562 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -22,5 +22,12 @@ owner=ansible group=ansible recurse=yes +- name: Install pip packages + pip: + name: + - django-extensions + - Pillow + executable: pip3 + - name: Restart apache service service: name=apache2 state=restarted From 78eeb91f0380c2ea369dc9580cd450d848b010e1 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:34:38 +0100 Subject: [PATCH 12/16] add a setup script to the ansible role --- ansible/roles/web_AI-5/tasks/main.yml | 3 +++ ansible/roles/web_AI-5/tasks/setup_script.sh | 6 ++++++ 2 files changed, 9 insertions(+) create mode 100644 ansible/roles/web_AI-5/tasks/setup_script.sh diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index 03d2562..a75ecf0 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -29,5 +29,8 @@ - Pillow executable: pip3 +- name: Run the setup script to add some final touches + shell: "/vagrant/ansible/roles/web_AI-5/tasks/setup_scripts.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 100644 index 0000000..a8682d8 --- /dev/null +++ b/ansible/roles/web_AI-5/tasks/setup_script.sh @@ -0,0 +1,6 @@ +mysql < /vagrant/sql/04_remove_database.sql +mysql < /vagrant/sql/01_create_database.sql +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 From 05cb259a304b75813d3fff722de7947e872b0cbd Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:39:26 +0100 Subject: [PATCH 13/16] fix a typo --- ansible/roles/web_AI-5/tasks/main.yml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index a75ecf0..e956179 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -30,7 +30,7 @@ executable: pip3 - name: Run the setup script to add some final touches - shell: "/vagrant/ansible/roles/web_AI-5/tasks/setup_scripts.sh" + shell: "/vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh" - name: Restart apache service service: name=apache2 state=restarted From 630d46fb4dcaca412de838b9db2e443dae8c4fe4 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:39:34 +0100 Subject: [PATCH 14/16] make the setup script executable --- ansible/roles/web_AI-5/tasks/setup_script.sh | 0 1 file changed, 0 insertions(+), 0 deletions(-) mode change 100644 => 100755 ansible/roles/web_AI-5/tasks/setup_script.sh diff --git a/ansible/roles/web_AI-5/tasks/setup_script.sh b/ansible/roles/web_AI-5/tasks/setup_script.sh old mode 100644 new mode 100755 From 16a854012deed327637efb0487dd0cdd9447cc67 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:47:04 +0100 Subject: [PATCH 15/16] move some parts from the vagrant file into a separate script This way both vagrant and ansible can use the script --- Vagrantfile | 24 +------------------- ansible/roles/web_AI-5/tasks/setup_script.sh | 13 +++++++++++ 2 files changed, 14 insertions(+), 23 deletions(-) diff --git a/Vagrantfile b/Vagrantfile index b7f26bb..a905239 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/web_AI-5/tasks/setup_script.sh b/ansible/roles/web_AI-5/tasks/setup_script.sh index a8682d8..d9ed1c3 100755 --- a/ansible/roles/web_AI-5/tasks/setup_script.sh +++ b/ansible/roles/web_AI-5/tasks/setup_script.sh @@ -1,6 +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 From 2b8f41725c92bc92a1fb6715dc6f02dac75f0e90 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Mon, 25 Dec 2017 22:50:42 +0100 Subject: [PATCH 16/16] fix a typo --- Vagrantfile | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index a905239..7e8c3d7 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -32,7 +32,7 @@ Vagrant.configure("2") do |config| libnss-mdns libapache2-mod-wsgi-py3 python3-mysqldb python3-pip pip3 install django-extensions Pillow - ./vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh + /vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh SHELL end