refactor: reorganize folder structure for improved maintainability and readability

This commit is contained in:
Chneemann 2025-04-19 18:15:57 +02:00
parent 259dccef20
commit 59d5b842b6
38 changed files with 25 additions and 51 deletions

View file

@ -1,6 +1,6 @@
from django.apps import AppConfig from django.apps import AppConfig
class AuthConfig(AppConfig): class AuthAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = 'django.db.models.BigAutoField'
name = 'auth' name = 'auth_app'

View file

@ -2,7 +2,7 @@ from django.urls import reverse
from rest_framework import status from rest_framework import status
from rest_framework.test import APITestCase from rest_framework.test import APITestCase
from rest_framework.authtoken.models import Token from rest_framework.authtoken.models import Token
from users.models import CustomUser from user_app.models import CustomUser
class AuthTests(APITestCase): class AuthTests(APITestCase):
""" """

View file

@ -6,11 +6,11 @@ from rest_framework.authtoken.models import Token
from rest_framework.authtoken.views import ObtainAuthToken from rest_framework.authtoken.views import ObtainAuthToken
from django.contrib.auth import authenticate from django.contrib.auth import authenticate
from .serializer import LoginSerializer from .serializer import LoginSerializer
from users.serializer import UserSerializer from user_app.serializer import UserSerializer
from django.utils.html import strip_tags from django.utils.html import strip_tags
from django.core.mail import EmailMultiAlternatives from django.core.mail import EmailMultiAlternatives
from django.template.loader import render_to_string from django.template.loader import render_to_string
from users.models import CustomUser from user_app.models import CustomUser
from django.db.models import Q from django.db.models import Q
class LoginView(APIView): class LoginView(APIView):

View file

@ -1,6 +1,6 @@
from django.apps import AppConfig from django.apps import AppConfig
class UsersConfig(AppConfig): class UserAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = 'django.db.models.BigAutoField'
name = 'users' name = 'user_app'

View file

@ -2,7 +2,7 @@ import string
import secrets import secrets
from django.contrib.auth.models import AbstractUser from django.contrib.auth.models import AbstractUser
from django.db import models from django.db import models
from content.models import Video from video_app.models import Video
class CustomUser(AbstractUser): class CustomUser(AbstractUser):
verify_email_token = models.CharField(max_length=20, blank=True, null=True) verify_email_token = models.CharField(max_length=20, blank=True, null=True)

View file

@ -1,5 +1,3 @@
from django.http import JsonResponse
from django.shortcuts import render
from rest_framework.decorators import api_view, permission_classes from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response

View file

@ -1,9 +1,9 @@
from django.apps import AppConfig from django.apps import AppConfig
class ContentConfig(AppConfig): class VideoAppConfig(AppConfig):
default_auto_field = 'django.db.models.BigAutoField' default_auto_field = 'django.db.models.BigAutoField'
name = 'content' name = 'video_app'
def ready(self): def ready(self):
from . import signals from . import signals

View file

@ -3,6 +3,7 @@ from django.conf import settings
from datetime import date from datetime import date
from .class_assets import FILM_GENRES from .class_assets import FILM_GENRES
import os import os
class Video(models.Model): class Video(models.Model):
creator = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,default=1) creator = models.ForeignKey(settings.AUTH_USER_MODEL, on_delete=models.CASCADE,default=1)
created_at = models.DateField(default=date.today) created_at = models.DateField(default=date.today)

View file

@ -1,8 +1,6 @@
from django.test import TestCase from django.test import TestCase
from unittest.mock import patch, MagicMock from unittest.mock import patch, MagicMock
from .tasks import convert_video_to_hls, delete_original_video from .tasks import convert_video_to_hls, delete_original_video
from django.core.files.uploadedfile import SimpleUploadedFile
class VideoTasksTest(TestCase): class VideoTasksTest(TestCase):
@patch('subprocess.run') @patch('subprocess.run')

View file

@ -1,4 +1,3 @@
from django.shortcuts import render
from rest_framework.decorators import api_view, permission_classes from rest_framework.decorators import api_view, permission_classes
from rest_framework.permissions import IsAuthenticated from rest_framework.permissions import IsAuthenticated
from rest_framework.response import Response from rest_framework.response import Response
@ -7,7 +6,6 @@ from .models import Video
from django.core.cache.backends.base import DEFAULT_TIMEOUT from django.core.cache.backends.base import DEFAULT_TIMEOUT
from django.views.decorators.cache import cache_page from django.views.decorators.cache import cache_page
from django.conf import settings from django.conf import settings
from django.http import FileResponse, Http404
from rest_framework.parsers import MultiPartParser, FormParser from rest_framework.parsers import MultiPartParser, FormParser
from django.http import JsonResponse from django.http import JsonResponse
import os import os

View file

