From cea32523223c07f6bc264ffc338de1fd29005f6f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Wed, 27 Dec 2017 19:32:14 +0100 Subject: [PATCH 1/8] add bootstrap to ansible and vagrant for django-bootstrap3 support --- Vagrantfile | 2 +- ansible/roles/web_AI-5/tasks/main.yml | 1 + django/didgeridoo/didgeridoo/settings.py | 1 + 3 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Vagrantfile b/Vagrantfile index 7e8c3d7..1ee8bbe 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -30,7 +30,7 @@ Vagrant.configure("2") do |config| #zu installierende Pakete apt-get install -y apache2 python3-django mariadb-server avahi-daemon \ libnss-mdns libapache2-mod-wsgi-py3 python3-mysqldb python3-pip - pip3 install django-extensions Pillow + pip3 install django-extensions Pillow django-bootstrap3 /vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh SHELL diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index e956179..2e067d1 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -27,6 +27,7 @@ name: - django-extensions - Pillow + - django-bootstrap3 executable: pip3 - name: Run the setup script to add some final touches diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index 155ca3d..dbe98ed 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -39,6 +39,7 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'bootstrap3' ] MIDDLEWARE = [ From 45ca9ca55e693653c6d9e118774a16b2a5a5dc23 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Fri, 29 Dec 2017 15:11:45 +0100 Subject: [PATCH 2/8] unfinshed atempt to make a nav abandoned for later use maybe --- .../webshop/templates/webshop/base.html | 73 +++++++++++++++---- 1 file changed, 59 insertions(+), 14 deletions(-) diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index fa6b702..8cd2aa6 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -1,17 +1,62 @@ - - - - -
-

{% block section_title %}Music Instrument Shop{% endblock %}

- {% block content %}{% endblock %} -
- -
- {% block footer %} -

This is a case study project of Ivan Hörler and Andreas Zweili. - It is a school project/excercise and has no commercial intent.

+ + + + + + + + + {% load static %} + + {% block title %} + + Casestudy 'Webshop' IBZ TIAE-5(2017/18) + {% endblock %} -
+ + +
+
+
+

+ {% block shop_name %}Music Instruments Inc.{% endblock %} +

+
+
+
+
+
+
+ {% block nav %} + + {% endblock %} +
+
+

+ {% block section_title %}{% endblock %} +

