Repository: carpentries/amy

Issue:
Link to tasks by ID
Since a70f8f7a (Adding display of tasks - editing still fails, 2014-12-11, #55), we've been linking to tasks with:

```
task/{event_slug}/{person_id}/{role_name}
```

This seems uneccessarily complicated to me, resulting in templated links like:

```
{% url 'task_details' task.event.slug task.person.id task.role.name %}
```

which could be just:

```
{% url 'task_details' task.id %}
```

How do we feel about simpler ID-based URLs here?



Discussion:
I don't want to lose the mnemonic URLs - I'd be happy if two different 
URLs (one mnemonic, one by task ID) went to the same place.

On Sun, Jan 18, 2015 at 12:18:22PM -0800, Greg Wilson wrote:

> I don't want to lose the mnemonic URLs - I'd be happy if two
> different URLs (one mnemonic, one by task ID) went to the same
> place.

Is it a mnemonic URL if there's a person ID in it?  If we were using:

  task/{event_slug}/{person_slug}/{role_name}

I think that argument would have more weight, but then we'd have to
require person slugs, and we're not doing that now [1](https://github.com/swcarpentry/amy/pull/125#issuecomment-69143688).

Good point.  Sure, make the change.
G

On 2015-01-18 4:12 PM, W. Trevor King wrote:

> On Sun, Jan 18, 2015 at 12:18:22PM -0800, Greg Wilson wrote:
> 
> > I don't want to lose the mnemonic URLs - I'd be happy if two
> > different URLs (one mnemonic, one by task ID) went to the same
> > place.
> 
> Is it a mnemonic URL if there's a person ID in it? If we were using:
> 
> task/{event_slug}/{person_slug}/{role_name}
> 
> I think that argument would have more weight, but then we'd have to
> require person slugs, and we're not doing that now [1].
> 
> [1]: https://github.com/swcarpentry/amy/pull/125#issuecomment-69143688
> 
> —
> Reply to this email directly or view it on GitHub 
> https://github.com/swcarpentry/amy/issues/153#issuecomment-70426207.

## 

Dr. Greg Wilson    | gvwilson@software-carpentry.org
Software Carpentry | http://software-carpentry.org


Resolving patch:
diff --git a/workshops/models.py b/workshops/models.py
--- a/workshops/models.py
+++ b/workshops/models.py
@@ -282,9 +282,7 @@ def __str__(self):
         return '{0}/{1}={2}'.format(self.event, self.person, self.role)
 
     def get_absolute_url(self):
-        return reverse('task_details', kwargs={'event_slug':str(self.event),
-                                               'person_id':self.person.pk,
-                                               'role_name':str(self.role)})
+        return reverse('task_details', kwargs={'task_id': self.id})
 
 #------------------------------------------------------------
 
diff --git a/workshops/urls.py b/workshops/urls.py
--- a/workshops/urls.py
+++ b/workshops/urls.py
@@ -27,8 +27,8 @@
     url(r'^event/(?P<event_ident>[\w-]+)/validate/?$', views.validate_event, name='validate_event'),
 
     url(r'^tasks/?$', views.all_tasks, name='all_tasks'),
-    url(r'^task/(?P<event_slug>[\w-]+)/(?P<person_id>[\w\.-]+)/(?P<role_name>[\w-]+)/?$', views.task_details, name='task_details'),
-    url(r'^task/(?P<event_slug>[\w-]+)/(?P<person_id>[\w\.-]+)/(?P<role_name>[\w-]+)/edit$', views.TaskUpdate.as_view(), name='task_edit'),
+    url(r'^task/(?P<task_id>\d+)/?', views.task_details, name='task_details'),
+    url(r'^task/(?P<task_id>\d+)/edit$', views.TaskUpdate.as_view(), name='task_edit'),
     url(r'^tasks/add/$', views.TaskCreate.as_view(), name='task_add'),
 
     url(r'^badges/?$', views.all_badges, name='all_badges'),
diff --git a/workshops/views.py b/workshops/views.py
--- a/workshops/views.py
+++ b/workshops/views.py
@@ -316,9 +316,9 @@ def all_tasks(request):
     return render(request, 'workshops/all_tasks.html', context)
 
 
-def task_details(request, event_slug, person_id, role_name):
+def task_details(request, task_id):
     '''List details of a particular task.'''
-    task = Task.objects.get(event__slug=event_slug, person__id=person_id, role__name=role_name)
+    task = Task.objects.get(pk=task_id)
     context = {'title' : 'Task {0}'.format(task),
                'task' : task}
     return render(request, 'workshops/task.html', context)
@@ -334,17 +334,6 @@ class TaskUpdate(UpdateViewContext):
     fields = TASK_FIELDS
     pk_url_kwarg = 'task_id'
 
-    def get_object(self):
-        """
-        Returns the object the view is displaying.
-        """
-
-        event_slug = self.kwargs.get('event_slug', None)
-        person_id = self.kwargs.get('person_id', None)
-        role_name = self.kwargs.get('role_name', None)
-
-        return get_object_or_404(Task, event__slug=event_slug, person__id=person_id, role__name=role_name)
-
 
 #------------------------------------------------------------
 


Test patch:
diff --git a/workshops/test/test_tasks.py b/workshops/test/test_tasks.py
--- a/workshops/test/test_tasks.py
+++ b/workshops/test/test_tasks.py
@@ -73,9 +73,7 @@ def test_task_edit_view_reachable_from_event_person_and_role_of_task(self):
 
         correct_task = self.fixtures['test_task_1']
 
-        url_kwargs = {'event_slug': correct_task.event.slug,
-                      'person_id': correct_task.person.pk,
-                      'role_name': correct_task.role.name}
+        url_kwargs = {'task_id': correct_task.id}
 
         response = self.client.get(reverse('task_edit',
                                    kwargs=url_kwargs))