mirror of
https://github.com/MOIS3Y/logs-collector.git
synced 2025-02-01 01:10:52 +01:00
Fix: custom storage path
This commit is contained in:
parent
68bec09209
commit
b65481207a
@ -11,7 +11,7 @@ from collector.models import Archive, Platform, Ticket
|
||||
|
||||
|
||||
def delete_test_files(ticket):
|
||||
test_file = settings.MEDIA_ROOT_FOR_SENSITIVE_FILES / Path(str(ticket))
|
||||
test_file = settings.MEDIA_ROOT / Path(str(ticket))
|
||||
test_file.unlink(missing_ok=True)
|
||||
|
||||
|
||||
|
@ -1,12 +1,10 @@
|
||||
# Generated by Django 4.2 on 2023-08-15 03:58
|
||||
# Generated by Django 4.2 on 2023-08-30 05:52
|
||||
|
||||
import collector.utils
|
||||
from django.conf import settings
|
||||
import django.core.files.storage
|
||||
import django.core.validators
|
||||
from django.db import migrations, models
|
||||
import django.db.models.deletion
|
||||
import pathlib
|
||||
import uuid
|
||||
|
||||
|
||||
@ -49,7 +47,7 @@ class Migration(migrations.Migration):
|
||||
name='Archive',
|
||||
fields=[
|
||||
('id', models.BigAutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
|
||||
('file', models.FileField(blank=True, null=True, storage=django.core.files.storage.FileSystemStorage(base_url='/archives/', location=pathlib.PurePosixPath('/home/stepan/Documents/Dev/ISPsystem/logs-collector/logs_collector/archives')), upload_to=collector.utils.logs_dir_path)),
|
||||
('file', models.FileField(blank=True, null=True, upload_to=collector.utils.logs_dir_path)),
|
||||
('md5', models.CharField(editable=False, max_length=1024)),
|
||||
('time_create', models.DateTimeField(auto_now_add=True)),
|
||||
('time_update', models.DateTimeField(auto_now=True)),
|
||||
|
@ -1,35 +1,16 @@
|
||||
import uuid
|
||||
import hashlib
|
||||
from functools import partial
|
||||
|
||||
from django.core.validators import MaxValueValidator, MinValueValidator
|
||||
from django.contrib.auth.models import User
|
||||
from django.db import models
|
||||
from django.conf import settings
|
||||
from django.core.files.storage import FileSystemStorage
|
||||
from django.urls import reverse
|
||||
|
||||
from .utils import logs_dir_path
|
||||
|
||||
|
||||
# Create a custom storage location, using a value from your settings file
|
||||
sensitive_upload_storage = FileSystemStorage(
|
||||
location=settings.MEDIA_ROOT_FOR_SENSITIVE_FILES,
|
||||
base_url=settings.MEDIA_URL_FOR_SENSITIVE_FILES
|
||||
)
|
||||
# ... and a file field that will use the custom storage
|
||||
AuthenticatedFileField = partial(
|
||||
models.FileField,
|
||||
storage=sensitive_upload_storage
|
||||
)
|
||||
|
||||
|
||||
class Archive(models.Model):
|
||||
file = AuthenticatedFileField(
|
||||
upload_to=logs_dir_path,
|
||||
blank=True,
|
||||
null=True
|
||||
)
|
||||
file = models.FileField(upload_to=logs_dir_path, blank=True, null=True)
|
||||
md5 = models.CharField(max_length=1024, editable=False)
|
||||
time_create = models.DateTimeField(auto_now_add=True)
|
||||
time_update = models.DateTimeField(auto_now=True)
|
||||
|
@ -8,7 +8,7 @@ from collector.models import Platform, Ticket, Archive
|
||||
|
||||
|
||||
def delete_test_files(ticket):
|
||||
test_file = settings.MEDIA_ROOT_FOR_SENSITIVE_FILES / Path(str(ticket))
|
||||
test_file = settings.MEDIA_ROOT / Path(str(ticket))
|
||||
test_file.unlink(missing_ok=True)
|
||||
|
||||
|
||||
|
@ -139,12 +139,21 @@ STATIC_ROOT = BASE_DIR / 'static'
|
||||
|
||||
DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
|
||||
|
||||
MEDIA_ROOT = BASE_DIR / 'media'
|
||||
MEDIA_URL = 'media/'
|
||||
|
||||
MEDIA_ROOT_FOR_SENSITIVE_FILES = BASE_DIR / 'archives'
|
||||
MEDIA_URL_FOR_SENSITIVE_FILES = '/archives/'
|
||||
MEDIA_ROOT = BASE_DIR / 'archives'
|
||||
|
||||
STORAGES = {
|
||||
# ...
|
||||
"default": {
|
||||
"BACKEND": "django.core.files.storage.FileSystemStorage",
|
||||
"OPTIONS": {
|
||||
"location": MEDIA_ROOT,
|
||||
"base_url": "/archives/",
|
||||
},
|
||||
},
|
||||
"staticfiles": {
|
||||
"BACKEND": "django.contrib.staticfiles.storage.StaticFilesStorage",
|
||||
},
|
||||
}
|
||||
|
||||
# django-crispy-forms and crispy-bootstrap5
|
||||
# https://django-crispy-forms.readthedocs.io/en/latest/
|
||||
|
@ -1,4 +1,3 @@
|
||||
from django.conf.urls.static import static
|
||||
from django.contrib import admin
|
||||
from django.urls import path, include
|
||||
|
||||
@ -9,8 +8,6 @@ from drf_spectacular.views import (
|
||||
)
|
||||
|
||||
from two_factor.urls import urlpatterns as tf_urls
|
||||
|
||||
from logs_collector import settings
|
||||
from account.utils import AdminSiteOTPRequiredMixinRedirectSetup
|
||||
|
||||
|
||||
@ -57,8 +54,3 @@ urlpatterns += [
|
||||
name='redoc'
|
||||
),
|
||||
]
|
||||
|
||||
if settings.DEBUG:
|
||||
urlpatterns += static(
|
||||
settings.MEDIA_URL, document_root=settings.MEDIA_ROOT
|
||||
)
|
||||
|
Loading…
Reference in New Issue
Block a user