@ -1,22 +0,0 @@
#!/usr/bin/env python
"""Django's command-line utility for administrative tasks."""
import os
import sys
def main():
"""Run administrative tasks."""
os.environ.setdefault('DJANGO_SETTINGS_MODULE', 'videoflix.settings')
try:
from django.core.management import execute_from_command_line
except ImportError as exc:
raise ImportError(
"Couldn't import Django. Are you sure it's installed and "
"available on your PYTHONPATH environment variable? Did you "
"forget to activate a virtual environment?"
) from exc
execute_from_command_line(sys.argv)
if __name__ == '__main__':
main()

View file

@ -68,8 +68,8 @@ INSTALLED_APPS = [
'debug_toolbar', 'debug_toolbar',
'django_rq', 'django_rq',
'import_export', 'import_export',
'content.apps.ContentConfig', 'user_app',
'users', 'video_app.apps.VideoAppConfig',
] ]
MIDDLEWARE = [ MIDDLEWARE = [
@ -203,7 +203,8 @@ DEFAULT_AUTO_FIELD = 'django.db.models.BigAutoField'
# Auth # Auth
AUTH_EMAIL_VERIFICATION = True AUTH_EMAIL_VERIFICATION = True
AUTH_USER_MODEL = 'users.CustomUser'
AUTH_USER_MODEL = 'user_app.CustomUser'
# Rest Framework # Rest Framework
@ -214,7 +215,7 @@ REST_FRAMEWORK = {
} }
AUTHENTICATION_BACKENDS = ( AUTHENTICATION_BACKENDS = (
'auth.custom_backend.EmailBackend', 'auth_app.custom_backend.EmailBackend',
'django.contrib.auth.backends.ModelBackend', 'django.contrib.auth.backends.ModelBackend',
) )

View file

@ -18,8 +18,8 @@ from django.contrib import admin
from django.urls import path, include from django.urls import path, include
from django.conf import settings from django.conf import settings
from django.conf.urls.static import static from django.conf.urls.static import static
from users import views as user_views from user_app import views as user_views
from auth.views import ( from auth_app.views import (
LoginView, LoginView,
RegisterView, RegisterView,
VerifyEmailView, VerifyEmailView,
@ -27,7 +27,7 @@ from auth.views import (
ForgotPasswordView, ForgotPasswordView,
ChangePasswordView ChangePasswordView
) )
from content import views as content_views from video_app import views as video_views
from debug_toolbar.toolbar import debug_toolbar_urls from debug_toolbar.toolbar import debug_toolbar_urls
from django.contrib.staticfiles.urls import staticfiles_urlpatterns from django.contrib.staticfiles.urls import staticfiles_urlpatterns
@ -36,9 +36,9 @@ urlpatterns = [
path('django-rq/', include('django_rq.urls')), path('django-rq/', include('django_rq.urls')),
# Content URLs # Content URLs
path('content/', content_views.video_list, name='video_list'), path('video/', video_views.video_list, name='video_list'),
path('content/upload/', content_views.video_upload, name='video_upload'), path('video/upload/', video_views.video_upload, name='video_upload'),
path('content/movie/<int:id>/', content_views.check_video_resolutions, name='check_video_resolutions'), path('video/movie/<int:id>/', video_views.check_video_resolutions, name='check_video_resolutions'),
# Users URLs # Users URLs
path('users/', user_views.user_list, name='user_list'), path('users/', user_views.user_list, name='user_list'),

View file

@ -12,7 +12,7 @@ export class MovieService {
constructor(private http: HttpClient) {} constructor(private http: HttpClient) {}
getAllMovies(): Promise<any> { getAllMovies(): Promise<any> {
const url = environment.baseUrl + '/content/'; const url = environment.baseUrl + '/video/';
const headers = this.getAuthHeaders(); const headers = this.getAuthHeaders();
return lastValueFrom(this.http.get(url, { headers })); return lastValueFrom(this.http.get(url, { headers }));
} }
@ -24,7 +24,7 @@ export class MovieService {
} }
uploadMovie(formData: FormData) { uploadMovie(formData: FormData) {
const url = environment.baseUrl + '/content/upload/'; const url = environment.baseUrl + '/video/upload/';
const headers = this.getAuthHeaders(); const headers = this.getAuthHeaders();
return lastValueFrom(this.http.post(url, formData, { headers })); return lastValueFrom(this.http.post(url, formData, { headers }));
} }
@ -74,7 +74,7 @@ export class MovieService {
private fetchAndCacheResolutions( private fetchAndCacheResolutions(
videoID: number videoID: number
): Observable<{ [resolution: string]: boolean }> { ): Observable<{ [resolution: string]: boolean }> {
const url = `${environment.baseUrl}/content/movie/${videoID}/`; const url = `${environment.baseUrl}/video/movie/${videoID}/`;
const headers = this.getAuthHeaders(); const headers = this.getAuthHeaders();
return new Observable<{ [resolution: string]: boolean }>((observer) => { return new Observable<{ [resolution: string]: boolean }>((observer) => {