-
Notifications
You must be signed in to change notification settings - Fork 20
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1133 from akvo/1118_typeahead
[#1118] typeahead
- Loading branch information
Showing
18 changed files
with
430 additions
and
213 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,72 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Akvo RSR is covered by the GNU Affero General Public License. | ||
See more details in the license.txt file located at the root folder of the | ||
Akvo RSR module. For additional details on the GNU license please | ||
see < http://www.gnu.org/licenses/agpl.html >. | ||
""" | ||
|
||
from rest_framework import serializers | ||
# from akvo.codelists.models import SectorCategory | ||
from akvo.rsr.models import Country, Organisation, Project, ProjectUpdate | ||
|
||
|
||
class TypeaheadCountrySerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = Country | ||
fields = ( | ||
'id', | ||
'name', | ||
'iso_code', | ||
'continent_code', | ||
) | ||
|
||
|
||
class TypeaheadOrganisationSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = Organisation | ||
fields = ( | ||
'id', | ||
'name', | ||
'long_name', | ||
) | ||
|
||
|
||
class TypeaheadProjectSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = Project | ||
fields = ( | ||
'id', | ||
'project_plan_summary', | ||
'subtitle', | ||
'title', | ||
) | ||
|
||
|
||
class TypeaheadProjectUpdateSerializer(serializers.ModelSerializer): | ||
|
||
class Meta: | ||
model = ProjectUpdate | ||
fields = ( | ||
'id', | ||
'project', | ||
'title' | ||
) | ||
|
||
# class TypeaheadSectorSerializer(serializers.ModelSerializer): | ||
|
||
# class Meta: | ||
# model = Project | ||
# depth = 1 | ||
# fields = ( | ||
# 'id', | ||
# 'sectors', | ||
# ) | ||
# # fields = ( | ||
# # 'id', | ||
# # # 'categories', | ||
# # 'name', | ||
# # ) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
# -*- coding: utf-8 -*- | ||
|
||
"""Akvo RSR is covered by the GNU Affero General Public License. | ||
See more details in the license.txt file located at the root folder of the | ||
Akvo RSR module. For additional details on the GNU license please | ||
see < http://www.gnu.org/licenses/agpl.html >. | ||
""" | ||
|
||
from rest_framework.decorators import api_view | ||
from rest_framework.response import Response | ||
|
||
from akvo.rest.serializers import (TypeaheadCountrySerializer, | ||
TypeaheadOrganisationSerializer, | ||
TypeaheadProjectSerializer, | ||
TypeaheadProjectUpdateSerializer) | ||
# from akvo.codelists.models import SectorCategory | ||
from akvo.rsr.models import Country, Organisation, Project, ProjectUpdate | ||
|
||
|
||
def rejig(queryset, serializer): | ||
"""Rearrange & add queryset count to the response data.""" | ||
return { | ||
'count': queryset.count(), | ||
'results': serializer.data | ||
} | ||
|
||
|
||
@api_view(['GET']) | ||
def typeahead_country(request): | ||
countries = Country.objects.all() | ||
return Response( | ||
rejig(countries, TypeaheadCountrySerializer(countries, many=True)) | ||
) | ||
|
||
|
||
@api_view(['GET']) | ||
def typeahead_organisation(request): | ||
organisations = Organisation.objects.all() | ||
return Response( | ||
rejig(organisations, TypeaheadOrganisationSerializer(organisations, | ||
many=True)) | ||
) | ||
|
||
|
||
@api_view(['GET']) | ||
def typeahead_project(request): | ||
projects = Project.objects.published() | ||
return Response( | ||
rejig(projects, TypeaheadProjectSerializer(projects, many=True)) | ||
) | ||
|
||
|
||
@api_view(['GET']) | ||
def typeahead_projectupdate(request): | ||
updates = ProjectUpdate.objects.all() | ||
return Response( | ||
rejig(updates, TypeaheadProjectUpdateSerializer(updates, many=True)) | ||
) | ||
|
||
|
||
# @api_view(['GET']) | ||
# def typeahead_sector(request): | ||
# """ | ||
# """ | ||
|
||
# sectors = Sector.objects.all() | ||
|
||
# return Response( | ||
# rejig(sectors, TypeaheadSectorSerializer(sectors, many=True)) | ||
# ) | ||
|
||
|
||
# @api_view(['GET']) | ||
# def typeahead_sector(request): | ||
# """ | ||
# """ | ||
# sectors = SectorCategory.objects.all() | ||
# return Response( | ||
# rejig(sectors, TypeaheadSectorSerializer(sectors, many=True)) | ||
# ) |
Oops, something went wrong.