Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Split media and static folders #340

Merged
merged 2 commits into from
Jan 19, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
20 changes: 11 additions & 9 deletions dockerize/docker-compose.yml
Original file line number Diff line number Diff line change
@@ -1,4 +1,7 @@
version: "3.8"
volumes:
django-statics-data: {}
django-media-data: {}
services:
db:
container_name: qgis-plugins-db
Expand Down Expand Up @@ -28,8 +31,8 @@ services:
- RABBITMQ_HOST=rabbitmq
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./static:/home/web/media:rw
- django-statics-data:/home/web/static:rw
- django-media-data:/home/web/media:rw
links:
- db:db
- rabbitmq:rabbitmq
Expand All @@ -54,8 +57,8 @@ services:
- RABBITMQ_HOST=rabbitmq
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./static:/home/web/media:rw
- django-statics-data:/home/web/static:rw
- django-media-data:/home/web/media:rw
links:
- db:db
- rabbitmq:rabbitmq
Expand Down Expand Up @@ -95,8 +98,8 @@ services:
- RABBITMQ_HOST=rabbitmq
volumes:
- ../qgis-app:/home/web/django_project
- ./static:/home/web/static:rw
- ./static:/home/web/media:rw
- django-statics-data:/home/web/static:rw
- django-media-data:/home/web/media:rw
links:
- db:db
- rabbitmq:rabbitmq
Expand All @@ -108,9 +111,8 @@ services:
hostname: nginx
volumes:
- ./sites-enabled:/etc/nginx/conf.d:ro
# I dont use volumes_from as I want to use the ro modifier
- ./static:/home/web/static:ro
- ./static:/home/web/media:ro
- django-statics-data:/home/web/static:ro
- django-media-data:/home/web/media:ro
- ./logs:/var/log/nginx
links:
- web:uwsgi
Expand Down
38 changes: 38 additions & 0 deletions qgis-app/plugins/management/commands/cleanmediafolder.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
import os
from shutil import rmtree
from django.conf import settings
from django.core.management import call_command
from django.core.management.base import BaseCommand

class Command(BaseCommand):
help = 'Run collectstatic and delete folders from media that exist in static'

def handle(self, *args, **options):
confirm = input("Do you want to run 'collectstatic' first? (yes/no): ")
if confirm.lower() == 'yes':
# Run collectstatic command
call_command('collectstatic', interactive=False)

# Get the paths of static and media folders
static_root = settings.STATIC_ROOT
media_root = settings.MEDIA_ROOT

# Iterate over each directory in the static folder
for static_dir in os.listdir(static_root):
static_path = os.path.join(static_root, static_dir)

# Check if the path is a directory and exists in the media folder
if os.path.isdir(static_path) and os.path.exists(os.path.join(media_root, static_dir)):
confirm = input(f"Are you sure you want to delete '{static_dir}' from the media folder? (yes/no): ")

if confirm.lower() == 'yes':
try:
# Delete the corresponding folder in the media folder
rmtree(os.path.join(media_root, static_dir))
self.stdout.write(self.style.SUCCESS(f'Deleted {static_dir} from media folder.'))
except Exception as e:
self.stderr.write(self.style.ERROR(f'Error deleting {static_dir}: {str(e)}'))
else:
self.stdout.write(self.style.WARNING(f'Skipped deletion of {static_dir}.'))

self.stdout.write(self.style.SUCCESS('The media folder has been cleaned.'))
Loading