Skip to content

Commit

Permalink
Merge pull request #22 from chnm/feature/minio
Browse files Browse the repository at this point in the history
Merge feature/minio into main
  • Loading branch information
hepplerj authored Jul 23, 2024
2 parents 2b51beb + faaa68e commit be0b5bc
Show file tree
Hide file tree
Showing 60 changed files with 191 additions and 48 deletions.
7 changes: 7 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,13 @@ DJANGO_SECRET_KEY=thisisnotasecretkey
DJANGO_ALLOWED_HOSTS='localhost,"",127.0.0.1,0.0.0.0'
DJANGO_CSRF_TRUSTED_ORIGINS='http://localhost'

# Object Store
OBJ_STORAGE=False # set to True to turn on, fill in the following variables
OBJ_STORAGE_ACCESS_KEY_ID=winterthur
OBJ_STORAGE_SECRET_ACCESS_KEY=winterthur
OBJ_STORAGE_BUCKET_NAME=winterthur
OBJ_STORAGE_ENDPOINT_URL=minio

# Database
DB_NAME=winterthur
DB_USER=winterthur
Expand Down
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ models.png
documents/
staticfiles/
images/
static/upload

### Generated by gibo (https://github.com/simonwhitaker/gibo)
### https://raw.github.com/github/gitignore/4488915eec0b3a45b5c63ead28f286819c0917de/Python.gitignore
Expand Down
51 changes: 40 additions & 11 deletions config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,18 @@
# ------------------------------------------------------------------------------

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = env("DJANGO_SECRET_KEY", default="django-insecure cin)v(4&89%_$17s0yezo=t+^1b*mq)=+348r-bv(ms#pm2y2#")
SECRET_KEY = env(
"DJANGO_SECRET_KEY",
default="django-insecure cin)v(4&89%_$17s0yezo=t+^1b*mq)=+348r-bv(ms#pm2y2#",
)

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = env("DEBUG")

ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=['localhost'])
CSRF_TRUSTED_ORIGINS = env.list("DJANGO_CSRF_TRUSTED_ORIGINS", default=['http://localhost'])
ALLOWED_HOSTS = env.list("DJANGO_ALLOWED_HOSTS", default=["localhost"])
CSRF_TRUSTED_ORIGINS = env.list(
"DJANGO_CSRF_TRUSTED_ORIGINS", default=["http://localhost"]
)


# Application definition
Expand All @@ -46,6 +51,8 @@
"django.contrib.sessions",
"django.contrib.messages",
"django.contrib.staticfiles",
"storages",
"django_cleanup.apps.CleanupConfig", # auto-delete files from FileField or ImageField if deleted in django-admin
"wagtail.contrib.forms",
"wagtail.contrib.redirects",
"wagtail.embeds",
Expand Down Expand Up @@ -155,7 +162,7 @@
# https://docs.djangoproject.com/en/4.1/topics/i18n/

LANGUAGE_CODE = "en-us"
TIME_ZONE = "UTC"
TIME_ZONE = "America/New_York"

USE_I18N = True
USE_TZ = True
Expand All @@ -166,23 +173,45 @@
"127.0.0.1",
]

# Wagtail configuration
WAGTAILADMIN_BASE_URL = "localhost:8000"
WAGTAIL_SITE_NAME = "Denig Essays"
TAGGIT_TAGS_FROM_STRING = "taggit_selectize.utils.parse_tags"
TAGGIT_STRING_FROM_TAGS = "taggit_selectize.utils.join_tags"

STORAGES = {
"default": {
"BACKEND": "django.core.files.storage.FileSystemStorage",
},
"staticfiles": {
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
},
}

# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/4.1/howto/static-files/

STATIC_URL = "static/"
STATIC_URL = "/static/"
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
STATIC_ROOT = os.path.join(BASE_DIR, "staticfiles")
MEDIA_ROOT = os.path.join(BASE_DIR, "media")
MEDIA_URL = "/media/"

# Extra places for collectstatic to find static files.
STATICFILES_DIRS = (os.path.join(BASE_DIR, "static"),)
# Media files
OBJ_STORAGE = env("OBJ_STORAGE", default=False)
if OBJ_STORAGE:
AWS_ACCESS_KEY_ID = env("OBJ_STORAGE_ACCESS_KEY_ID")
AWS_SECRET_ACCESS_KEY = env("OBJ_STORAGE_SECRET_ACCESS_KEY")
AWS_STORAGE_BUCKET_NAME = env("OBJ_STORAGE_BUCKET_NAME")
AWS_S3_ENDPOINT_URL = env("OBJ_STORAGE_ENDPOINT_URL")

MEDIA_URL = f"{AWS_S3_ENDPOINT_URL}/{AWS_STORAGE_BUCKET_NAME}/"

# override default storage backend for media
STORAGES["default"] = {
"BACKEND": "storages.backends.s3.S3Storage",
}
else:
MEDIA_URL = "media/"
MEDIA_ROOT = os.path.join(BASE_DIR, "mediafiles")

# Default primary key field type
# https://docs.djangoproject.com/en/4.1/ref/settings/#default-auto-field

