Merge remote-tracking branch 'origin/master' into currency
* origin/master: remove the old media directory create the path /srv/media/images in the Vagrant vm create the media directory on the production server add pictures to the article details page move the media root and add support for MEDIA_URL readd two commands
This commit is contained in:
commit
4f51e17504
|
@ -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
|
||||
|
||||
|
|
|
@ -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
|
||||
|
|
|
@ -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>
|
||||
|
||||
|
|
|
@ -69,6 +69,7 @@ TEMPLATES = [
|
|||
'django.template.context_processors.request',
|
||||
'django.contrib.auth.context_processors.auth',
|
||||
'django.contrib.messages.context_processors.messages',
|
||||
'django.template.context_processors.media'
|
||||
],
|
||||
},
|
||||
},
|
||||
|
@ -133,6 +134,8 @@ 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 = '/'
|
||||
|
|
|
@ -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'', include('currencies.urls')),
|
||||
url(r'^admin/', admin.site.urls),
|
||||
]
|
||||
] + static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT)
|
||||
|
|
|
@ -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 %}
|
||||
|
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue