Linter and format fixes
continuous-integration/drone/push Build is failing Details

This commit is contained in:
Jordi Loyzaga 2024-09-17 02:18:58 -06:00
parent ff2d88493b
commit c6d7566c72
17 changed files with 53 additions and 42 deletions

View File

@ -1,6 +1,4 @@
from django.apps import (
AppConfig,
)
from django.apps import AppConfig
class CommonConfig(AppConfig):

View File

@ -3,18 +3,21 @@ import re
CONTENT_RANGE_HEADER = "HTTP_CONTENT_RANGE"
CONTENT_RANGE_HEADER_PATTERN = re.compile(r"^bytes (?P<start>\d+)-(?P<end>\d+)$")
class UPLOAD_STATUS_TYPES:
UPLOADING = "uploading"
COMPLETED = "completed"
ABANDONED = "abandoned"
ERROR = "error"
class UPLOAD_ERROR_CODES:
FILE_MISSING = "file_missing"
CHUNK_MISMATCH = "chunk_mismatch"
# Config
CONFIG_KEYS = {
"ABANDONED_DELTA_MINUTES": {
"description": "Date created + this delta at which a file is marked as abandoned",
@ -42,7 +45,7 @@ CONFIG_KEYS = {
"verbose_name": "Max upload size in bytes",
"native_type": int,
"sensitive": False,
"default": 1024 * 1024 * 30, # 200 MB
"default": 1024 * 1024 * 30, # 200 MB
},
"ENABLE_BROWSABLE_API": {
"description": "REST Framework browsable API is enabled (Always enabled if DEBUG is true)",

View File

@ -15,9 +15,11 @@ class Config(NamedTuple):
value: Any
source: str
def normalize_string(string, form="NFKC"):
return normalize(form, string)
def cast_to_native_type(key, value, native_type):
if native_type == list:

View File

@ -1,15 +1,15 @@
from common.constants import CONFIG_KEYS
from common.serializers import ConfigSerializer
from common.utils import get_config
from rest_framework import status
from rest_framework.decorators import api_view
from rest_framework.response import Response
from common.constants import CONFIG_KEYS
from common.serializers import ConfigSerializer
from common.utils import get_config
def get_all_configs():
return [get_config(key, value_only=False)._asdict() for key in CONFIG_KEYS]
@api_view(["GET"])
def configs(request, key=None):
if key:

View File

@ -3,8 +3,10 @@ from pathlib import Path
# TODO: LOG MEEEEE
# TODO: Figure out file owner in system, permissions, GUID
# Whats the default path if not provided? // docker volume
def validate_paths(media_path):
try:
Path(media_path).mkdir(exist_ok=True)
except Exception as e:
raise e
try:
Path(media_path).mkdir(exist_ok=True)
except Exception as e:
raise e

View File

@ -1,9 +1,9 @@
from django.contrib import admin
from storage.models import File
class FileAdmin(admin.ModelAdmin):
readonly_fields = File.readonly_fields
admin.site.register(File, FileAdmin)

View File

@ -1,13 +1,14 @@
from datetime import timedelta
from hashlib import md5
from pathlib import Path
from common.constants import UPLOAD_STATUS_TYPES, UPLOAD_ERROR_CODES
from common.constants import UPLOAD_ERROR_CODES, UPLOAD_STATUS_TYPES
from common.models import LockboxBase
from common.utils import get_config, get_max_size_chunk_bytes
from django.conf import settings
from django.db import models, transaction
from django.utils import timezone
from django.utils.translation import gettext_lazy as _
from django.conf import settings
from hashlib import md5
class UploadError(Exception):

View File

@ -1,7 +1,5 @@
from django.urls import include, path
from rest_framework.routers import SimpleRouter
from rest_framework_nested.routers import NestedSimpleRouter
from storage import views_api, views_client
router = SimpleRouter()

View File

@ -1,19 +1,11 @@
from common.constants import (
CONTENT_RANGE_HEADER,
CONTENT_RANGE_HEADER_PATTERN
)
# from common.utils import get_config
from common.constants import CONTENT_RANGE_HEADER, CONTENT_RANGE_HEADER_PATTERN
from django.core.exceptions import ValidationError
from rest_framework import status
from rest_framework.decorators import action
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from rest_framework.exceptions import NotFound
from rest_framework.exceptions import ValidationError as UserValidationError
from rest_framework.parsers import FileUploadParser
from django.core.exceptions import ValidationError
from rest_framework.response import Response
from rest_framework.viewsets import ModelViewSet
from storage.models import File, UploadError
from storage.serializers import FileSerializer
@ -36,7 +28,7 @@ class FileModelViewSet(ModelViewSet):
chunk_data = self.get_content_range(request)
if not chunk_data:
raise UserValidationError(
f"Missing content range headers"
"Missing content-range headers"
)
chunk_file = request.FILES["Content"]

View File

@ -1,7 +1,7 @@
from common.utils import get_config
from django.shortcuts import render
from django.views import View
# Static view
class FileUploadView(View):
def get(self, request):

View File

@ -1,9 +1,9 @@
from django.contrib import admin
from user.models import LockboxUser
class LockboxUserAdmin(admin.ModelAdmin):
readonly_fields = LockboxUser.readonly_fields
admin.site.register(LockboxUser, LockboxUserAdmin)

View File

@ -1,5 +1,4 @@
import pytest
from user.models import LockboxUser
@ -11,4 +10,4 @@ class TestUser:
def test_stub(self):
user = LockboxUser.objects.create(alias="TestUser", username="meow")
loaded_user = LockboxUser.objects.filter(alias="TestUser").first()
assert user.lid == loaded_user.lid
assert user.lid == loaded_user.lid

16
poetry.lock generated
View File

@ -201,6 +201,20 @@ files = [
{file = "iniconfig-2.0.0.tar.gz", hash = "sha256:2d91e135bf72d31a410b17c16da610a82cb55f6b0477d1a902134b24a455b8b3"},
]
[[package]]
name = "isort"
version = "5.13.2"
description = "A Python utility / library to sort Python imports."
optional = false
python-versions = ">=3.8.0"
files = [
{file = "isort-5.13.2-py3-none-any.whl", hash = "sha256:8ca5e72a8d85860d5a3fa69b8745237f2939afe12dbf656afbcb47fe72d947a6"},
{file = "isort-5.13.2.tar.gz", hash = "sha256:48fdfcb9face5d58a4f6dde2e72a1fb8dcaf8ab26f95ab49fab84c2ddefb0109"},
]
[package.extras]
colors = ["colorama (>=0.4.6)"]
[[package]]
name = "mccabe"
version = "0.7.0"
@ -373,4 +387,4 @@ brotli = ["brotli"]
[metadata]
lock-version = "2.0"
python-versions = "~3.12"
content-hash = "d8ff6440e16bd3eb499933ec438f2490a91e8caab975ab40505a64daab72cf9e"
content-hash = "155d31f2edffb6e6ea604c7a1115fa072072a5370e012eea577644e0a337f0b0"

View File

@ -19,6 +19,7 @@ pytest = "^8.0.0"
pytest-django = "^4.8.0"
pytest-cov = "^4.1.0"
flake8-pyproject = "^1.2.3"
isort = "^5.13.2"
[tool.pytest.ini_options]

View File

@ -7,6 +7,7 @@ drf-nested-routers==0.93.5 ; python_version >= "3.12" and python_version < "3.13
flake8-pyproject==1.2.3 ; python_version >= "3.12" and python_version < "3.13"
flake8==7.1.1 ; python_version >= "3.12" and python_version < "3.13"
iniconfig==2.0.0 ; python_version >= "3.12" and python_version < "3.13"
isort==5.13.2 ; python_version >= "3.12" and python_version < "3.13"
mccabe==0.7.0 ; python_version >= "3.12" and python_version < "3.13"
packaging==24.1 ; python_version >= "3.12" and python_version < "3.13"
pluggy==1.5.0 ; python_version >= "3.12" and python_version < "3.13"

View File

@ -1,2 +1,2 @@
printf "\n\n|| Starting ruff check ||\n\n"
ruff check --config=./pyproject.toml
printf "\n\n|| Starting lint check ||\n\n"
flake8