+
+
+ {% block content %}{% endblock %} +
+
+
+
+
+
+
+ {% block footer %} + This is a case study project of Ivan Hörler and Andreas Zweili.
+ It is a school project/excercise and has no commercial intent. + {% endblock %} +
+
+
+
+ From 7bb875e6965a44c2ee5a4351ff18ca843df35565 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Fri, 29 Dec 2017 15:12:29 +0100 Subject: [PATCH 3/8] selfmade css file --- django/didgeridoo/static/webshop/css/base.css | 6 ++++++ django/didgeridoo/webshop/templates/webshop/index.html | 1 + 2 files changed, 7 insertions(+) create mode 100755 django/didgeridoo/static/webshop/css/base.css diff --git a/django/didgeridoo/static/webshop/css/base.css b/django/didgeridoo/static/webshop/css/base.css new file mode 100755 index 0000000..6e68a39 --- /dev/null +++ b/django/didgeridoo/static/webshop/css/base.css @@ -0,0 +1,6 @@ + +.sidebar-nav { + margin-top: 30px; + padding: 10; + list-style: none; +} diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index 651ea42..8ddc755 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,4 +1,5 @@ {% extends "webshop/base.html" %} +{% block section_title %}Home{% endblock %} {% block content %} {% if category_list %}
    From d500712dc2635417cfd806c29b669b6131a28eb8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Ivan=20Ho=CC=88rler?= Date: Fri, 29 Dec 2017 22:32:27 +0100 Subject: [PATCH 4/8] changed some of the views and implemented a more selfish perspective of a shop. For shure not ideal and in NO way DRY but a solution for now. --- django/didgeridoo/didgeridoo/settings.py | 2 +- .../webshop/templates/webshop/base.html | 51 +++++++++++++------ .../webshop/templates/webshop/category.html | 36 +++++++++---- .../webshop/templates/webshop/index.html | 44 ++++++++++------ django/didgeridoo/webshop/views.py | 28 ++++++++-- 5 files changed, 117 insertions(+), 44 deletions(-) diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index 67fac21..ac6bd08 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -23,7 +23,7 @@ BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) SECRET_KEY = '(#4#-$$&mx7(%q+6&&@-c&g%i0dc4)zfks1%sy8b%lsxspou&%' # SECURITY WARNING: don't run with debug turned on in production! -DEBUG = False +DEBUG = True ALLOWED_HOSTS = [ 'localhost', diff --git a/django/didgeridoo/webshop/templates/webshop/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index c1d1e54..bb41953 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -16,34 +16,55 @@ {% endblock %} -
    - Home | - {% if user.is_authenticated %} - Profile | Logout - {% else %} - Login - {% endif %} -

    {% block section_title %}Music Instrument Shop{% endblock %}

    - {% block content %}{% endblock %} -

    {% block shop_name %}Music Instruments Inc.{% endblock %}

    +
    + {% block search %}{% endblock %} +
    +
    - {% block nav %} -
    diff --git a/django/didgeridoo/webshop/templates/webshop/category.html b/django/didgeridoo/webshop/templates/webshop/category.html index 373f03f..bb6a535 100644 --- a/django/didgeridoo/webshop/templates/webshop/category.html +++ b/django/didgeridoo/webshop/templates/webshop/category.html @@ -1,13 +1,31 @@ {% extends "webshop/base.html" %} {% block section_title %}Category Overview{% endblock %} {% block content %} - {% if article_list %} - - {% else %} -

    There are no articles in this category.

    - {% endif %} + {% if article_list %} + + + + + + + + + {% for article in article_list %} + + + + + + + + {% endfor %} +
    IDNAMECATHEGORYSTOCKPRICE
    {{ article.id }} + + {{ article.name }} + {{ article.category }}{{ article.stock }}{{ article.price_in_chf }}
    + {% else %} +

    + Something whent wrong, no articles are stored. +

    + {% endif %} {% endblock %} diff --git a/django/didgeridoo/webshop/templates/webshop/index.html b/django/didgeridoo/webshop/templates/webshop/index.html index 8ddc755..7f661bd 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,18 +1,32 @@ {% extends "webshop/base.html" %} -{% block section_title %}Home{% endblock %} +{% block section_title %}Articles{% endblock %} {% block content %} - {% if category_list %} -
      - {% for category, sub_category in category_list.items %} -
    • {{ category.name }}
    • - {% for i in sub_category %} - - {% endfor %} - {% endfor %} -
    - {% else %} -

    No categories are available.

    - {% endif %} + {% if articles_list %} + + + + + + + + + {% for article in articles_list %} + + + + + + + + {% endfor %} +
    IDNAMECATHEGORYSTOCKPRICE
    {{ article.id }} + + {{ article.name }} + + {{ article.category }}{{ article.stock }}{{ article.price_in_chf }}
    + {% else %} +

    + Something whent wrong, no articles are stored. +

    + {% endif %} {% endblock %} diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 499c261..db2462e 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -12,6 +12,8 @@ from webshop.forms import RegistrationForm def index(request): parent_category_list = Category.objects.filter(parent_category=None) category_list = {} + hidden = ArticleStatus.objects.get(name="hidden") + articles_list = Article.objects.all().exclude(status=hidden.id) for i in parent_category_list: category_list.update( @@ -19,7 +21,8 @@ def index(request): return render(request, 'webshop/index.html', - {'category_list': category_list}) + {'category_list': category_list, + 'articles_list': articles_list}) def articles_in_category(request, category_id): @@ -29,16 +32,33 @@ def articles_in_category(request, category_id): article_list = Article.objects.filter( category=selected_category.id).exclude(status=hidden.id) + parent_category_list = Category.objects.filter(parent_category=None) + category_list = {} + + for i in parent_category_list: + category_list.update( + {i: Category.objects.filter(parent_category=i.id)}) + return render(request, 'webshop/category.html', {'article_list': article_list, + 'category_list': category_list, 'category': selected_category}) def article_details(request, article_id): - article = get_object_or_404(Article, pk=article_id) - return render(request, 'webshop/article_details.html', - {'article': article}) + parent_category_list = Category.objects.filter(parent_category=None) + category_list = {} + + for i in parent_category_list: + category_list.update( + {i: Category.objects.filter(parent_category=i.id)}) + + article = get_object_or_404(Article, pk=article_id) + + return render(request, 'webshop/article_details.html', + {'article': article, + 'category_list': category_list}) @login_required def profile(request): From 95ec91fbf035bd8a7a369eee72b32fc8fc80a789 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 13 Jan 2018 09:34:01 +0100 Subject: [PATCH 5/8] remove a duplicate entry --- django/didgeridoo/didgeridoo/settings.py | 1 - 1 file changed, 1 deletion(-) diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index e019849..3e84361 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -35,7 +35,6 @@ ALLOWED_HOSTS = [ # Application definition INSTALLED_APPS = [ - 'currencies', 'webshop.apps.WebshopConfig', 'django_extensions', 'django.contrib.admin', From 012e4ff148fec379f37811a5b86b5713ae2da0d8 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 13 Jan 2018 09:36:25 +0100 Subject: [PATCH 6/8] add migrations to the ignore list --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d9a0721..47c224d 100644 --- a/.gitignore +++ b/.gitignore @@ -267,3 +267,4 @@ fabric.properties # End of https://www.gitignore.io/api/pycharm /django/.idea/workspace.xml /docs/main.listing +/django/didgeridoo/currencies/migrations/*.py From 0a8e74110f01c4b0a6e09100d7ac35b7ed1a172c Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 13 Jan 2018 09:37:38 +0100 Subject: [PATCH 7/8] add a cronjob to trigger the currency updates --- Vagrantfile | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/Vagrantfile b/Vagrantfile index 42bf2e5..1c9461d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -43,6 +43,10 @@ Vagrant.configure("2") do |config| systemctl restart apache2.service /vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh + + #insert the currency update cronjob + echo "wget -O /dev/null http://localhost:8080" > /etc/cron.hourly/currency_update + chmod +x /etc/cron.hourly/currency_update SHELL end From 0048475a2d63a08805050d767834606e6547eab9 Mon Sep 17 00:00:00 2001 From: Andreas Zweili Date: Sat, 13 Jan 2018 10:46:49 +0100 Subject: [PATCH 8/8] remove a migration file --- .../currencies/migrations/0001_initial.py | 48 ------------------- 1 file changed, 48 deletions(-) delete mode 100644 django/didgeridoo/currencies/migrations/0001_initial.py diff --git a/django/didgeridoo/currencies/migrations/0001_initial.py b/django/didgeridoo/currencies/migrations/0001_initial.py deleted file mode 100644 index ee9f2f4..0000000 --- a/django/didgeridoo/currencies/migrations/0001_initial.py +++ /dev/null @@ -1,48 +0,0 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.7 on 2018-01-09 18:21 -from __future__ import unicode_literals - -from django.db import migrations, models -import django.db.models.deletion - - -class Migration(migrations.Migration): - - initial = True - - dependencies = [ - ] - - operations = [ - migrations.CreateModel( - name='ExchangeRate', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('exchange_rate_to_chf', models.DecimalField(decimal_places=5, max_digits=12)), - ], - ), - migrations.CreateModel( - name='ExchangeRate_date', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('date', models.DateField(unique_for_date=True, verbose_name='%Y-%m-%d')), - ], - ), - migrations.CreateModel( - name='ExchangeRate_name', - fields=[ - ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), - ('name', models.CharField(max_length=200, unique=True)), - ], - ), - migrations.AddField( - model_name='exchangerate', - name='date', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='currencies.ExchangeRate_date'), - ), - migrations.AddField( - model_name='exchangerate', - name='name', - field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='currencies.ExchangeRate_name'), - ), - ]