Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
116 commits
Select commit Hold shift + click to select a range
7a8b5ba
wip: use django-async-upload for media records
paigewilliams Jan 8, 2026
619adf5
use local admin async libraary during development
paigewilliams Jan 8, 2026
9546b76
use AsyncFileCleanupMixin in MediaAdmin form
paigewilliams Jan 13, 2026
630ae96
support async uploads for MediaBulkUploads
paigewilliams Jan 20, 2026
2484eae
fix tests for media bulk upload admin
paigewilliams Jan 21, 2026
56004dc
set ADMIN_SIMULTANEOUS_UPLOADS to 1
paigewilliams Jan 23, 2026
d251595
use ADMIN_RESUMABLE_CHUNK_FOLDER setting
paigewilliams Jan 24, 2026
22a25af
clean up comments
paigewilliams Jan 26, 2026
a0eed17
remove debug log
paigewilliams Jan 27, 2026
2671ad7
remove OrphanedFileCleanupMiddleware and AsyncFileCleanupMixin
paigewilliams Jan 27, 2026
736938c
refactor MediaBulkUploadForm to use FormResumableMultipleFileField
paigewilliams Jan 28, 2026
0788466
remove unused ThumbnailFileInput and MultipleFileField
paigewilliams Jan 28, 2026
95da7bf
use django_resumable_async_upload package
paigewilliams Jan 30, 2026
295dd49
use python 3.11 in gh action run-tests
paigewilliams Jan 30, 2026
be3da99
add migration for async file fields
paigewilliams Jan 30, 2026
7404d03
revert tests to run on python 3.10
paigewilliams Jan 30, 2026
8a17fb2
Merge pull request #231 from Ecotrust/interruptible-uploads
paigewilliams Feb 2, 2026
27d0ff6
use .env.prod in docker-compose.prod.yaml
paigewilliams Feb 3, 2026
5e5cc5b
add github action to publish docker image to github packages
paigewilliams Feb 3, 2026
e91eb06
point push step to prod dockerfile
paigewilliams Feb 3, 2026
ec83f25
try triggering action on push
paigewilliams Feb 3, 2026
453f95e
try generating slug for repo name
paigewilliams Feb 3, 2026
4d93d8d
try getting slug for repo name as string
paigewilliams Feb 3, 2026
43916a5
try again to use lowercase repo name
paigewilliams Feb 3, 2026
521e750
try setting lowercase IMAGE_NAME env var
paigewilliams Feb 3, 2026
05fcd1b
add prod dockerfile
paigewilliams Feb 3, 2026
76b4ab0
remove cache lines for build and push step
paigewilliams Feb 4, 2026
5fb47f5
try token change
paigewilliams Feb 4, 2026
942ea13
remove push from trigger options
paigewilliams Feb 4, 2026
c83e88c
use common docker compose and use extends
paigewilliams Feb 4, 2026
3e60eaa
wip: add gh action to push to ECR and deploy to app runner
paigewilliams Feb 4, 2026
cddcf48
set 5432 as default db port
paigewilliams Feb 24, 2026
bd97aac
use nginx proxy in prod setup
paigewilliams Feb 24, 2026
fd1ec89
add docker compose for testing prod set up locally
paigewilliams Feb 24, 2026
7f91476
add OpenTofu/terraform to gitignore
paigewilliams Feb 24, 2026
60d0dcc
add tf/opentofu IaC
paigewilliams Feb 26, 2026
e8e2c00
track terraform.lock.hcl
paigewilliams Feb 26, 2026
1d46d36
remove deploy app runner gh action workflow
paigewilliams Feb 26, 2026
476f04b
use commands in docker compose not dockerfiles; remove prod.Dockerfile
paigewilliams Feb 26, 2026
1d13c2d
add user_data script to use on install
paigewilliams Feb 27, 2026
aa5786e
remove TODO
paigewilliams Feb 27, 2026
e5f6998
clean up infra files
paigewilliams Mar 2, 2026
d55fbfe
add step in gh action to build and push proxy docker image
paigewilliams Mar 2, 2026
d26b090
add action run on push for testing
paigewilliams Mar 2, 2026
dda7f30
remove format repo slug step in gh action
paigewilliams Mar 2, 2026
cedfa41
spin up docker containers in user_data script
paigewilliams Mar 3, 2026
52c174b
fix syntax in attestation step
paigewilliams Mar 3, 2026
ef93a8e
fix attestation step for images
paigewilliams Mar 3, 2026
7cca80b
wip: gh action to build and push to ECR
paigewilliams Mar 3, 2026
763cc13
update cadence for gh actions
paigewilliams Mar 3, 2026
728a1b8
wip: debug gh action
paigewilliams Mar 3, 2026
4b16ff5
point to correct dockerfile locations
paigewilliams Mar 3, 2026
8f3efe4
use multiarchitechure builds in gh action
paigewilliams Mar 3, 2026
3a8e9ab
wip: use ssm to deploy docker
paigewilliams Mar 3, 2026
87c5b21
only manually trigger create-and-publish-docker-images gh action
paigewilliams Mar 3, 2026
130d0fb
wip: comment out build step, fix syntax in ssm commands
paigewilliams Mar 3, 2026
3513e94
try verifying deployment status
paigewilliams Mar 3, 2026
0f25d03
remove -p from docker compose up
paigewilliams Mar 3, 2026
2c28abd
comment back in docker build image steps
paigewilliams Mar 3, 2026
b3e3dc1
add logs module to track expired chunk deletion
paigewilliams Mar 4, 2026
b943f3b
management command to delete expired chunks
paigewilliams Mar 4, 2026
6ccc0ca
ruff format
paigewilliams Mar 4, 2026
499517b
remove dynamic part of defaultmediabulkname
paigewilliams Mar 4, 2026
9b3da45
Merge pull request #233 from Ecotrust/fix-defaultmediabulkname
paigewilliams Mar 4, 2026
61aa1d9
wip: add celery for deleting expired chunks
paigewilliams Mar 5, 2026
49ddfa5
trigger ec2 on push to develop branch
paigewilliams Mar 5, 2026
ac50543
push to GHR on merge to main
paigewilliams Mar 5, 2026
4df94c8
push to GHR on merge to main
paigewilliams Mar 5, 2026
e5234f8
Merge branch 'develop' into delete-partial-files
paigewilliams Mar 5, 2026
8cecf62
sequence containers, update env vars
paigewilliams Mar 5, 2026
7e4b7b9
schedule task to delete remaining chunks
paigewilliams Mar 5, 2026
6a9f661
move delete_expired_chunks tasks to TEKDB
paigewilliams Mar 5, 2026
8c00426
Merge pull request #232 from Ecotrust/docker-nginx
paigewilliams Mar 5, 2026
0241a46
Merge branch 'develop' into delete-partial-files
paigewilliams Mar 5, 2026
f14f7a0
move env vars out of common.yaml
paigewilliams Mar 6, 2026
2c95eec
add redis, celery, and celery beat to docker-compose.prod.local
paigewilliams Mar 6, 2026
d2fefb8
remove debug task
paigewilliams Mar 6, 2026
354fa94
wip: add tests for delete_expired_chunks
paigewilliams Mar 6, 2026
bcdd5fb
rename tests
paigewilliams Mar 6, 2026
ed2c2b4
add scripts and services for celery in vagrant
paigewilliams Mar 10, 2026
17a3ffb
add CELERY_RESULT_EXTENDED setting
paigewilliams Mar 10, 2026
4ffb47f
remove celery and celery beat restart commands from update.sh
paigewilliams Mar 10, 2026
c24318b
set redis service name as redis-server in celery service files
paigewilliams Mar 10, 2026
bd06fda
add redis, celery and celery-beat to docker-compose.prod.yaml; remove…
paigewilliams Mar 10, 2026
ad6f113
delete delete_expired_chunks.py
paigewilliams Mar 11, 2026
9633ef5
remove unnecessary env vars from celery and celery beat containers
paigewilliams Mar 11, 2026
ce84241
run as non-root user in docker to resolve warning in celery worker
paigewilliams Mar 11, 2026
4f1de26
add test for failed to delete chunk case
paigewilliams Mar 11, 2026
efb9681
Merge pull request #234 from Ecotrust/delete-partial-files
paigewilliams Mar 12, 2026
3d2bc99
add celery_broker_url tf variable
paigewilliams Mar 12, 2026
d7440f5
Merge pull request #236 from Ecotrust/update-branch-user-data
paigewilliams Mar 12, 2026
7232b70
remove non root user from dockerfile
paigewilliams Mar 12, 2026
9557af8
Merge pull request #237 from Ecotrust/remove-non-root-user-dockerfile
paigewilliams Mar 12, 2026
719afe0
add env file to celery and celery-beat in prod docker-compose
paigewilliams Mar 13, 2026
d9143c0
add logs to user_data.tfpl; move code to tekdb dir
paigewilliams Mar 13, 2026
2ddd2d2
add caching to deploy ec2 gh action
paigewilliams Mar 13, 2026
cf07b62
Merge pull request #238 from Ecotrust/fix-staging-deployment
paigewilliams Mar 13, 2026
d539283
update logic in entrypoint to load fixtures
paigewilliams Mar 13, 2026
9613a37
Merge pull request #239 from Ecotrust/try-again-fix-staging
paigewilliams Mar 13, 2026
bd2c09b
unlimited client_max_body_size
paigewilliams Mar 13, 2026
c4bc287
Merge pull request #240 from Ecotrust/large-data-uploads
paigewilliams Mar 13, 2026
9b2626b
fix location for tekdb repo in gh action
paigewilliams Mar 13, 2026
e9a18fe
Merge pull request #241 from Ecotrust/fix-gh-action-dir-location
paigewilliams Mar 13, 2026
d1d6c64
use absolute paths in ssm command
paigewilliams Mar 13, 2026
8202e3e
Merge pull request #242 from Ecotrust/use-absolute-paths-gh-action
paigewilliams Mar 13, 2026
54921de
add settings for logging
paigewilliams Mar 16, 2026
bc6d7f9
Merge pull request #243 from Ecotrust/docker-logs
paigewilliams Mar 16, 2026
76768b1
bind media volumes to celery and celery-beat; use ECR images in prod …
paigewilliams Mar 16, 2026
e9c4a3a
Merge pull request #244 from Ecotrust/debug-delete-expired-chunks
paigewilliams Mar 16, 2026
2ce08bb
dont inherit build and volumes for celery and celery-beat
paigewilliams Mar 16, 2026
c81374b
Merge pull request #245 from Ecotrust/keep-debugging-celery-task
paigewilliams Mar 16, 2026
29c9341
clear ContentType cache in import database
paigewilliams Mar 17, 2026
8b1c601
add test assertion for clear_cache run
paigewilliams Mar 18, 2026
7cc073a
Merge pull request #246 from Ecotrust/debug-interruptable-upload-lookup
paigewilliams Mar 18, 2026
3098601
bump version to 2.9.0
paigewilliams Mar 18, 2026
50b40c4
Merge pull request #247 from Ecotrust/bump-version-2.9.0
paigewilliams Mar 18, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
80 changes: 80 additions & 0 deletions .github/workflows/create-and-publish-docker-images.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
# source: https://docs.github.com/en/actions/tutorials/publish-packages/publish-docker-images#publishing-images-to-docker-hub-and-github-packages
name: Create and publish a Docker image

