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.
```
This commit is contained in:
sankalp committed 2025-12-18 21:38:26 +05:45
1 parent 96629b26b3
commit e8f0a89bfd
2 files changed
+15 -33

No files matched your search

-24
View File
@@ -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/<int:pk>/edit/", views.note_edit, name="note_edit"),
path("notes/<int:pk>/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/<int:pk>/edit/", views.timeentry_edit, name="timeentry_edit"),
path(
"time-entries/<int:pk>/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",
),
]
+15 -9
View File
@@ -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")