Skip to content

Commit

Permalink
Adding possibility to export the site as static
Browse files Browse the repository at this point in the history
  • Loading branch information
Simon-Rey committed Apr 10, 2024
1 parent 8313a08 commit fa4915a
Show file tree
Hide file tree
Showing 4 changed files with 50 additions and 39 deletions.
2 changes: 2 additions & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,5 @@ local_settings.py
/cache/
.idea/
venv/

output/
1 change: 1 addition & 0 deletions preflib/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django_distill',
]

MIDDLEWARE = [
Expand Down
27 changes: 17 additions & 10 deletions preflibapp/urls.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,30 @@
from django.urls import path, re_path
from django.urls import re_path
from django_distill import distill_path, distill_re_path

from . import views
from .models import DataSet


def get_all_dataset_num():
for ds in DataSet.objects.all():
yield {'dataset_num': ds.series_number}


app_name = 'preflibapp'
urlpatterns = [
path('', views.main, name='main'),
re_path(r'^format/?$', views.data_format, name='data-format'),
distill_path('', views.main, name='main', distill_file='index.html'),
distill_re_path(r'^format/?$', views.data_format, name='data-format', distill_file="format.html"),

re_path(r'^datasets/?$', views.all_datasets, name='all-datasets'),
re_path(r'^dataset/(?P<dataset_num>[0-9]{5})/?$', views.dataset_view, name='dataset'),
distill_re_path(r'^datasets/?$', views.all_datasets, name='all-datasets', distill_file="datasets.html"),
distill_re_path(r'^dataset/(?P<dataset_num>[0-9]{5})/?$', views.dataset_view, name='dataset', distill_func=get_all_dataset_num),

re_path(r'^data/search/?$', views.data_search, name="data-search"),
distill_re_path(r'^data/search/?$', views.data_search, name="data-search"),

re_path(r'^BoSc22/?$', views.boehmer_schaar, name="boehmer-schaar"),
distill_re_path(r'^BoSc22/?$', views.boehmer_schaar, name="boehmer-schaar", distill_file="BoSc22.html"),

re_path(r'^tools/ivs/?$', views.tools_IVS, name='tools-IVS'),
re_path(r'^tools/kdg/?$', views.tools_KDG, name='tools-KDG'),
re_path(r'^tools/cris/?$', views.tools_CRIS, name='tools-CRIS'),
distill_re_path(r'^tools/ivs/?$', views.tools_IVS, name='tools-IVS', distill_file="tools/ivs.html"),
distill_re_path(r'^tools/kdg/?$', views.tools_KDG, name='tools-KDG', distill_file="tools/kdg.html"),
distill_re_path(r'^tools/cris/?$', views.tools_CRIS, name='tools-CRIS', distill_file="tools/cris.html"),

re_path(r'^login/?$', views.user_login, name='login'),
re_path(r'^logout/?$', views.user_logout, name='logout'),
Expand Down
59 changes: 30 additions & 29 deletions quicksetup.py
Original file line number Diff line number Diff line change
@@ -1,8 +1,9 @@
import os

## Write the settings.py file that we do not git for security reasons
with open("preflib/local_settings.py", "w") as f:
f.write("""
if __name__ == "__main__":
## Write the settings.py file that we do not git for security reasons
with open("preflib/local_settings.py", "w") as f:
f.write("""
import os
# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
Expand Down Expand Up @@ -35,29 +36,29 @@
# Path to the unix convert command for the image handling
CONVERT_PATH = 'convert'
""")
f.close()

## Create the migration folder and run the initial migration to set up the
## database (a simple SQLlite db here since it should be only use to play around).
try:
os.makedirs(os.path.join("preflibapp", "migrations"))
except:
pass
with open(os.path.join("preflibapp", "migrations", "__init__.py"), "w") as f:
f.write("")
f.close()

os.system("python3 manage.py makemigrations")
os.system("python3 manage.py migrate")

## Initialize the website
os.system("python3 manage.py initializedb")
os.system("python3 manage.py updatepapers")
os.system("python3 manage.py collectstatic")

## Set everything up to add data
try:
os.makedirs(os.path.join("preflibapp", "static", "datatoadd"))
except:
pass
""")
f.close()

## Create the migration folder and run the initial migration to set up the
## database (a simple SQLlite db here since it should be only use to play around).
try:
os.makedirs(os.path.join("preflibapp", "migrations"))
except:
pass
with open(os.path.join("preflibapp", "migrations", "__init__.py"), "w") as f:
f.write("")
f.close()

os.system("python3 manage.py makemigrations")
os.system("python3 manage.py migrate")

## Initialize the website
os.system("python3 manage.py initializedb")
os.system("python3 manage.py updatepapers")
os.system("python3 manage.py collectstatic")

## Set everything up to add data
try:
os.makedirs(os.path.join("preflibapp", "static", "datatoadd"))
except:
pass

0 comments on commit fa4915a

Please sign in to comment.