Repository: kartoza/prj.app

Issue:
GeoJson feeds for certification
3 Feeds:

1) Geojson with point for every training org's training centres and link to their home page and their certification training page e.g. http://www.faunalia.eu/ and https://changelog.qgis.org/en/qgis/certifyingorganisation/qgis-faunalia/ 

2) GeoJSON as above but only for courses scheduled in the future. JSON should also contain a link to the course page: e.g.

https://changelog.qgis.org/en/qgis/certifyingorganisation/qgis-faunalia/course/qgis_python-e-qgis-pyqgis-e-plugin_2019-11-05-2019-11-07/

The page should not show attendees list for anyone except cert org members. Other users should only see details about the course being convened. No credits or attendees should be shown to anyone but org members of that certifying org.

![Screenshot 2020-03-04 at 09 37 09](https://user-images.githubusercontent.com/178003/75865720-e1853780-5dfb-11ea-9ac5-3cb6b337f0ca.png)


3) As in 2 above but for courses from the past



Discussion:
CC @geomenke

Resolving patch:
diff --git a/django_project/certification/feeds/geojson_feed.py b/django_project/certification/feeds/geojson_feed.py
--- a/django_project/certification/feeds/geojson_feed.py
+++ b/django_project/certification/feeds/geojson_feed.py
@@ -34,7 +34,8 @@ def add_item_elements(self, item):
                 ],
             },
             'properties': {
-                'name': item['description']
+                'name': item['name'],
+                'certifying_organisation': item['certifying_organisation'].name
             }
         }
         return item_elements
diff --git a/django_project/certification/feeds/training_center.py b/django_project/certification/feeds/training_center.py
--- a/django_project/certification/feeds/training_center.py
+++ b/django_project/certification/feeds/training_center.py
@@ -110,7 +110,7 @@ def items(self, obj):
         """
         return TrainingCenter.objects.filter(
             certifying_organisation=obj,
-        ).order_by('-name')
+        ).order_by('name')
 
     def item_title(self, item):
         """Return the title of the training center.
@@ -125,5 +125,65 @@ def item_title(self, item):
 
     def item_extra_kwargs(self, item):
         return {
-            'location': item.location
+            'location': item.location,
+            'certifying_organisation': item.certifying_organisation,
+            'name': item.name
         }
+
+
+class ProjectTrainingCenterFeed(TrainingCenterFeed):
+    """Feed to list all training center within a project."""
+
+    def get_object(self, request, *args, **kwargs):
+        """Return the certifying organisation object that
+        matches the project_slug and organisation slug.
+
+        :param request: The incoming HTTP request object
+        :type request: Request object
+
+        :param args: Positional arguments
+        :type args: tuple
+
+        :param kwargs: Keyword arguments
+        :type kwargs: dict
+
+        :returns: project
+        :rtype: Project
+
+        :raises: Http404
+        """
+        try:
+            project_slug = kwargs.get('project_slug', None)
+            project = get_object_or_404(Project, slug=project_slug)
+            project.uri = (
+                self.get_absolute_obj_url(request, project))
+            return project
+        except Http404:
+            raise Http404(
+                'Sorry! We could not find your project!')
+
+    def feed_extra_kwargs(self, obj):
+        """Return the homepage of the certifying organisation.
+
+        :param obj: A certifying organisation
+        :type obj: CertifyingOrganisation
+
+        :returns: Homepage of the certifying organisation.
+        :rtype: str
+        """
+        return {
+            'homepage': obj.project_url
+        }
+
+    def items(self, obj):
+        """Return training center of the certifying organisation.
+
+        :param obj: A certifying organisation
+        :type obj: CertifyingOrganisation
+
+        :returns: List of training center of a certifying organisation
+        :rtype: list
+        """
+        return TrainingCenter.objects.filter(
+            certifying_organisation__project=obj,
+        ).order_by('certifying_organisation__name', 'name')
diff --git a/django_project/certification/urls.py b/django_project/certification/urls.py
--- a/django_project/certification/urls.py
+++ b/django_project/certification/urls.py
@@ -2,7 +2,10 @@
 """Urls for certification apps."""
 
 from django.conf.urls import url
-from .feeds.training_center import TrainingCenterFeed
+from .feeds.training_center import (
+    TrainingCenterFeed,
+    ProjectTrainingCenterFeed
+)
 from .feeds.course import (
     UpcomingCourseFeed,
     PastCourseFeed,
@@ -308,6 +311,9 @@
     url(regex='^(?P<project_slug>[\w-]+)/feed/past-course/$',
         view=PastCourseProjectFeed(),
         name='feed-past-project-course'),
+    url(regex='^(?P<project_slug>[\w-]+)/feed/training-center/$',
+        view=ProjectTrainingCenterFeed(),
+        name='feed-training-center-project'),
     url(regex='^(?P<project_slug>[\w-]+)/certifyingorganisation/'
               '(?P<organisation_slug>[\w-]+)/feed/training-center/$',
         view=TrainingCenterFeed(),


Test patch: