- permissions - all about the permission system - selected task - requirements for the task - list-wireframe - html mock of the page - tdd - tdd step through implemention
12 KiB
TDD Plan: Task List View with Filtering, Sorting, Pagination
Use this in LiveCompare — each step = one test + implementation cycle
Test File Location
NearBeach/tests/tests_views/tests_task/test_task_list.py
Run Single Test Command
cd /workspace/nearbeach
python3 manage.py test NearBeach.tests.tests_views.tests_task.test_task_list.TestTaskList.<test_method> -v 2
STEP 1: URL + Template Rendering
TEST PROMPT (send to model)
Write a test
test_task_list_url_accessibleintest_task_list.pythat:
- Creates a superuser
- Logs in the client
- GETs
/tasks/- Asserts status code 200
- Asserts template
NearBeach/tasks/task_list.htmlis used- Asserts "All Tasks" appears in response content
Run it — it should FAIL (no view/URL/template exists yet).
IMPL PROMPT (after test fails)
Implement the minimal code to make
test_task_list_url_accessiblepass:
- Add
task_list(request)view inNearBeach/views/task_views.pywith@login_required, returns render ofNearBeach/tasks/task_list.htmlwith context{"nearbeach_title": "All Tasks"}- Add URL route
path("tasks/", views.task_list, name="task_list")inNearBeach/urls.py- Create minimal template
NearBeach/templates/NearBeach/tasks/task_list.htmlextending base, showing "All Tasks" heading- Run the test again — should PASS
STEP 2: Permission Filtering (Core)
TEST PROMPT
Write test
test_task_list_filters_by_user_projects:
- Create two users:
user_alpha,user_beta- Create two groups:
group_alpha,group_betawithpermission_set__task=2- Create two projects:
project_alpha,project_beta- Create
ObjectAssignment(group_alpha, project_alpha)andObjectAssignment(group_beta, project_beta)- Create tasks:
task_alphainproject_alpha,task_betainproject_beta- Login as
user_alpha→ GET/tasks/→ asserttask_alphain response,task_betaNOT in response- Login as
user_beta→ GET/tasks/→ asserttask_betain response,task_alphaNOT in response- Login as superuser → GET
/tasks/→ assert BOTH tasks in response
IMPL PROMPT
Update
task_listview to filter tasks by user's project access viaObjectAssignment:
- Get user's groups:
UserGroup.objects.filter(is_deleted=False, username=request.user).values('group_id')- Get accessible project IDs:
ObjectAssignment.objects.filter(is_deleted=False, group_id__in=user_groups, project_id__isnull=False).values_list('project_id', flat=True).distinct()- If superuser:
Task.objects.filter(is_deleted=False)else:Task.objects.filter(is_deleted=False, project_id__in=accessible_project_ids)- Pass
tasksqueryset to template- Update template to loop through
tasksand displaytask_short_description- Run test — should PASS
STEP 3: Filter by Status
TEST PROMPT
Write test
test_task_list_filter_by_status:
- Setup: user with access to project, 3 tasks with different statuses (To Do, In Progress, Done)
- GET
/tasks/?status=in_progress→ assert only "In Progress" task shown- GET
/tasks/?status=todo&status=done→ assert To Do and Done shown, In Progress hidden- GET
/tasks/(no filter) → assert all 3 shown
IMPL PROMPT
Add status filtering to
task_listview:
- Create
TaskFilterForminforms.pywithstatus = forms.MultipleChoiceField(choices=ListOfTaskStatus.choices, required=False, widget=forms.CheckboxSelectMultiple)- In view: instantiate form with
request.GET, if valid applytasks_qs = tasks_qs.filter(task_status__in=form.cleaned_data['status'])when status provided- Pass
filter_formto template- Update template: render status checkboxes in sidebar, preserve other filters in form action
- Run test — should PASS
STEP 4: Filter by Assignee
TEST PROMPT
Write test
test_task_list_filter_by_assignee:
- Setup: user with project access, 2 assignees (user1, user2), 3 tasks (2 assigned to user1, 1 to user2, 1 unassigned)
- GET
/tasks/?assignee=user1_id→ assert only user1's tasks shown- GET
/tasks/?assignee=unassigned→ assert only unassigned task shown- GET
/tasks/?assignee=user1_id&assignee=unassigned→ assert both shown
IMPL PROMPT
Add assignee filtering:
- Add
assignee = forms.ChoiceField(choices=[("", "All Assignees"), ("unassigned", "Unassigned")] + dynamic user choices, required=False)toTaskFilterForm- In view: if
assignee == "unassigned"→tasks_qs.filter(assigned_user__isnull=True); elif assignee ID →tasks_qs.filter(assigned_user_id=assignee)- Populate assignee choices from users in accessible projects (or all users)
- Update template: assignee dropdown in sidebar
- Run test — should PASS
STEP 5: Filter by Project
TEST PROMPT
Write test
test_task_list_filter_by_project:
- Setup: user with access to 2 projects (project_a, project_b), tasks in each
- GET
/tasks/?project=project_a_id→ assert only project_a tasks shown- GET
/tasks/?project=project_b_id→ assert only project_b tasks shown
IMPL PROMPT
Add project filtering:
- Add
project = forms.ChoiceField(choices=[("", "All Projects")] + dynamic project choices, required=False)toTaskFilterForm- In view: if project selected →
tasks_qs.filter(project_id=project)- Project choices = user's accessible projects (from Step 2 queryset)
- Update template: project dropdown in sidebar
- Run test — should PASS
STEP 6: Filter by Date Range
TEST PROMPT
Write test
test_task_list_filter_by_date_range:
- Setup: tasks with start_date/end_date across October 2025
- GET
/tasks/?start_date=2025-10-15&end_date=2025-10-25→ assert only tasks with start_date >= 15th AND end_date <= 25th shown- GET
/tasks/?start_date=2025-10-01(only start) → assert tasks with start_date >= 1st- GET
/tasks/?end_date=2025-10-31(only end) → assert tasks with end_date <= 31st
IMPL PROMPT
Add date range filtering:
- Add
start_date = forms.DateField(required=False, widget=forms.DateInput(attrs={'type': 'date'}))andend_datetoTaskFilterForm- In view: if start_date →
tasks_qs.filter(task_start_date__gte=start_date); if end_date →tasks_qs.filter(task_end_date__lte=end_date)- Update template: two date inputs in sidebar
- Run test — should PASS
STEP 7: Sorting by Column Headers
TEST PROMPT
Write test
test_task_list_sorting:
- Setup: 5 tasks with different created, start_date, end_date, priority, status, project
- GET
/tasks/?sort=created→ assert tasks ordered by created ASC- GET
/tasks/?sort=-created→ assert tasks ordered by created DESC- GET
/tasks/?sort=priority→ assert priority order (High > Medium > Low)- GET
/tasks/?sort=project→ assert ordered by project name- Verify toggle: clicking same column again reverses order
IMPL PROMPT
Add sorting:
- Add
sort = forms.ChoiceField(choices=[("created", "Created"), ("-created", "Created ↓"), ("start_date", "Start Date"), ("-start_date", "Start Date ↓"), ("end_date", "End Date"), ("-end_date", "End Date ↓"), ("priority", "Priority"), ("-priority", "Priority ↓"), ("status", "Status"), ("-status", "Status ↓"), ("project", "Project"), ("-project", "Project ↓")], required=False)to form- In view: parse sort param, apply
.order_by(sort_field)to queryset- For priority: custom ordering using
Case/When(High=1, Medium=2, Low=3)- Update template: table headers as links with
?sort=...preserving other filters, show ▲/▼ indicator- Run test — should PASS
STEP 8: Pagination
TEST PROMPT
Write test
test_task_list_pagination:
- Setup: 50 tasks in user's project
- GET
/tasks/?page_size=10&page=1→ assert 10 tasks shown, page 1 active- GET
/tasks/?page_size=10&page=3→ assert tasks 21-30 shown- GET
/tasks/?page_size=25→ assert 25 tasks shown- GET
/tasks/?page_size=100→ assert all 50 shown (single page)- Verify page navigation links (prev/next, page numbers, ellipsis)
IMPL PROMPT
Add pagination:
- Add
page_size = forms.ChoiceField(choices=[(10, "10"), (25, "25"), (50, "50"), (100, "100")], required=False, initial=25)to form- In view: use
Paginator(tasks_qs, page_size), getpage_obj = paginator.get_page(page_number)- Pass
page_obj,paginator,page_sizeto template- Update template: pagination controls (prev/next, page numbers with ellipsis, page size selector)
- Run test — should PASS
STEP 9: Combined Filters + Sort + Pagination
TEST PROMPT
Write test
test_task_list_combined_filters_sort_pagination:
- Setup: 100 tasks across 3 projects, various statuses, assignees, dates
- GET
/tasks/?status=in_progress&project=proj1_id&sort=-priority&page_size=10&page=2- Assert: only In Progress tasks from proj1, sorted by priority DESC, page 2 (items 11-20)
IMPL PROMPT
Ensure all filters/sort/pagination work together:
- In view: apply filters → sort → paginate in that order
- Template: all filter/sort inputs in same
<form method="GET">, pagination links preserve all query params- Run test — should PASS
STEP 10: UI Permissions (user_level, user_group_permissions)
TEST PROMPT
Write test
test_task_list_ui_permissions:
- Setup: user with task permission level 1 (read only), user with level 3 (create)
- Login as level 1 → GET
/tasks/→ assert "New Task" button NOT in response- Login as level 3 → GET
/tasks/→ assert "New Task" button IS in response- Verify
user_levelin context equals max permission_set__task across accessible projects
IMPL PROMPT
Add permission context to template:
- In view: compute
user_level = UserGroup.objects.filter(...).aggregate(Max("permission_set__task"))["permission_set__task__max"] or 0- Pass
user_levelanduser_group_permissions = get_user_group_permission(request.user, ["task"])to template- Template:
{% if user_level >= 3 %}<a href="{% url 'new_task' %}">+ New Task</a>{% endif %}- Run test — should PASS
STEP 11: Empty State + Edge Cases
TEST PROMPT
Write test
test_task_list_edge_cases:
- User with no project access → GET
/tasks/→ assert "No tasks found" message, 0 tasks- Filter returns no results → assert "No tasks found"
- Invalid page number → redirects to last page
- Invalid sort param → defaults to created DESC
IMPL PROMPT
Handle edge cases:
- Template:
{% empty %}clause in task loop showing "No tasks found"- View:
Paginator.get_page()handles invalid pages gracefully- View: validate sort param against allowed list, default to
-created- Run test — should PASS
STEP 12: Full Test Suite Run
FINAL VERIFICATION PROMPT
Run the complete test suite:
python3 manage.py test NearBeach.tests.tests_views.tests_task -v 2Should report 10+ tests passing covering all verification steps from the task brief.
Quick Reference: Test Class Structure
# NearBeach/tests/tests_views/tests_task/test_task_list.py
from django.test import TestCase, Client
from django.urls import reverse
from django.contrib.auth import get_user_model
from NearBeach.models import *
class TestTaskList(TestCase):
def setUp(self):
# Common setup: users, groups, projects, ObjectAssignments, tasks
pass
def test_task_list_url_accessible(self):
pass # Step 1
def test_task_list_filters_by_user_projects(self):
pass # Step 2
def test_task_list_filter_by_status(self):
pass # Step 3
def test_task_list_filter_by_assignee(self):
pass # Step 4
def test_task_list_filter_by_project(self):
pass # Step 5
def test_task_list_filter_by_date_range(self):
pass # Step 6
def test_task_list_sorting(self):
pass # Step 7
def test_task_list_pagination(self):
pass # Step 8
def test_task_list_combined_filters_sort_pagination(self):
pass # Step 9
def test_task_list_ui_permissions(self):
pass # Step 10
def test_task_list_edge_cases(self):
pass # Step 11
LiveCompare Session Tips
- Send TEST PROMPT first → model writes test
- Run in Sandbox → confirm FAIL
- Send IMPL PROMPT → model implements
- Run in Sandbox → confirm PASS
- Commit/continue to next step
If model writes buggy implementation → test fails → you say "Test still fails, here's the error: [paste error]" → model fixes.
This gives you granular control and visible progress at each step.