# manually trigger while testing
on:
push:
branches:
- main
workflow_dispatch:

# Defines two custom environment variables for the workflow. These are used for the Container registry domain, and a name for the Docker image that this workflow builds.
env:
REGISTRY: ghcr.io

jobs:
build-and-push-image:
runs-on: ubuntu-latest
# Sets the permissions granted to the `PACKAGE_TOKEN` for the actions in this job.
permissions:
contents: read
packages: write
attestations: write
id-token: write
steps:
- name: Checkout repository
uses: actions/checkout@v5
# Uses the `docker/login-action` action to log in to the Container registry registry using the account and password that will publish the packages. Once published, the packages are scoped to the account defined here.
- name: Log in to the Container registry
uses: docker/login-action@v3
with:
registry: ${{ env.REGISTRY }}
username: ${{ github.actor }}
password: ${{ secrets.PACKAGE_TOKEN }}
# This step uses [docker/metadata-action](https://github.com/docker/metadata-action#about) to extract tags and labels that will be applied to the specified image. The `id` "meta" allows the output of this step to be referenced in a subsequent step. The `images` value provides the base name for the tags and labels.
- name: Set lowercase image name
run: |
IMAGE_NAME=$(echo "${GITHUB_REPOSITORY}" | tr '[:upper:]' '[:lower:]')
echo "IMAGE_NAME=${IMAGE_NAME}" >> $GITHUB_ENV
- name: Extract metadata (tags, labels) for Docker
id: meta
uses: docker/metadata-action@v5
with:
images: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}
# This step uses the `docker/build-push-action` action to build the image, based on your repository's `Dockerfile`. If the build succeeds, it pushes the image to GitHub Packages.
# It uses the `context` parameter to define the build's context as the set of files located in the specified path. For more information, see [Usage](https://github.com/docker/build-push-action#usage) in the README of the `docker/build-push-action` repository.
# It uses the `tags` and `labels` parameters to tag and label the image with the output from the "meta" step.

