From d77896a9f4e65d801f10cd925285a6eee956ce2e Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 2 Feb 2022 09:53:09 +0900 Subject: [PATCH 1/3] Remove unnecessary print --- backend/data_import/pipeline/builders.py | 1 - 1 file changed, 1 deletion(-) diff --git a/backend/data_import/pipeline/builders.py b/backend/data_import/pipeline/builders.py index 3449acc9..f60555c5 100644 --- a/backend/data_import/pipeline/builders.py +++ b/backend/data_import/pipeline/builders.py @@ -16,7 +16,6 @@ T = TypeVar('T') class PlainBuilder(Builder): def __init__(self, data_class: Type[BaseData]): - print(data_class) self.data_class = data_class def build(self, row: Dict[Any, Any], filename: str, line_num: int) -> Record: From 18daace617ae78f0d933e232e20e5339803f9e63 Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 2 Feb 2022 10:04:08 +0900 Subject: [PATCH 2/3] Enable to show images and audios in the case of pip and Docker --- Dockerfile | 1 + backend/app/urls.py | 17 +++++++++++++---- backend/cli.py | 1 + 3 files changed, 15 insertions(+), 4 deletions(-) diff --git a/Dockerfile b/Dockerfile index a3dd4a37..5cf8638f 100644 --- a/Dockerfile +++ b/Dockerfile @@ -58,6 +58,7 @@ VOLUME /data ENV DATABASE_URL="sqlite:////data/doccano.db" ENV DEBUG="False" +ENV STANDALONE="True" ENV SECRET_KEY="change-me-in-production" ENV PORT="8000" ENV WORKERS="2" diff --git a/backend/app/urls.py b/backend/app/urls.py index 828098c5..87701384 100644 --- a/backend/app/urls.py +++ b/backend/app/urls.py @@ -13,15 +13,17 @@ 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')) """ +import os +import re + from django.conf import settings -from django.conf.urls.static import static from django.contrib import admin from django.contrib.auth.views import TemplateView from django.urls import include, path, re_path +from django.views.static import serve from drf_yasg import openapi from drf_yasg.views import get_schema_view -# TODO: adds AnnotationList and AnnotationDetail endpoint. schema_view = get_schema_view( openapi.Info( title="doccano API", @@ -33,8 +35,15 @@ schema_view = get_schema_view( ) urlpatterns = [] -if settings.DEBUG: - urlpatterns += static(settings.MEDIA_URL, document_root=settings.MEDIA_ROOT) +if settings.DEBUG or os.environ.get('STANDALONE', False): + # For showing images and audios in the case of pip and Docker. + urlpatterns.append( + re_path( + r'^%s(?P.*)$' % re.escape(settings.MEDIA_URL.lstrip('/')), + serve, + {'document_root': settings.MEDIA_ROOT} + ) + ) urlpatterns += [ path('admin/', admin.site.urls), diff --git a/backend/cli.py b/backend/cli.py index 48fa0eca..ed8d2f3c 100644 --- a/backend/cli.py +++ b/backend/cli.py @@ -7,6 +7,7 @@ import sys from .app.celery import app os.environ['DEBUG'] = 'False' +os.environ['STANDALONE'] = 'True' base = os.path.abspath(os.path.dirname(__file__)) sys.path.append(base) manage_path = os.path.join(base, 'manage.py') From e2d0b1d8e3807f4ccfbaea6afbf0304d55a5fbeb Mon Sep 17 00:00:00 2001 From: Hironsan Date: Wed, 2 Feb 2022 10:04:25 +0900 Subject: [PATCH 3/3] Add django-health-check as a dependency --- setup.py | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/setup.py b/setup.py index 92b0a28d..17fe374e 100644 --- a/setup.py +++ b/setup.py @@ -44,7 +44,8 @@ required = [ 'gunicorn>=20.1.0', 'waitress>=2.0.0', 'pydantic>=1.8.2', - 'chardet>=4.0.0' + 'chardet>=4.0.0', + 'django-health-check' ] setup(