11# coding=utf-8
22import json
3+
4+ from base .models .project import Project
5+ from certification .mixins import ActiveCertifyingOrganisationRequiredMixin
36from django .http import HttpResponse
4- from rest_framework .views import APIView , Response
57from rest_framework import status
6- from base .models .project import Project
8+ from rest_framework .views import APIView , Response
9+
710from ..models .certifying_organisation import CertifyingOrganisation
811from ..models .training_center import TrainingCenter
912from ..utilities import CustomSerializer
@@ -14,53 +17,48 @@ class GetTrainingCenterProjectLocation(APIView):
1417
1518 def get (self , request ):
1619 try :
17- project = Project .objects .get (slug = ' qgis' )
20+ project = Project .objects .get (slug = " qgis" )
1821 training_centers = TrainingCenter .objects .filter (
1922 certifying_organisation__project = project
20- ).order_by (' certifying_organisation__name' )
23+ ).order_by (" certifying_organisation__name" )
2124 serializers = CustomSerializer ()
22- data = (
23- serializers .serialize (
24- training_centers ,
25- geometry_field = 'location' ,
26- fields = ('name' , 'certifying_organisation__name' )
27- )
25+ data = serializers .serialize (
26+ training_centers ,
27+ geometry_field = "location" ,
28+ fields = ("name" , "certifying_organisation__name" ),
2829 )
2930 return Response (json .loads (data ))
3031 except Project .DoesNotExist :
3132 return HttpResponse (
32- 'Project does not exist.' ,
33- status = status .HTTP_400_BAD_REQUEST
33+ "Project does not exist." , status = status .HTTP_400_BAD_REQUEST
3434 )
3535
3636
37- class GetTrainingCenterOrganisationLocation (APIView ):
37+ class GetTrainingCenterOrganisationLocation (
38+ ActiveCertifyingOrganisationRequiredMixin , APIView
39+ ):
3840 """API returns GeoJSON location of training center within
3941 a certifying organisation.
4042
4143 """
4244
4345 def get (self , request , organisation_slug ):
4446 try :
45- project = Project .objects .get (slug = ' qgis' )
47+ project = Project .objects .get (slug = " qgis" )
4648 organisation = CertifyingOrganisation .objects .get (
47- slug = organisation_slug ,
48- project = project
49+ slug = organisation_slug , project = project
4950 )
5051 training_centers = TrainingCenter .objects .filter (
5152 certifying_organisation = organisation
52- ).order_by (' name' )
53+ ).order_by (" name" )
5354 serializers = CustomSerializer ()
54- data = (
55- serializers .serialize (
56- training_centers ,
57- geometry_field = 'location' ,
58- fields = ('name' , 'certifying_organisation__name' )
59- )
55+ data = serializers .serialize (
56+ training_centers ,
57+ geometry_field = "location" ,
58+ fields = ("name" , "certifying_organisation__name" ),
6059 )
6160 return Response (json .loads (data ))
6261 except Project .DoesNotExist :
6362 return HttpResponse (
64- 'Project does not exist.' ,
65- status = status .HTTP_400_BAD_REQUEST
63+ "Project does not exist." , status = status .HTTP_400_BAD_REQUEST
6664 )
0 commit comments