diff --git a/test_settings.py b/test_settings.py index e1daff6..26bc9c6 100644 --- a/test_settings.py +++ b/test_settings.py @@ -13,7 +13,7 @@ EMAIL_BACKEND = 'django.core.mail.backends.console.EmailBackend' # Document TODO_STAFF_ONLY = False -TODO_DEFAULT_LIST_ID = None +TODO_DEFAULT_LIST_SLUG = 'tickets' TODO_DEFAULT_ASSIGNEE = None TODO_PUBLIC_SUBMIT_REDIRECT = '/' diff --git a/todo/management/commands/hopper.py b/todo/management/commands/hopper.py index 129be01..f001b41 100644 --- a/todo/management/commands/hopper.py +++ b/todo/management/commands/hopper.py @@ -86,9 +86,10 @@ class Command(BaseCommand): user.groups.add(bw_group) user.groups.add(sd_group) - # Create lists with tasks + # Create lists with tasks, plus one with fixed name for externally added tasks TaskListFactory.create_batch(5, group=bw_group) TaskListFactory.create_batch(5, group=sd_group) + TaskListFactory.create(name="Public Tickets", slug="tickets", group=bw_group) print("For each of two groups, created fake tasks in each of {} fake lists.".format(num_lists)) diff --git a/todo/tests/test_views.py b/todo/tests/test_views.py index 2415d17..74724d1 100644 --- a/todo/tests/test_views.py +++ b/todo/tests/test_views.py @@ -32,8 +32,8 @@ def test_view_reorder(todo_setup, admin_client): def test_view_external_add(todo_setup, admin_client, settings): default_list = TaskList.objects.first() - settings.TODO_DEFAULT_LIST_ID = default_list.id - assert settings.TODO_DEFAULT_LIST_ID == default_list.id + settings.TODO_DEFAULT_LIST_SLUG = default_list.slug + assert settings.TODO_DEFAULT_LIST_SLUG == default_list.slug url = reverse('todo:external_add') response = admin_client.get(url) assert response.status_code == 200 diff --git a/todo/views.py b/todo/views.py index 4bbe958..9060185 100644 --- a/todo/views.py +++ b/todo/views.py @@ -349,11 +349,11 @@ def external_add(request) -> HttpResponse: Publicly filed tickets are unassigned unless settings.DEFAULT_ASSIGNEE exists. """ - if not settings.TODO_DEFAULT_LIST_ID: - raise RuntimeError("This feature requires TODO_DEFAULT_LIST_ID: in settings. See documentation.") + if not settings.TODO_DEFAULT_LIST_SLUG: + raise RuntimeError("This feature requires TODO_DEFAULT_LIST_SLUG: in settings. See documentation.") - if not TaskList.objects.filter(id=settings.TODO_DEFAULT_LIST_ID).exists(): - raise RuntimeError("There is no TaskList with ID specified for DEFAULT_LIST_ID in settings.") + if not TaskList.objects.filter(slug=settings.TODO_DEFAULT_LIST_SLUG).exists(): + raise RuntimeError("There is no TaskList with slug specified for TODO_DEFAULT_LIST_SLUG in settings.") if request.POST: form = AddExternalTaskForm(request.POST) @@ -361,7 +361,7 @@ def external_add(request) -> HttpResponse: if form.is_valid(): current_site = Site.objects.get_current() task = form.save(commit=False) - task.task_list = TaskList.objects.get(id=settings.TODO_DEFAULT_LIST_ID) + task.task_list = TaskList.objects.get(slug=settings.TODO_DEFAULT_LIST_SLUG) task.created_by = request.user if settings.TODO_DEFAULT_ASSIGNEE: task.assigned_to = User.objects.get(username=settings.TODO_DEFAULT_ASSIGNEE)