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.
This commit is contained in:
Kumi 2024-06-02 20:27:02 +02:00
parent 9fbfe583be
commit ff70221553
53 changed files with 60 additions and 73 deletions

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,3 +1,2 @@
from django.db import models
# Create your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -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

View file

@ -1,3 +1,2 @@
from django.db import models
# Create your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.shortcuts import render
# Create your views here.

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,3 +1,2 @@
from django.db import models
# Create your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -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"

View file

@ -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"]:

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,3 +1,2 @@
from django.db import models
# Create your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.shortcuts import render
# Create your views here.

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,3 +1,2 @@
from django.db import models
# Create your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.shortcuts import render
# Create your views here.

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -16,7 +16,7 @@ class NavSection:
self.items.sort(key=lambda x: x.order)
for item in self.items:
html += f"""
html += """
<!-- Nav Item -->
<li class="nav-item""" + (" active" if item.name == active else "") + f"""">
<a class="nav-link" href="{item.url}">

View file

@ -1,3 +1,2 @@
from django.db import models
# Create your models here.

View file

@ -0,0 +1,32 @@
.heatmap-container {
height: 150px;
}
.card {
border-radius: 10px; /* Rounded corners */
}
.card-header {
background-color: #f8f9fc; /* Light background for headers */
border-bottom: none; /* Remove border */
}
.card-body {
padding: 1.5rem; /* Increase padding */
}
.text-uppercase {
letter-spacing: 0.05em; /* Slightly increased letter spacing */
}
.h5 {
font-size: 1.25rem; /* Slightly larger font size */
}
.mb-4 {
margin-bottom: 1.5rem !important; /* Consistent spacing */
}
.shadow-sm {
box-shadow: 0 0.125rem 0.25rem rgba(0, 0, 0, 0.075) !important; /* Subtle shadow */
}

View file

@ -15,9 +15,9 @@ def sidebar_nav():
features = import_module(f"{module}.features")
try:
sections += features.NAV_SECTIONS
except:
except Exception:
pass
except:
except Exception:
pass
return """

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,6 +1,6 @@
from .views import DashboardView, UserRegistrationView
from django.urls import path, include
from django.urls import path
app_name = "frontend"

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -4,10 +4,11 @@ from django.shortcuts import get_object_or_404
from django.utils import timezone
from django.contrib.gis.geos import Point
from .models import GPSTrack, GPSToken, GPSPoint
from .models import GPSTrack, GPSToken
class GPSLogView(LoginRequiredMixin, View):
# TODO: Finish this view
def dispatch(self, request, *args, **kwargs):
self.gps_track = get_object_or_404(GPSTrack, id=self.kwargs["track"])
self.gps_token = get_object_or_404(
@ -27,11 +28,9 @@ class GPSLogView(LoginRequiredMixin, View):
alt = request.GET.get("alt", None)
point = Point(lat, lon, alt)
tst = request.GET.get("tst", timezone.now().timestamp())
point = Point(lat, lon, alt) # noqa: F841
tst = request.GET.get("tst", timezone.now().timestamp()) # noqa: F841
def post(self, request, *args, **kwargs):
pass

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.shortcuts import render
# Create your views here.

View file

@ -1,3 +1,2 @@
from django.contrib import admin
# Register your models here.

View file

@ -35,12 +35,12 @@ class Medication(models.Model):
prn = models.BooleanField(default=False)
remarks = models.TextField(null=True, blank=True)
class MedicationSchedule(models.Model):
class ScheduleChoices(models.IntegerChoices):
class ScheduleChoices(models.IntegerChoices):
DAYS = 0
WEEKS = 1
MONTHS = 2
class MedicationSchedule(models.Model):
medication = models.ForeignKey(Medication, models.CASCADE)
cycle_type = models.IntegerField(choices=ScheduleChoices.choices)

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,3 +1,2 @@
from django.shortcuts import render
# Create your views here.

View file

@ -72,7 +72,7 @@ def activitystats(user):
for status in Status.objects.filter(user=user):
for activity in status.activity_set:
if not activity in output.keys():
if activity not in output.keys():
output[activity] = {
"alltime": 0,
"yearly": 0,
@ -275,8 +275,6 @@ def activitymood(activity):
def activitypies(activity):
hv.extension("bokeh")
maxdate = timezone.now()
sa = StatusActivity.objects.filter(activity=activity)
weekly = dict()

View file

@ -56,7 +56,7 @@ def average_mood(context, start, end=None, daily_averages=True):
for status in status_list:
if status.mood:
if daily_averages:
if not status.timestamp.date() in moods.keys():
if status.timestamp.date() not in moods.keys():
moods[status.timestamp.date()] = [status.mood.value]
else:
moods[status.timestamp.date()].append(status.mood.value)

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -24,7 +24,7 @@ from .views import (
MoodCountHeatmapJSONView,
)
from django.urls import path, include
from django.urls import path
app_name = "mood"

View file

@ -131,13 +131,13 @@ class StatusEditView(LoginRequiredMixin, UpdateView):
for activity in form.cleaned_data["activities"]:
if activity.user == self.request.user:
if not activity in form.instance.activity_set:
if activity not in form.instance.activity_set:
StatusActivity.objects.create(
activity=activity, status=form.instance
)
for statusactivity in form.instance.statusactivity_set.all():
if not statusactivity.activity in form.cleaned_data["activities"]:
if statusactivity.activity not in form.cleaned_data["activities"]:
statusactivity.delete()
return super().form_valid(form)
@ -419,7 +419,8 @@ class MoodStatisticsView(LoginRequiredMixin, TemplateView):
if startdate:
mindate = datetime.strptime(startdate, "%Y-%m-%d")
else:
mindate = maxdate - relativedelta.relativedelta(weeks=1)
mindate = maxdate - relativedelta.relativedelta(weeks=1) # noqa: F841
# TODO: Do something with this...?
context = super().get_context_data(**kwargs)
context["title"] = "Statistics"

View file

@ -1,7 +1,5 @@
from django.views.generic import View
from django.dispatch import receiver
import json
import asyncio
from nio import AsyncClient

View file

@ -1,7 +1,6 @@
from django.views.generic import View
from django.dispatch import receiver
import json
import telegram

View file

@ -15,7 +15,7 @@ def send_notifications(sender, **kwargs):
returns.append(notification.send())
datetime.sent = True
datetime.save()
except:
except Exception:
pass # TODO: Implement some sort of error logging / admin notification
for daily in notification.notificationdailyschedule_set.all():
if ((not daily.last_sent) or daily.last_sent < localtime(now()).date()) and daily.time <= localtime(now()).time():
@ -23,7 +23,7 @@ def send_notifications(sender, **kwargs):
returns.append(notification.send())
daily.last_sent = localtime(now()).date()
daily.save()
except:
except Exception:
pass # TODO: See above
return returns

View file

@ -1,4 +1,4 @@
from django.core.management.base import BaseCommand, CommandError
from django.core.management.base import BaseCommand
from dbsettings.functions import dbsettings

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here.

View file

@ -1,6 +1,2 @@
from .handler import send_notifications
from .gateways.telegram import TelegramWebhookView
import msgio.gateways.matrix
import msgio.gateways.telegram

View file

@ -1 +0,0 @@
from kumify.wsgi import application