diff --git a/.gitignore b/.gitignore index d828399..fecb118 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,5 @@ local_settings.py /cache/ .idea/ venv/ + +output/ \ No newline at end of file diff --git a/preflib/settings.py b/preflib/settings.py index 14c7eab..d3901a0 100755 --- a/preflib/settings.py +++ b/preflib/settings.py @@ -30,6 +30,7 @@ 'django.contrib.sessions', 'django.contrib.messages', 'django.contrib.staticfiles', + 'django_distill', ] MIDDLEWARE = [ diff --git a/preflibapp/urls.py b/preflibapp/urls.py index 4768076..cb5b131 100644 --- a/preflibapp/urls.py +++ b/preflibapp/urls.py @@ -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[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[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'), diff --git a/quicksetup.py b/quicksetup.py index 359deea..25c12ff 100644 --- a/quicksetup.py +++ b/quicksetup.py @@ -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, ...) @@ -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