DEFAULT_AUTO_FIELD = "django.db.models.BigAutoField"
21 changes: 14 additions & 7 deletions denig/management/commands/importimages.py
Original file line number Diff line number Diff line change
Expand Up @@ -28,14 +28,21 @@ def handle(self, *args, **options):
document_id, _ = os.path.splitext(filename)
try:
document = Document.objects.get(document_id=document_id)
with open(os.path.join(filepath, filename), "rb") as f:
image = Image(
related_document=document,
image=File(f, name=filename),
)
image.save()
if not Image.objects.filter(related_document=document).exists():
with open(os.path.join(filepath, filename), "rb") as f:
image = Image(
related_document=document,
image=File(f, name=filename),
)
image.save()
self.stdout.write(
self.style.SUCCESS(f"Successfully associated {filename}.")
)
else:
self.stdout.write(
self.style.SUCCESS(f"Successfully associated {filename}.")
self.style.WARNING(
f"Image for document {document_id} already exists."
)
)
except Document.DoesNotExist:
self.stdout.write(
Expand Down
8 changes: 1 addition & 7 deletions denig/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -54,15 +54,9 @@ class DocumentListView(generic.ListView):
template_name = "manuscript.html"

def get_queryset(self):
# This method ensures the documents are ordered by 'document_id'
return Document.objects.all().order_by("document_id")

def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs)
document_list = Document.objects.all().order_by("document_id")
context["document_list"] = document_list

return context

def get_absolute_url(self):
"""Return the URL for this document."""
return reverse("document", args=[str(self.id)])
Expand Down
5 changes: 5 additions & 0 deletions docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,11 @@ services:
- DB_NAME=winterthur
- DB_USER=winterthur
- DB_PASSWORD=password
- OBJ_STORAGE=True
- OBJ_STORAGE_ACCESS_KEY_ID=test-key-id
- OBJ_STORAGE_SECRET_ACCESS_KEY=test-secret-key
- OBJ_STORAGE_BUCKET_NAME=test
- OBJ_STORAGE_ENDPOINT_URL=http://10.112.113.212:8000
command: >
sh -c "poetry run python3 manage.py migrate &&
poetry run python3 manage.py runserver 0.0.0.0:8000"
Expand Down
9 changes: 5 additions & 4 deletions docker-compose.yml.j2
Original file line number Diff line number Diff line change
Expand Up @@ -18,12 +18,16 @@ services:
- DB_NAME={{ template.env.db_name }}
- DB_USER={{ template.env.db_user }}
- DB_PASSWORD={{ template.env.db_pass }}
- OBJ_STORAGE={{ template.env.obj_storage }}
- OBJ_STORAGE_ACCESS_KEY_ID={{ template.env.obj_storage_access_key_id }}
- OBJ_STORAGE_SECRET_ACCESS_KEY={{ template.env.obj_storage_secret_access_key }}
- OBJ_STORAGE_BUCKET_NAME={{ template.env.obj_storage_bucket_name }}
- OBJ_STORAGE_ENDPOINT_URL={{ template.env.obj_storage_endpoint_url }}
command: >
sh -c "poetry run python3 manage.py migrate &&
poetry run python3 manage.py runserver 0.0.0.0:8000"
volumes:
- dj-static:/app/staticfiles
- dj-media:/app/media
depends_on:
db:
condition: service_healthy
Expand All @@ -49,9 +53,6 @@ volumes:
dj-static:
name: "{{ template.name }}_app-static-vol"
external: true
dj-media:
name: "{{ template.name }}_app-media-vol"
external: true
pg-data:
name: "{{ template.name }}_db-vol"
external: true
102 changes: 101 additions & 1 deletion poetry.lock

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

3 changes: 3 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,9 @@ psycopg2 = "^2.9.9"
pandas = "^2.2.0"
wagtail = "^6.0.1"
django-modelcluster = "^6.3"
boto3 = "^1.34.128"
django-storages = "^1.14.3"
django-cleanup = "^8.1.0"


[tool.poetry.group.dev.dependencies]
Expand Down
Binary file removed static/upload/2020-0011_view-001.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-002.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-003.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-004.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-005.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-006.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-007.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-008.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-009.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-010.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-011.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-012.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-013.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-014.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-015.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-016.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-017.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-018.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-019.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-020.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-021.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-022.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-023.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-024.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-025.jpg
Binary file not shown.
Binary file removed static/upload/2020-0011_view-026.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-027.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-028.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-029.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-030.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-031.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-032.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-033.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-034.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-035.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-036.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-037.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-038.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-039.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-040.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-041.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-042.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-043.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-044.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-045.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-046.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-047.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-048.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-049.jpg
Diff not rendered.
Binary file removed static/upload/2020-0011_view-050.jpg
Diff not rendered.
32 changes: 14 additions & 18 deletions templates/manuscript.html
Original file line number Diff line number Diff line change
Expand Up @@ -28,27 +28,23 @@ <h1>The Manuscript.</h1>
{% if forloop.first %}
<li></li> {# Empty element for the left side #}
{% endif %}
<li class="flex space-x-4">
{% if document.attached_images.all %}
<ul>
{% for image in document.attached_images.all %}
<li>
<a href="{% url 'manuscript_page' document.id %}"><img src="{{ image.image.url }}"
alt="Document Image" load="lazy"></a>
<p class="prose-figcaption font-sans">
Page {{ document.page_range }} ({{document.docside}})
</p>
</li>
{% endfor %}
</ul>
{% else %}
{# Handle case where no images are attached #}
{% for image in document.attached_images.all %}
<li class="flex space-x-4">
<a href="{% url 'manuscript_page' document.id %}">
<img src="{{ image.image.url }}" alt="Document Image" load="lazy">
<p class="prose-figcaption font-sans">
Page {{ document.page_range }} ({{document.docside}}) ({{document.description}})
</p>
</a>
</li>
{% empty %}
<li class="flex space-x-4">
<p>No images available</p>
{% endif %}
</li>
</li>
{% endfor %}
{% endfor %}
</ul>
{% endif %}
</div>
</div>
{% endblock content %}
{% endblock content %}

0 comments on commit be0b5bc

Please sign in to comment.