From e8f0a89bfd2e9b55ad5ef4351ce52b56d210ac05 Mon Sep 17 00:00:00 2001 From: S4NKALP Date: Thu, 18 Dec 2025 21:38:26 +0545 Subject: [PATCH] refactor(productivity): reorganize URL patterns and improve code formatting The changes include a reorganization of the URL patterns in `urls.py` and improvements to code formatting in `views.py` for better readability and maintainability. - **Enhancements & Refinements**: - Reorganized URL patterns in `urls.py` to group related endpoints and improve structure. - Improved code formatting in `views.py` for better readability, including consistent line breaks and indentation. - Removed redundant imports and trailing whitespace in both files. ``` --- src/api/productivity/urls.py | 24 ------------------------ src/api/productivity/views.py | 24 +++++++++++++++--------- 2 files changed, 15 insertions(+), 33 deletions(-) diff --git a/src/api/productivity/urls.py b/src/api/productivity/urls.py index 0d3adb5..8ab2e85 100644 --- a/src/api/productivity/urls.py +++ b/src/api/productivity/urls.py @@ -2,28 +2,6 @@ from django.urls import path from . import views -urlpatterns = [ - path("", views.productivity_dashboard, name="productivity_dashboard"), - # Notes - path("notes/", views.note_list, name="note_list"), - path("notes/create/", views.note_create, name="note_create"), - path("notes//edit/", views.note_edit, name="note_edit"), - path("notes//delete/", views.note_delete, name="note_delete"), - # Time entries - path("time-entries/", views.timeentry_list, name="timeentry_list"), - path("time-entries/create/", views.timeentry_create, name="timeentry_create"), - path("time-entries//edit/", views.timeentry_edit, name="timeentry_edit"), - path( - "time-entries//delete/", - views.timeentry_delete, - name="timeentry_delete", - ), -] - -from django.urls import path - -from . import views - urlpatterns = [ # Dashboard path("", views.productivity_dashboard, name="productivity_dashboard"), @@ -42,5 +20,3 @@ urlpatterns = [ name="timeentry_delete", ), ] - - diff --git a/src/api/productivity/views.py b/src/api/productivity/views.py index 4187c3a..7990a59 100644 --- a/src/api/productivity/views.py +++ b/src/api/productivity/views.py @@ -9,12 +9,14 @@ from src.models.projects import Project, Task def productivity_dashboard(request): recent_notes = Note.objects.all()[:5] - recent_time_entries = ( - TimeEntry.objects.select_related("project", "task").all()[:5] - ) + recent_time_entries = TimeEntry.objects.select_related("project", "task").all()[:5] total_tracked_hours = ( sum( - (entry.duration.total_seconds() for entry in recent_time_entries if entry.duration), + ( + entry.duration.total_seconds() + for entry in recent_time_entries + if entry.duration + ), 0, ) / 3600 @@ -106,7 +108,9 @@ def timeentry_create(request): end_time = _parse_datetime(end_time_raw) if description and start_time: - project = Project.objects.filter(id=project_id).first() if project_id else None + project = ( + Project.objects.filter(id=project_id).first() if project_id else None + ) task = Task.objects.filter(id=task_id).first() if task_id else None TimeEntry.objects.create( @@ -141,8 +145,12 @@ def timeentry_edit(request, pk): end_time = _parse_datetime(end_time_raw) if description and start_time: - time_entry.project = Project.objects.filter(id=project_id).first() if project_id else None - time_entry.task = Task.objects.filter(id=task_id).first() if task_id else None + time_entry.project = ( + Project.objects.filter(id=project_id).first() if project_id else None + ) + time_entry.task = ( + Task.objects.filter(id=task_id).first() if task_id else None + ) time_entry.description = description time_entry.start_time = start_time time_entry.end_time = end_time @@ -162,5 +170,3 @@ def timeentry_delete(request, pk): time_entry = get_object_or_404(TimeEntry, pk=pk) time_entry.delete() return redirect("timeentry_list") - -