- name: Build and push web Docker image
id: push
uses: docker/build-push-action@v6
with:
context: ./TEKDB
file: ./TEKDB/Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/web:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/web:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}
- name: Build and push proxy Docker image
id: push-proxy
uses: docker/build-push-action@v6
with:
context: ./proxy
file: ./proxy/Dockerfile
push: true
tags: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/proxy:latest,${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/proxy:${{ github.sha }}
labels: ${{ steps.meta.outputs.labels }}

# This step generates an artifact attestation for the image, which is an unforgeable statement about where and how it was built. It increases supply chain security for people who consume the image. For more information, see [Using artifact attestations to establish provenance for builds](/actions/security-guides/using-artifact-attestations-to-establish-provenance-for-builds).
- name: Generate artifact attestation for web image
uses: actions/attest-build-provenance@v3
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/web
subject-digest: ${{ steps.push.outputs.digest }}
push-to-registry: true
- name: Generate artifact attestation for proxy image
uses: actions/attest-build-provenance@v3
with:
subject-name: ${{ env.REGISTRY }}/${{ env.IMAGE_NAME }}/proxy
subject-digest: ${{ steps.push-proxy.outputs.digest }}
push-to-registry: true

111 changes: 111 additions & 0 deletions .github/workflows/deploy-ec2-staging.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,111 @@
name: Build, Push, and Deploy to EC2 Staging

on:
push:
branches:
- develop
workflow_dispatch:

jobs:
build-push-and-deploy:
name: Build, Push to ECR, Deploy to EC2 Staging
runs-on: ubuntu-latest
permissions:
id-token: write

steps:
- name: Checkout code
uses: actions/checkout@v5

- name: Configure AWS credentials
uses: aws-actions/configure-aws-credentials@v5
with:
role-to-assume: ${{ secrets.AWS_ROLE_ARN }}
aws-region: ${{ secrets.AWS_REGION}}

- name: Login to Amazon ECR
id: login-ecr
uses: aws-actions/amazon-ecr-login@v2

- name: Set up Docker Buildx
uses: docker/setup-buildx-action@v3

- name: Build, tag, and push web Docker image to ECR
id: build-web-image
env:
IMAGE_TAG: ${{ github.sha }}
IMAGE_URI: ${{ secrets.WEB_ECR_IMAGE_URI }}
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from type=gha,scope=web \
--cache-to type=gha,mode=max,scope=web \
-t $IMAGE_URI:$IMAGE_TAG \
-t $IMAGE_URI:latest \
-f ./TEKDB/Dockerfile ./TEKDB \
--push
- name: Build, tag, and push proxy Docker image to ECR
id: build-proxy-image
env:
IMAGE_TAG: ${{ github.sha }}
IMAGE_URI: ${{ secrets.PROXY_ECR_IMAGE_URI }}
run: |
docker buildx build \
--platform linux/amd64,linux/arm64 \
--cache-from type=gha,scope=proxy \
--cache-to type=gha,mode=max,scope=proxy \
-t $IMAGE_URI:$IMAGE_TAG \
-t $IMAGE_URI:latest \
-f ./proxy/Dockerfile ./proxy \
--push
- name: get EC2 Instance ID
id: get-instance
run: |
INSTANCE_ID=$(aws ec2 describe-instances \
--filters "Name=tag:Name,Values=${{ secrets.EC2_INSTANCE_NAME }}" \
"Name=instance-state-name,Values=running" \
--query "Reservations[0].Instances[0].InstanceId" \
--output text)
echo "instance_id=$INSTANCE_ID" >> $GITHUB_OUTPUT
- name: Deploy via SSM
id: ssm-deploy
run: |
COMMAND_ID=$(aws ssm send-command \
--instance-ids "${{ steps.get-instance.outputs.instance_id }}" \
--document-name "AWS-RunShellScript" \
--parameters 'commands=[
"cd /tekdb/TEKDB && git pull origin develop",
"aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | sudo docker login --username AWS --password-stdin ${{ secrets.WEB_ECR_IMAGE_URI }}",
"sudo docker pull ${{ secrets.WEB_ECR_IMAGE_URI }}:latest",
"aws ecr get-login-password --region ${{ secrets.AWS_REGION }} | sudo docker login --username AWS --password-stdin ${{ secrets.PROXY_ECR_IMAGE_URI }}",
"sudo docker pull ${{ secrets.PROXY_ECR_IMAGE_URI }}:latest",
"sudo docker compose -f /tekdb/TEKDB/docker/docker-compose.prod.yaml down",
"docker compose --env-file /tekdb/TEKDB/docker/.env.prod -f /tekdb/TEKDB/docker/docker-compose.prod.yaml up -d",
"sleep 5",
"docker ps --filter name=web --format \"{{.Status}}\""
]' \
--timeout-seconds 120 \
--comment "Deploy ${{ github.sha }}" \
--query "Command.CommandId" \
--output text)
echo "command_id=$COMMAND_ID" >> $GITHUB_OUTPUT
- name: Wait for deployment to complete
run: |
aws ssm wait command-executed \
--command-id ${{ steps.ssm-deploy.outputs.command_id }} \
--instance-id ${{ steps.get-instance.outputs.instance_id }}
- name: Verify deployment result
run: |
RESULT=$(aws ssm get-command-invocation \
--command-id ${{ steps.ssm-deploy.outputs.command_id }} \
--instance-id ${{ steps.get-instance.outputs.instance_id }} \
--query "{Status:Status,Output:StandardOutputContent,Error:StandardErrorContent}" \
--output json)
echo "$RESULT" | jq .
STATUS=$(echo "$RESULT" | jq -r '.Status')
if [ "$STATUS" != "Success" ]; then
echo "::error::Deployment failed with status: $STATUS"
exit 1
fi
echo "Deployment succeeded."
9 changes: 8 additions & 1 deletion .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,7 @@ celerybeat-schedule

# dotenv
.env
.env.prod

# virtualenv
venv/
Expand All @@ -98,4 +99,10 @@ ENV/
.ropeproject

#vscode settings
.vscode/
.vscode/

# OpenTofu/Terraform
.terraform/
terraform.tfstate
terraform.tfstate.backup
*.tfvars
1 change: 1 addition & 0 deletions TEKDB/.env.dev
Original file line number Diff line number Diff line change
Expand Up @@ -7,3 +7,4 @@ SQL_USER=postgres
SQL_PASSWORD=tekdb_password
SQL_HOST=db
SQL_PORT=5432
CELERY_BROKER_URL=redis://redis:6379/0
11 changes: 9 additions & 2 deletions TEKDB/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ WORKDIR /usr/src/app
COPY requirements.txt requirements_linux.txt /usr/src/app/

# Upgrade pip and install Python dependencies
# Note: editable packages (-e) will be installed at runtime via entrypoint.sh
RUN pip install --upgrade pip \
&& pip install -r requirements.txt -r requirements_linux.txt

Expand All @@ -33,6 +34,14 @@ COPY . /usr/src/app
COPY entrypoint.sh /usr/local/bin/entrypoint.sh
RUN chmod +x /usr/local/bin/entrypoint.sh

# Create a non-root user and give it ownership of the app directory
# TODO: consider using a non-root user for better security. Addings just this
# resulted in a permissions error, "ERROR: Unable to load local_settings.py."
# RUN addgroup --system appgroup && adduser --system --ingroup appgroup appuser \
# && chown -R appuser:appgroup /usr/src/app

# USER appuser

# Expose the port the app runs on (entrypoint starts django development server or uWSGI on 8000)
EXPOSE 8000

Expand All @@ -41,5 +50,3 @@ ENV DJANGO_SETTINGS_MODULE=TEKDB.settings

ENTRYPOINT ["/usr/local/bin/entrypoint.sh"]

# use development server by default
CMD ["dev"]
4 changes: 4 additions & 0 deletions TEKDB/TEKDB/__init__.py
Original file line number Diff line number Diff line change
@@ -1,2 +1,6 @@
# TEKDB/__init__.py
# This will make sure the app is always imported when
# Django starts so that shared_task will use this app.
from .celery import app as celery_app

__all__ = ("celery_app",)
116 changes: 67 additions & 49 deletions TEKDB/TEKDB/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@
from dal import autocomplete
from mimetypes import guess_type
from django.templatetags.static import static
from django_celery_results.admin import GroupResult

# from moderation.admin import ModerationAdmin
import nested_admin
Expand Down Expand Up @@ -61,6 +62,7 @@
from TEKDB.settings import BASE_DIR
from TEKDB.widgets import OpenLayers6Widget


admin.site.site_header = ADMIN_SITE_HEADER


Expand Down Expand Up @@ -626,57 +628,69 @@ def save_model(self, request, obj, form, change):
activities = form.cleaned_data.get("activities")
placesresources = form.cleaned_data.get("placesresources")

for file in request.FILES.getlist("files"):
mime_type, _ = guess_type(file.name)
# if mime_type:
file_mime_type = mime_type.split("/")[0]
media_type_instance = LookupMediaType.objects.filter(
mediatype__startswith=file_mime_type
).first()
if media_type_instance:
mediatype = media_type_instance
else:
media_type_instance = LookupMediaType.objects.filter(
mediatype__startswith="other"
).first()
# Handle async uploaded file (comes as a list of file path strings)
uploaded_file_paths = form.cleaned_data.get("files")

if uploaded_file_paths and isinstance(uploaded_file_paths, list):
import os

for uploaded_file_path in uploaded_file_paths:
# Extract just the filename from the path
file_name = os.path.basename(uploaded_file_path)

# Guess MIME type from filename
mime_type, _ = guess_type(file_name)
if mime_type:
file_mime_type = mime_type.split("/")[0]
media_type_instance = LookupMediaType.objects.filter(
mediatype__startswith=file_mime_type
).first()
else:
media_type_instance = None

if not media_type_instance:
media_type_instance = LookupMediaType.objects.filter(
mediatype__startswith="other"
).first()

mediatype = media_type_instance
filename = file.name.split(".")[0]
filename = file_name.rsplit(".", 1)[0] # Remove extension

media_instance = Media(
medianame=filename,
mediadescription=f'Part of the "{obj.mediabulkname}" Media Bulk Upload that was uploaded on {obj.mediabulkdate}',
mediafile=file,
mediatype=mediatype,
)
media_instance.save()
obj.mediabulkupload.add(media_instance)

# Add relationships
if places:
for place in places:
PlacesMediaEvents.objects.create(
placeid=place, mediaid=media_instance
)
if resources:
for resource in resources:
ResourcesMediaEvents.objects.create(
resourceid=resource, mediaid=media_instance
)
if citations:
for citation in citations:
MediaCitationEvents.objects.create(
citationid=citation, mediaid=media_instance
)
if activities:
for activity in activities:
ResourceActivityMediaEvents.objects.create(
resourceactivityid=activity, mediaid=media_instance
)
if placesresources:
for placeresource in placesresources:
PlacesResourceMediaEvents.objects.create(
placeresourceid=placeresource, mediaid=media_instance
)
media_instance = Media(
medianame=filename,
mediadescription=f'Part of the "{obj.mediabulkname}" Media Bulk Upload that was uploaded on {obj.mediabulkdate}',
mediafile=uploaded_file_path,
mediatype=mediatype,
)
media_instance.save()
obj.mediabulkupload.add(media_instance)

# Add relationships
if places:
for place in places:
PlacesMediaEvents.objects.create(
placeid=place, mediaid=media_instance
)
if resources:
for resource in resources:
ResourcesMediaEvents.objects.create(
resourceid=resource, mediaid=media_instance
)
if citations:
for citation in citations:
MediaCitationEvents.objects.create(
citationid=citation, mediaid=media_instance
)
if activities:
for activity in activities:
ResourceActivityMediaEvents.objects.create(
resourceactivityid=activity, mediaid=media_instance
)
if placesresources:
for placeresource in placesresources:
PlacesResourceMediaEvents.objects.create(
placeresourceid=placeresource, mediaid=media_instance
)

@admin.display(description="Thumbnails")
def thumbnail_gallery(self, obj):
Expand Down Expand Up @@ -1757,3 +1771,7 @@ class UsersAdmin(UserAdmin):
admin.site.register(LookupAuthorType)
admin.site.register(LookupUserInfo)
# admin.site.register(CurrentVersion)

admin.site.unregister(GroupResult)
# admin.site.unregister(CrontabScheduleAdmin)
# admin.site.unregister(ClockedScheduleAdmin)
Loading
Loading