diff --git a/.gitignore b/.gitignore index 084c0cf..97ee392 100644 --- a/.gitignore +++ b/.gitignore @@ -2,6 +2,7 @@ db.sqlite3 docs /static dev +/static_pile *.ttf *.woff diff --git a/sdbs_pile/pile/templates/front_base.html b/sdbs_pile/pile/templates/front_base.html index 4c36f3f..e160577 100644 --- a/sdbs_pile/pile/templates/front_base.html +++ b/sdbs_pile/pile/templates/front_base.html @@ -44,19 +44,21 @@ {% block content %}{% endblock %} -
- [login // maintain] -
+{% if not STATIC_PILE %} +
+ [login // maintain] +
+{% endif %} diff --git a/sdbs_pile/pile/views.py b/sdbs_pile/pile/views.py index 216d880..60dd4c4 100644 --- a/sdbs_pile/pile/views.py +++ b/sdbs_pile/pile/views.py @@ -17,6 +17,7 @@ from django.utils.text import slugify from django.views import View from django.views.generic import TemplateView +from sdbs_pile import settings from sdbs_pile.pile.models import Tag, Document, DocumentLink @@ -31,7 +32,8 @@ class BasePileView(TemplateView): 'tags': tags, 'document_count': Document.objects.count(), 'untagged_count': Document.objects.all().untagged().count(), - 'can_see_hidden': self.request.user.has_perm('pile.see_hidden') + 'can_see_hidden': settings.STATIC_PILE or self.request.user.has_perm('pile.see_hidden'), + 'STATIC_PILE': settings.STATIC_PILE } @@ -43,7 +45,8 @@ class IndexView(BasePileView): return { 'recent_documents': Document.objects.order_by('-uploaded')[:10], - 'random_document': choice(Document.objects.all()[5:]) if Document.objects.count() > 0 else None, + 'random_document': choice(Document.objects.all()[5:]) \ + if not settings.STATIC_PILE and Document.objects.count() > 0 else None, **base_context_data } @@ -128,7 +131,7 @@ class DocumentWithLabelView(View): except ObjectDoesNotExist: raise Http404 - if not self.request.user.has_perm('pile.see_hidden') and not document.public: + if not self.request.user.has_perm('pile.see_hidden') and not document.public and not settings.STATIC_PILE: raise PermissionDenied() if document.is_local_pdf: diff --git a/sdbs_pile/settings.py b/sdbs_pile/settings.py index 925c0e9..dc6fd22 100644 --- a/sdbs_pile/settings.py +++ b/sdbs_pile/settings.py @@ -28,6 +28,8 @@ else: DEBUG = False ALLOWED_HOSTS = ["pile.sdbs.cz"] +STATIC_PILE = bool(os.getenv("STATIC")) + # Application definition INSTALLED_APPS = [ diff --git a/sdbs_pile/urls.py b/sdbs_pile/urls.py index 7f17f21..e325540 100644 --- a/sdbs_pile/urls.py +++ b/sdbs_pile/urls.py @@ -13,10 +13,16 @@ Including another URLconf 1. Import the include() function: from django.urls import include, path 2. Add a URL to urlpatterns: path('blog/', include('blog.urls')) """ +from django.conf.urls.static import static from django.contrib import admin from django.urls import path, include +from sdbs_pile import settings + urlpatterns = [ path('', include('sdbs_pile.pile.urls')), path('admin/', admin.site.urls), ] + +if settings.STATIC_PILE: + urlpatterns += static("/docs/", document_root=settings.BASE_DIR + "/docs") \ No newline at end of file diff --git a/static_mirror.sh b/static_mirror.sh new file mode 100755 index 0000000..4b9514f --- /dev/null +++ b/static_mirror.sh @@ -0,0 +1,6 @@ +#!/bin/bash +set -e +rsync -vr --delete sdbs:/var/www/sdbs-pile/docs/ docs/ +rsync sdbs:/var/www/sdbs-pile/db.sqlite3 . +rm -rf static_pile +wget --mirror --convert-links --adjust-extension --page-requisites --no-parent --directory-prefix=static_pile http://localhost:4002