Skip to content

Commit

Permalink
feat: implement dockerimage using sample data
Browse files Browse the repository at this point in the history
WIP: sample data should be pulled from git
WIP: put ontology into `apis_ontology
  • Loading branch information
b1rger committed May 27, 2024
1 parent 5ff57cd commit ce2b936
Show file tree
Hide file tree
Showing 5 changed files with 39 additions and 52 deletions.
9 changes: 9 additions & 0 deletions Dockerfile
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
FROM python:3.11

COPY . /app

RUN pip install /app

EXPOSE 8000

ENTRYPOINT ["/app/sample_project/entrypoint.sh"]
53 changes: 8 additions & 45 deletions manage.py
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys

if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "apis.settings.settings_test_ci")

def main():
"""Run administrative tasks."""
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "sample_project.settings")
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
Expand All @@ -12,48 +15,8 @@
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)

# TODO : Check at some time if the bug in dal_select2 has been fixed, and if so, remove this function here
def work_around_dal_select2_bug():
"""
Due to a bug in dal_select2, this workaround function here goes into the offending file and replaces the
relevant code segment with a work-around segment.
This function ensures that this replacement is done each time django is run and also modifies only the file
which is loaded via the respective library within the virtual environment of the current python interpreter.
"""

import dal_select2

file_to_fix = dal_select2.__file__.replace(
"/__init__.py", "/static/autocomplete_light/select2.js"
)

try:
with open(file_to_fix, "r") as f:
lines = f.readlines()

for i, line in enumerate(lines):
if (
line == " processResults: function (data, page) {\n"
and lines[i + 1]
== " if (element.attr('data-tags')) {\n"
and lines[i + 2]
== " $.each(data.results, function(index, value) {\n"
and lines[i + 3]
== " value.id = value.text;\n"
):
lines[i + 3] = " value.id = value.id;\n"

with open(file_to_fix, "w") as f:
f.write("".join(lines))

except FileNotFoundError:
raise Exception(
"Could not find select2.js file to inject bug workaround into.\n"
+ "Maybe the dal_select library has changed and this workaround is not necessary anymore?"
)

work_around_dal_select2_bug()

execute_from_command_line(sys.argv)
if __name__ == "__main__":
main()
6 changes: 6 additions & 0 deletions sample_project/entrypoint.sh
Original file line number Diff line number Diff line change
@@ -0,0 +1,6 @@
#!/bin/sh

./manage.py migrate
./manage.py loaddata sample_project
./manage.py loaddata auth
./manage.py runserver
11 changes: 11 additions & 0 deletions sample_project/fixtures/auth.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
[
{ "model": "auth.user",
"pk": 1,
"fields": {
"username": "user1",
"password": "pbkdf2_sha256$600000$tJ0VACk6Oa84oNYiGVk0Ue$yH7UIR2dE6UsRnoJQVrNUumgSR465lwJXSOnGFuiIBw=",
"is_staff": true,
"is_superuser": true
}
}
]
12 changes: 5 additions & 7 deletions sample_project/settings.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
SECRET_KEY = "a+nkut46lzzg_=ul)zrs29$u_6^*)2by2mjmwn)tqlgw)_at&l"
import os
from django.core.management.utils import get_random_secret_key

SECRET_KEY = os.environ.get("SECRET_KEY", get_random_secret_key())
DEBUG = True

ALLOWED_HOSTS = []
Expand Down Expand Up @@ -28,10 +31,9 @@
"dal_select2",
# api
"rest_framework",
"rest_framework.authtoken",
# for swagger ui generation
"drf_spectacular",
"simple_history",
# our ontology
"sample_project",
]

Expand All @@ -43,8 +45,6 @@
"django.contrib.auth.middleware.AuthenticationMiddleware",
"django.contrib.messages.middleware.MessageMiddleware",
"django.middleware.clickjacking.XFrameOptionsMiddleware",
"allow_cidr.middleware.AllowCIDRMiddleware",
"reversion.middleware.RevisionMiddleware",
]

ROOT_URLCONF = "apis_core.urls"
Expand All @@ -60,8 +60,6 @@
"django.template.context_processors.request",
"django.contrib.auth.context_processors.auth",
"django.contrib.messages.context_processors.messages",
# we need this for accessing `basetemplate`
"apis_core.context_processors.custom_context_processors.list_apis_settings",
],
},
},
Expand Down

0 comments on commit ce2b936

Please sign in to comment.