-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat: upgrading simple api to drf compatible.
- Loading branch information
Showing
3 changed files
with
67 additions
and
29 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
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,28 @@ | ||
from django.contrib.auth.models import User # lint-amnesty, pylint: disable=imported-auth-user | ||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import gettext as _ | ||
from rest_framework import serializers, status | ||
|
||
from lms.djangoapps.instructor.access import ROLES | ||
|
||
|
||
class RoleNameSerializer(serializers.Serializer): # pylint: disable=abstract-method | ||
""" | ||
Serializer that describes the response of the problem response report generation API. | ||
""" | ||
|
||
rolename = serializers.CharField(help_text=_("Role name")) | ||
|
||
def validate_rolename(self, value): | ||
""" | ||
Check that the rolename is valid. | ||
""" | ||
if value not in ROLES: | ||
raise ValidationError(_("Invalid role name.")) | ||
return value | ||
|
||
|
||
class UserSerializer(serializers.ModelSerializer): | ||
class Meta: | ||
model = User | ||
fields = ['username', 'email', 'first_name', 'last_name'] |