widelands-dev team mailing list archive
-
widelands-dev team
-
Mailing list archive
-
Message #15466
[Merge] lp:~widelands-dev/widelands-website/django_staticfiles into lp:widelands-website
The proposal to merge lp:~widelands-dev/widelands-website/django_staticfiles into lp:widelands-website has been updated.
Description changed to:
The problem i had when introducing django-star-ratings (https://wl.widelands.org/forum/topic/4389/) was a result of not implementing django's default behavior for static files (css, js, images), which was introduced many versions ago. Modern third party django-apps rely on this default behavior, and this is what had bitten me this time. On the server i have fixed this by configuring local_settings.py. This branch reflects the changes i did on the server, and some other related stuff. As a sideeffect, this solves also this bug :-)
Main concepts of new static files handling:
1. Setting STATIC_ROOT to an absolute path where static files will be collected using the management command 'collectstatic'. This command needs executed if settings.DEBUG=False. 'collectstatic' searches all apps which are in INSTALLED_APPS for a folder called 'static' and copies, or symlink, all of it's content into STATIC_ROOT. https://docs.djangoproject.com/en/1.11/ref/contrib/staticfiles/#collectstatic
2. Different urls for static files and user uploaded files.
3. Use of the 'static' template tag in the templates to refer to static content (this is the main reason why this diff is that big)
Differences to the current state on the server:
1. Using the collectstatic command from this branch collects static files in 'media/static_collected/' (on the server i used 'media/static_foreign', which was a bad name).
Unchanged:
Files uploaded by a user where still uploaded to 'media/[wlmaps|wlprofile|wlimages]'. The name of the link stays unchanged, so 'wlmedia/*'.
Other things:
1. Moved own static files from 'media/' to 'mainpage/static/' or to the app (folder) where it belongs to. I am planning to do the same with the subfolders in 'templates/*' to have all things related to one app in one folder. So working e.g. on some things in pybb, pybb related css is found in 'pybb/static/css/' and templates will be in 'pybb/templates/pybb/*.html'
2. I found also 2 issues if one wants to setup the website from scratch. Those are fixed in https://bazaar.launchpad.net/~widelands-dev/widelands-website/django_staticfiles/revision/514
To get this in:
1. Set website maintenance
2. Remove the contents of 'media/static_foreign' to avoid merge conflicts
3. merge the branch
4. Remove setting of STATIC_ROOT or set it to the destination where you want to collect static files. Exchange variable 'bd' with USER_MEDIA_BASE_PATH. Remove the lines containing STATIC_MEDIA_PATH (this were useless at all, because prior only used in local_urls.py)
5. run 'python manage.py collectstatic -l' (the switch '-l' creates symlinks instead of copying the files)
6. Change the url which refers to static content to point to the folder of STATIC_ROOT
7. pybb posts containing a smiley needs resaving to exchange the url pointing to the new smiley directory for field 'body_html'. This can be done best in the management shell:
from pybb.models import Post
for post in Post.objects.filter(body_html__contains='/wlmedia/img/smileys/'):
post.save()
This takes some time...
8. Unset website maintenance
I will setup the alpha site for testing.
For more details, see:
https://code.launchpad.net/~widelands-dev/widelands-website/django_staticfiles/+merge/359345
--
Your team Widelands Developers is subscribed to branch lp:widelands-website.
References