Repository: kartoza/prj.app

Issue:
Training centre does not exist
Changelog certification creating a new course fails with:

```python
ERROR 2020-01-27 14:44:04,359 base 31226 140227744548608
 [u'DoesNotExist: TrainingCenter matching query does not exist.', u'  
File "django/core/handlers/base.py", line 132, in get_response', u'  
File "django/views/generic/base.py", line 71, in view', u'  
File "django/views/generic/base.py", line 89, in dispatch', u'  
File "django/views/generic/detail.py", line 115, in get', u'  
File "certification/views/training_center.py", line 163, in get_object', u'  File "django/db/models/query.py", line 334, in get']
```
![certification](https://user-images.githubusercontent.com/178003/73185330-c563eb80-4115-11ea-8266-76909cdc53e7.gif)

See http://sentry.kartoza.com/sentry/projecta/issues/1693/

cc @saberraz 


Discussion:

Resolving patch:
diff --git a/django_project/certification/models/course_convener.py b/django_project/certification/models/course_convener.py
--- a/django_project/certification/models/course_convener.py
+++ b/django_project/certification/models/course_convener.py
@@ -70,6 +70,9 @@ def save(self, *args, **kwargs):
     def __unicode__(self):
         return self.user.username
 
+    def __str__(self):
+        return self.user.username
+
     def get_absolute_url(self):
         """Return URL to course convener detail page.
 
diff --git a/django_project/certification/views/course.py b/django_project/certification/views/course.py
--- a/django_project/certification/views/course.py
+++ b/django_project/certification/views/course.py
@@ -63,6 +63,10 @@ def get_context_data(self, **kwargs):
         context['courses'] = self.get_queryset() \
             .filter(certifying_organisation=self.certifying_organisation)
         context['organisation_slug'] = self.kwargs.pop('organisation_slug')
+        context['organisation'] = (
+            CertifyingOrganisation.objects.get(
+                slug=context['organisation_slug'])
+        )
         context['project_slug'] = self.kwargs.pop('project_slug')
         return context
 
@@ -159,6 +163,10 @@ def get_context_data(self, **kwargs):
         context['courses'] = self.get_queryset() \
             .filter(certifying_organisation=self.certifying_organisation)
         context['organisation_slug'] = self.kwargs.pop('organisation_slug')
+        context['organisation'] = (
+            CertifyingOrganisation.objects.get(
+                slug=context['organisation_slug'])
+        )
         context['project_slug'] = self.kwargs.pop('project_slug')
         return context
 
diff --git a/django_project/certification/views/course_type.py b/django_project/certification/views/course_type.py
--- a/django_project/certification/views/course_type.py
+++ b/django_project/certification/views/course_type.py
@@ -60,6 +60,9 @@ def get_context_data(self, **kwargs):
             CourseTypeCreateView, self).get_context_data(**kwargs)
         context['coursetypes'] = self.get_queryset() \
             .filter(certifying_organisation=self.certifying_organisation)
+        context['organisation'] = CertifyingOrganisation.objects.get(
+            slug=self.kwargs.get('organisation_slug', None)
+        )
         return context
 
     def get_form_kwargs(self):
@@ -204,6 +207,9 @@ def get_context_data(self, **kwargs):
             CourseTypeUpdateView, self).get_context_data(**kwargs)
         context['coursetypes'] = self.get_queryset() \
             .filter(certifying_organisation=self.certifying_organisation)
+        context['organisation'] = CertifyingOrganisation.objects.get(
+            slug=self.kwargs.get('organisation_slug', None)
+        )
         return context
 
     def get_queryset(self):


Test patch: