def put(self, request, pk, format=None): user = self.get_object(pk) serializer = UserSerializer(user, data=request.data) if serializer.is_valid(): serializer.save() logger.debug('Updated data of User object with id ' + str(pk)) return Response(serializer.data) logger.error('Error on data update for User object with id ' + str(pk)) return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def post(self, request, format=None): """ Method used to create a new User object. """ body = json.loads(request.body) body["password"] = make_password(body["password"]) serializer = UserSerializer(data=body) if serializer.is_valid(): serializer.save() logger.debug('Created a new User object') return Response(serializer.data, status=status.HTTP_201_CREATED) logger.error('Error on creation of a new User object') return Response(serializer.errors, status=status.HTTP_400_BAD_REQUEST)
def modify_core(): User.assign_attrs( __cache_key_forum_post_count__='users_{id}_forum_post_count', __cache_key_forum_thread_count__='users_{id}_forum_thread_count', forum_thread_count=forum_thread_count, forum_post_count=forum_post_count, forum_permissions=forum_permissions, ) UserSerializer.assign_attrs( forum_permissions=Attribute(permission='users_moderate', nested=False)) Permissions.permission_regexes['basic'] += [ re.compile('forumaccess_forum_\d+$'), re.compile('forumaccess_thread_\d+$'), ] Config.BASIC_PERMISSIONS += [ 'forums_posts_create', 'forums_threads_create', ]
class AuthorSerializer(serializers.HyperlinkedModelSerializer): class Meta: model = Author fields = ('id', 'github', 'bio', 'user') user = UserSerializer()