rudimentary version of an offline pile

This commit is contained in:
Tomáš Mládek 2020-07-30 01:00:27 +02:00
parent 7337a31192
commit 9d63e361b4
6 changed files with 28 additions and 8 deletions

1
.gitignore vendored
View file

@ -2,6 +2,7 @@ db.sqlite3
docs
/static
dev
/static_pile
*.ttf
*.woff

View file

@ -44,19 +44,21 @@
{% block content %}{% endblock %}
</div>
<div id="login">
<a href="/admin">[login // maintain]</a>
</div>
{% if not STATIC_PILE %}
<div id="login">
<a href="/admin">[login // maintain]</a>
</div>
{% endif %}
<script>
(function () {
window.counter = 'https://sdbs_pile.goatcounter.com/count'
window.counter = 'https://sdbs_pile.goatcounter.com/count';
var script = document.createElement('script');
script.async = 1;
script.src = '//gc.zgo.at/count.js';
var ins = document.getElementsByTagName('script')[0];
ins.parentNode.insertBefore(script, ins)
ins.parentNode.insertBefore(script, ins);
})();
</script>
</body>

View file

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

View file

@ -28,6 +28,8 @@ else:
DEBUG = False
ALLOWED_HOSTS = ["pile.sdbs.cz"]
STATIC_PILE = bool(os.getenv("STATIC"))
# Application definition
INSTALLED_APPS = [

View file

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

6
static_mirror.sh Executable file
View file

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