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 diff --git a/Vagrantfile b/Vagrantfile index cea707a..1c9461d 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -30,7 +30,8 @@ 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 pyaml + pip3 install django-extensions Pillow pyaml django-bootstrap3 + #Copy the apache configuration for django to the correct place cp /vagrant/apache/000-default.conf /etc/apache2/sites-available/ @@ -42,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 diff --git a/ansible/roles/web_AI-5/tasks/main.yml b/ansible/roles/web_AI-5/tasks/main.yml index 025855b..5daf02b 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -29,6 +29,7 @@ - django-extensions - Pillow - pyaml + - django-bootstrap3 executable: pip3 - name: Run the setup script to add some final touches 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'), - ), - ] diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index 71b26b2..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', @@ -44,6 +43,8 @@ INSTALLED_APPS = [ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'currencies', + 'bootstrap3', ] MIDDLEWARE = [ 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/base.html b/django/didgeridoo/webshop/templates/webshop/base.html index cf6c6e2..bb41953 100644 --- a/django/didgeridoo/webshop/templates/webshop/base.html +++ b/django/didgeridoo/webshop/templates/webshop/base.html @@ -1,23 +1,93 @@ - - - - -
- 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 sidebar %} + {% 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 %} + {% endblock %} +
+
+

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

+
+
+ {% block content %}{% endblock %} +
+
+
+ + 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 651ea42..7f661bd 100644 --- a/django/didgeridoo/webshop/templates/webshop/index.html +++ b/django/didgeridoo/webshop/templates/webshop/index.html @@ -1,17 +1,32 @@ {% extends "webshop/base.html" %} +{% block section_title %}Articles{% endblock %} {% block content %} - {% if category_list %} - - {% 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 7d921a6..cce4b63 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -17,6 +17,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( @@ -24,7 +26,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): @@ -34,18 +37,32 @@ 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) - picture_list = Picture.objects.filter(article=article_id) - return render(request, 'webshop/article_details.html', - {'article': article, - 'picture_list': picture_list}) + 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):