-
Notifications
You must be signed in to change notification settings - Fork 4
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- add retrive profiles view - add profiles url - add support for profiles - add profiles serializer [DELIVERS #160617680] change profiles serializer
- Loading branch information
1 parent
d3f8f22
commit 904e7e5
Showing
4 changed files
with
50 additions
and
13 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,15 +1,23 @@ | ||
import json | ||
from rest_framework.renderers import JSONRenderer | ||
from rest_framework.utils.serializer_helpers import ReturnDict, ReturnList | ||
|
||
|
||
class ProfileJSONRenderer(JSONRenderer): | ||
|
||
charset = 'utf-8' | ||
|
||
def render(self, data, media_type=None, renderer_context=None): | ||
errors = data.get('errors', None) | ||
if errors is not None: | ||
|
||
return super(ProfileJSONRenderer, self).render(data) | ||
return json.dumps({ | ||
'profile': data | ||
}) | ||
def render(self, data, accepted_media_type=None, renderer_context=None): | ||
if type(data) != ReturnList: | ||
errors = data.get('errors', None) | ||
if errors is not None: | ||
return super(ProfileJSONRenderer, self).render(data) | ||
|
||
if type(data) == ReturnDict: | ||
return json.dumps({ | ||
'profile': data | ||
}) | ||
else: | ||
return json.dumps({ | ||
'profiles': data | ||
}) |
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 |
---|---|---|
@@ -1,10 +1,11 @@ | ||
from django.urls import path | ||
|
||
from .views import ProfileRetrieveUpdateView | ||
from .views import ProfileRetrieveUpdateView, RetriveProfilesView | ||
|
||
app_name ='profiles' | ||
|
||
urlpatterns = [ | ||
path('profiles/',RetriveProfilesView.as_view()), | ||
path('profiles/<str:username>/', ProfileRetrieveUpdateView.as_view()), | ||
] | ||
|
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