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 89dc526a69
commit ae97cfa30e
Signed by: kumi
GPG key ID: ECBCC9082395383F
53 changed files with 60 additions and 73 deletions

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,5 +1,5 @@
from django.db import models 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 from multiselectfield import MultiSelectField

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here. # 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 .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" 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.contrib.auth.mixins import LoginRequiredMixin
from django.shortcuts import get_object_or_404 from django.shortcuts import get_object_or_404
from django.urls import reverse_lazy from django.urls import reverse_lazy
@ -93,11 +92,11 @@ class DreamEditView(LoginRequiredMixin, UpdateView):
def form_valid(self, form): def form_valid(self, form):
for theme in form.cleaned_data["themes"]: for theme in form.cleaned_data["themes"]:
if theme.user == self.request.user: 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) DreamTheme.objects.create(theme=theme, dream=form.instance)
for dreamtheme in form.instance.dreamtheme_set.all(): 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() dreamtheme.delete()
for attachment in form.cleaned_data["uploads"]: for attachment in form.cleaned_data["uploads"]:

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -1,3 +1,2 @@
from django.db import models
# Create your models here. # 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") features = import_module(f"{module}.features")
try: try:
sections += features.NAV_SECTIONS sections += features.NAV_SECTIONS
except: except Exception:
pass pass
except: except Exception:
pass pass
return """ return """

View file

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

View file

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

View file

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

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here. # 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.utils import timezone
from django.contrib.gis.geos import Point from django.contrib.gis.geos import Point
from .models import GPSTrack, GPSToken, GPSPoint from .models import GPSTrack, GPSToken
class GPSLogView(LoginRequiredMixin, View): class GPSLogView(LoginRequiredMixin, View):
# TODO: Finish this view
def dispatch(self, request, *args, **kwargs): def dispatch(self, request, *args, **kwargs):
self.gps_track = get_object_or_404(GPSTrack, id=self.kwargs["track"]) self.gps_track = get_object_or_404(GPSTrack, id=self.kwargs["track"])
self.gps_token = get_object_or_404( self.gps_token = get_object_or_404(
@ -27,11 +28,9 @@ class GPSLogView(LoginRequiredMixin, View):
alt = request.GET.get("alt", None) alt = request.GET.get("alt", None)
point = Point(lat, lon, alt) point = Point(lat, lon, alt) # noqa: F841
tst = request.GET.get("tst", timezone.now().timestamp())
tst = request.GET.get("tst", timezone.now().timestamp()) # noqa: F841
def post(self, request, *args, **kwargs): def post(self, request, *args, **kwargs):
pass pass

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

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

View file

@ -131,13 +131,13 @@ class StatusEditView(LoginRequiredMixin, UpdateView):
for activity in form.cleaned_data["activities"]: for activity in form.cleaned_data["activities"]:
if activity.user == self.request.user: 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( StatusActivity.objects.create(
activity=activity, status=form.instance activity=activity, status=form.instance
) )
for statusactivity in form.instance.statusactivity_set.all(): 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() statusactivity.delete()
return super().form_valid(form) return super().form_valid(form)
@ -419,7 +419,8 @@ class MoodStatisticsView(LoginRequiredMixin, TemplateView):
if startdate: if startdate:
mindate = datetime.strptime(startdate, "%Y-%m-%d") mindate = datetime.strptime(startdate, "%Y-%m-%d")
else: 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 = super().get_context_data(**kwargs)
context["title"] = "Statistics" context["title"] = "Statistics"

View file

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

View file

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

View file

@ -15,7 +15,7 @@ def send_notifications(sender, **kwargs):
returns.append(notification.send()) returns.append(notification.send())
datetime.sent = True datetime.sent = True
datetime.save() datetime.save()
except: except Exception:
pass # TODO: Implement some sort of error logging / admin notification pass # TODO: Implement some sort of error logging / admin notification
for daily in notification.notificationdailyschedule_set.all(): 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(): 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()) returns.append(notification.send())
daily.last_sent = localtime(now()).date() daily.last_sent = localtime(now()).date()
daily.save() daily.save()
except: except Exception:
pass # TODO: See above pass # TODO: See above
return returns 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 from dbsettings.functions import dbsettings

View file

@ -1,3 +1,2 @@
from django.test import TestCase
# Create your tests here. # 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