Browse Source

Merge pull request #1667 from doccano/fix/1611

Enable to show images and audios in the case of pip and Docker
pull/1670/head
Hiroki Nakayama 2 years ago
committed by GitHub
parent
commit
61a8569ce1
No known key found for this signature in database GPG Key ID: 4AEE18F83AFDEB23
5 changed files with 17 additions and 6 deletions
  1. 1
      Dockerfile
  2. 17
      backend/app/urls.py
  3. 1
      backend/cli.py
  4. 1
      backend/data_import/pipeline/builders.py
  5. 3
      setup.py

1
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"

17
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<path>.*)$' % re.escape(settings.MEDIA_URL.lstrip('/')),
serve,
{'document_root': settings.MEDIA_ROOT}
)
)
urlpatterns += [
path('admin/', admin.site.urls),

1
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')

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

3
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(

Loading…
Cancel
Save