Merge branch 'master' into production

This commit is contained in:
Andreas Zweili 2017-12-31 15:23:59 +01:00
commit 9269e77e4a
8 changed files with 38 additions and 6 deletions

9
Vagrantfile vendored
View File

@ -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

View File

@ -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

View File

@ -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/
<Directory /vagrant/django/didgeridoo/didgeridoo>
@ -23,7 +23,7 @@ WSGIPythonPath /vagrant/django/didgeridoo/
</Directory>
<Directory /vagrant/django/didgeridoo/media>
<Directory /srv/media>
Require all granted
</Directory>

View File

@ -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 = '/'

View File

@ -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)

View File

@ -6,4 +6,7 @@
<p><b>Stock:</b> {{ article.stock }}</p>
<p><b>Status:</b> {{ article.status}}</p>
<p><b>Price:</b> {{ article.price_in_chf }}</p>
{% for picture in picture_list %}
<p><img src="{{ MEDIA_URL }}{{ picture.image }}" width="200" /></p>
{% endfor %}
{% endblock %}

View File

@ -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