diff --git a/Vagrantfile b/Vagrantfile index a8fe782..cea707a 100644 --- a/Vagrantfile +++ b/Vagrantfile @@ -32,6 +32,15 @@ Vagrant.configure("2") do |config| libnss-mdns libapache2-mod-wsgi-py3 python3-mysqldb python3-pip pip3 install django-extensions Pillow pyaml + #Copy the apache configuration for django to the correct place + cp /vagrant/apache/000-default.conf /etc/apache2/sites-available/ + + mkdir -p /srv/media/images + chmod -R 777 /srv/media + + #restart the webserver + systemctl restart apache2.service + /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 4cab145..025855b 100644 --- a/ansible/roles/web_AI-5/tasks/main.yml +++ b/ansible/roles/web_AI-5/tasks/main.yml @@ -34,5 +34,13 @@ - name: Run the setup script to add some final touches shell: "/vagrant/ansible/roles/web_AI-5/tasks/setup_script.sh" +- name: Creates directory + file: + path: /srv/media + state: directory + owner: www-data + group: www-data + mode: 0755 + - name: Restart apache service service: name=apache2 state=restarted diff --git a/apache/000-default.conf b/apache/000-default.conf index bf85cc0..b9d347e 100644 --- a/apache/000-default.conf +++ b/apache/000-default.conf @@ -13,7 +13,7 @@ WSGIPythonPath /vagrant/django/didgeridoo/ ServerAdmin webmaster@localhost - Alias /media/ /vagrant/django/didgeridoo/media/ + Alias /media/ /srv/media/ Alias /static/ /vagrant/django/didgeridoo/static/ @@ -23,7 +23,7 @@ WSGIPythonPath /vagrant/django/didgeridoo/ - + Require all granted diff --git a/django/didgeridoo/didgeridoo/settings.py b/django/didgeridoo/didgeridoo/settings.py index 97a551d..09afaaa 100644 --- a/django/didgeridoo/didgeridoo/settings.py +++ b/django/didgeridoo/didgeridoo/settings.py @@ -68,6 +68,7 @@ TEMPLATES = [ 'django.template.context_processors.request', 'django.contrib.auth.context_processors.auth', 'django.contrib.messages.context_processors.messages', + 'django.template.context_processors.media' ], }, }, @@ -132,7 +133,9 @@ USE_TZ = True STATIC_URL = '/static/' STATIC_ROOT = '/vagrant/django/didgeridoo/static/' -MEDIA_ROOT = '/vagrant/django/didgeridoo/media/' + +MEDIA_URL = '/media/' +MEDIA_ROOT = '/srv/media/' LOGIN_REDIRECT_URL = '/' diff --git a/django/didgeridoo/didgeridoo/urls.py b/django/didgeridoo/didgeridoo/urls.py index 1eef47b..be44997 100644 --- a/django/didgeridoo/didgeridoo/urls.py +++ b/django/didgeridoo/didgeridoo/urls.py @@ -15,9 +15,11 @@ Including another URLconf """ from django.conf.urls import include, url from django.contrib import admin +from django.conf import settings +from django.conf.urls.static import static urlpatterns = [ url(r'', include('webshop.urls')), url(r'^admin/', admin.site.urls), url(r'^admin/', admin.site.urls), -] +] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) diff --git a/django/didgeridoo/media/images/.keep b/django/didgeridoo/media/images/.keep deleted file mode 100644 index e69de29..0000000 diff --git a/django/didgeridoo/webshop/templates/webshop/article_details.html b/django/didgeridoo/webshop/templates/webshop/article_details.html index e580fdc..3c1c3bb 100644 --- a/django/didgeridoo/webshop/templates/webshop/article_details.html +++ b/django/didgeridoo/webshop/templates/webshop/article_details.html @@ -6,4 +6,7 @@

Stock: {{ article.stock }}

Status: {{ article.status}}

Price: {{ article.price_in_chf }}

+ {% for picture in picture_list %} +

+ {% endfor %} {% endblock %} diff --git a/django/didgeridoo/webshop/views.py b/django/didgeridoo/webshop/views.py index 499c261..7d921a6 100644 --- a/django/didgeridoo/webshop/views.py +++ b/django/didgeridoo/webshop/views.py @@ -3,7 +3,12 @@ from django.shortcuts import get_object_or_404, render from django.contrib.auth.decorators import login_required from django.contrib.auth.models import User from django.contrib.auth.forms import UserCreationForm -from webshop.models import Article, Category, ArticleStatus, Person, City +from webshop.models import (Article, + Category, + ArticleStatus, + Person, + City, + Picture) from webshop.forms import RegistrationForm # Create your views here. @@ -36,8 +41,10 @@ def articles_in_category(request, category_id): 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}) + {'article': article, + 'picture_list': picture_list}) @login_required