From ff702215538d85699f14c19a39438015d4de74a3 Mon Sep 17 00:00:00 2001 From: Kumi Date: Sun, 2 Jun 2024 20:27:02 +0200 Subject: [PATCH] refactor: clean up unused imports and improve code quality Removed unnecessary imports across various modules to streamline the application's dependencies and improve loading times. Specific changes include the removal of unused Django model and admin imports in several apps, simplifying view imports by eliminating unutilized components, and cleaning up static CSS for better maintainability. Corrections were made to conditional expressions for clearer logic. The removal of the django.test.TestCase import in test files reflects a shift towards a different testing strategy or the current lack of tests. Exception handling has been made more explicit to avoid catching unintended exceptions, paving the way for more robust error handling and logging in the future. Additionally, a new CSS file was added for frontend enhancements, indicating ongoing UI/UX improvements. These changes collectively aim to make the codebase more maintainable and efficient, reducing clutter and focusing on used functionalities. It's a step towards optimizing the application's performance and ensuring a clean, manageable codebase for future development. --- api/admin.py | 1 - api/models.py | 1 - api/tests.py | 1 - cbt/admin.py | 1 - cbt/tests.py | 1 - common/admin.py | 1 - common/fields.py | 2 +- common/models.py | 1 - common/tests.py | 1 - common/views.py | 1 - cronhandler/admin.py | 1 - cronhandler/models.py | 1 - cronhandler/tests.py | 1 - dreams/tests.py | 1 - dreams/urls.py | 2 +- dreams/views.py | 7 +++-- environment/admin.py | 1 - environment/models.py | 1 - environment/tests.py | 1 - environment/views.py | 1 - friends/admin.py | 1 - friends/models.py | 1 - friends/tests.py | 1 - friends/views.py | 1 - frontend/admin.py | 1 - frontend/classes.py | 2 +- frontend/models.py | 1 - frontend/static/frontend/css/frontend.css | 32 +++++++++++++++++++++++ frontend/templatetags/navigation.py | 4 +-- frontend/tests.py | 1 - frontend/urls.py | 2 +- gpslog/admin.py | 1 - gpslog/tests.py | 1 - gpslog/views.py | 9 +++---- habits/admin.py | 1 - habits/tests.py | 1 - habits/views.py | 1 - health/admin.py | 1 - health/models.py | 10 +++---- health/tests.py | 1 - health/views.py | 1 - mood/statistics.py | 4 +-- mood/templatetags/mood_stats.py | 2 +- mood/tests.py | 1 - mood/urls.py | 2 +- mood/views.py | 7 ++--- msgio/gateways/matrix.py | 2 -- msgio/gateways/telegram.py | 1 - msgio/handler.py | 4 +-- msgio/management/commands/telegram.py | 2 +- msgio/tests.py | 1 - msgio/views.py | 4 --- passenger_wsgi.py | 1 - 53 files changed, 60 insertions(+), 73 deletions(-) create mode 100644 frontend/static/frontend/css/frontend.css diff --git a/api/admin.py b/api/admin.py index 8c38f3f..b97a94f 100644 --- a/api/admin.py +++ b/api/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin # Register your models here. diff --git a/api/models.py b/api/models.py index 71a8362..35e0d64 100644 --- a/api/models.py +++ b/api/models.py @@ -1,3 +1,2 @@ -from django.db import models # Create your models here. diff --git a/api/tests.py b/api/tests.py index 7ce503c..4929020 100644 --- a/api/tests.py +++ b/api/tests.py @@ -1,3 +1,2 @@ -from django.test import TestCase # Create your tests here. diff --git a/cbt/admin.py b/cbt/admin.py index 8c38f3f..b97a94f 100644 --- a/cbt/admin.py +++ b/cbt/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin # Register your models here. diff --git a/cbt/tests.py b/cbt/tests.py index 7ce503c..4929020 100644 --- a/cbt/tests.py +++ b/cbt/tests.py @@ -1,3 +1,2 @@ -from django.test import TestCase # Create your tests here. diff --git a/common/admin.py b/common/admin.py index 8c38f3f..b97a94f 100644 --- a/common/admin.py +++ b/common/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin # Register your models here. diff --git a/common/fields.py b/common/fields.py index 4f1593c..6b11e00 100644 --- a/common/fields.py +++ b/common/fields.py @@ -1,5 +1,5 @@ from django.db import models -from django.core.validators import MinValueValidator, MaxValueValidator, validate_comma_separated_integer_list +from django.core.validators import MinValueValidator, MaxValueValidator from multiselectfield import MultiSelectField diff --git a/common/models.py b/common/models.py index 71a8362..35e0d64 100644 --- a/common/models.py +++ b/common/models.py @@ -1,3 +1,2 @@ -from django.db import models # Create your models here. diff --git a/common/tests.py b/common/tests.py index 7ce503c..4929020 100644 --- a/common/tests.py +++ b/common/tests.py @@ -1,3 +1,2 @@ -from django.test import TestCase # Create your tests here. diff --git a/common/views.py b/common/views.py index 91ea44a..b8e4ee0 100644 --- a/common/views.py +++ b/common/views.py @@ -1,3 +1,2 @@ -from django.shortcuts import render # Create your views here. diff --git a/cronhandler/admin.py b/cronhandler/admin.py index 8c38f3f..b97a94f 100644 --- a/cronhandler/admin.py +++ b/cronhandler/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin # Register your models here. diff --git a/cronhandler/models.py b/cronhandler/models.py index 71a8362..35e0d64 100644 --- a/cronhandler/models.py +++ b/cronhandler/models.py @@ -1,3 +1,2 @@ -from django.db import models # Create your models here. diff --git a/cronhandler/tests.py b/cronhandler/tests.py index 7ce503c..4929020 100644 --- a/cronhandler/tests.py +++ b/cronhandler/tests.py @@ -1,3 +1,2 @@ -from django.test import TestCase # Create your tests here. diff --git a/dreams/tests.py b/dreams/tests.py index 7ce503c..4929020 100644 --- a/dreams/tests.py +++ b/dreams/tests.py @@ -1,3 +1,2 @@ -from django.test import TestCase # Create your tests here. diff --git a/dreams/urls.py b/dreams/urls.py index 0375aab..b51ef56 100644 --- a/dreams/urls.py +++ b/dreams/urls.py @@ -1,6 +1,6 @@ from .views import DreamListView, DreamViewView, DreamDeleteView, DreamEditView, DreamCreateView, ThemeListView, ThemeEditView, ThemeCreateView, ThemeDeleteView, NotificationCreateView, NotificationDeleteView, NotificationEditView, NotificationListView -from django.urls import path, include +from django.urls import path app_name = "dreams" diff --git a/dreams/views.py b/dreams/views.py index bcf46f9..d87ccaf 100644 --- a/dreams/views.py +++ b/dreams/views.py @@ -1,6 +1,5 @@ -from django.shortcuts import render -from django.views.generic import TemplateView, ListView, UpdateView, DetailView, CreateView, DeleteView +from django.views.generic import ListView, UpdateView, DetailView, CreateView, DeleteView from django.contrib.auth.mixins import LoginRequiredMixin from django.shortcuts import get_object_or_404 from django.urls import reverse_lazy @@ -93,11 +92,11 @@ class DreamEditView(LoginRequiredMixin, UpdateView): def form_valid(self, form): for theme in form.cleaned_data["themes"]: if theme.user == self.request.user: - if not theme in form.instance.theme_set: + if theme not in form.instance.theme_set: DreamTheme.objects.create(theme=theme, dream=form.instance) for dreamtheme in form.instance.dreamtheme_set.all(): - if not dreamtheme.theme in form.cleaned_data["themes"]: + if dreamtheme.theme not in form.cleaned_data["themes"]: dreamtheme.delete() for attachment in form.cleaned_data["uploads"]: diff --git a/environment/admin.py b/environment/admin.py index 8c38f3f..b97a94f 100644 --- a/environment/admin.py +++ b/environment/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin # Register your models here. diff --git a/environment/models.py b/environment/models.py index 71a8362..35e0d64 100644 --- a/environment/models.py +++ b/environment/models.py @@ -1,3 +1,2 @@ -from django.db import models # Create your models here. diff --git a/environment/tests.py b/environment/tests.py index 7ce503c..4929020 100644 --- a/environment/tests.py +++ b/environment/tests.py @@ -1,3 +1,2 @@ -from django.test import TestCase # Create your tests here. diff --git a/environment/views.py b/environment/views.py index 91ea44a..b8e4ee0 100644 --- a/environment/views.py +++ b/environment/views.py @@ -1,3 +1,2 @@ -from django.shortcuts import render # Create your views here. diff --git a/friends/admin.py b/friends/admin.py index 8c38f3f..b97a94f 100644 --- a/friends/admin.py +++ b/friends/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin # Register your models here. diff --git a/friends/models.py b/friends/models.py index 71a8362..35e0d64 100644 --- a/friends/models.py +++ b/friends/models.py @@ -1,3 +1,2 @@ -from django.db import models # Create your models here. diff --git a/friends/tests.py b/friends/tests.py index 7ce503c..4929020 100644 --- a/friends/tests.py +++ b/friends/tests.py @@ -1,3 +1,2 @@ -from django.test import TestCase # Create your tests here. diff --git a/friends/views.py b/friends/views.py index 91ea44a..b8e4ee0 100644 --- a/friends/views.py +++ b/friends/views.py @@ -1,3 +1,2 @@ -from django.shortcuts import render # Create your views here. diff --git a/frontend/admin.py b/frontend/admin.py index 8c38f3f..b97a94f 100644 --- a/frontend/admin.py +++ b/frontend/admin.py @@ -1,3 +1,2 @@ -from django.contrib import admin # Register your models here. diff --git a/frontend/classes.py b/frontend/classes.py index 421a950..5e45322 100644 --- a/frontend/classes.py +++ b/frontend/classes.py @@ -16,7 +16,7 @@ class NavSection: self.items.sort(key=lambda x: x.order) for item in self.items: - html += f""" + html += """