<s> from django . contrib . auth import get_user_model <EOL> from django . contrib . auth . models import Group <EOL> from django . db . models import Prefetch <EOL> from ralph . accounts . models import Region , Team <EOL> from ralph . api import RalphAPISerializer , RalphAPIViewSet , router <EOL> from ralph . api . permissions import IsSuperuserOrReadonly <EOL> from ralph . back_office . api import ( <EOL> BackOfficeAssetSerializer , <EOL> BackOfficeAssetViewSet <EOL> ) <EOL> from ralph . back_office . models import BackOfficeAsset <EOL> from ralph . licences . api import LicenceUserViewSet <EOL> from ralph . licences . api_simple import SimpleLicenceUserSerializer <EOL> from ralph . licences . models import LicenceUser <EOL> class GroupSerializer ( RalphAPISerializer ) : <EOL> class Meta : <EOL> model = Group <EOL> exclude = ( '<STR_LIT>' , ) <EOL> class GroupViewSet ( RalphAPIViewSet ) : <EOL> queryset = Group . objects . all ( ) <EOL> serializer_class = GroupSerializer <EOL> class RalphUserSerializer ( RalphAPISerializer ) : <EOL> assets_as_user = BackOfficeAssetSerializer ( read_only = True , many = True ) <EOL> assets_as_owner = BackOfficeAssetSerializer ( read_only = True , many = True ) <EOL> licences = SimpleLicenceUserSerializer ( read_only = True , many = True ) <EOL> class Meta : <EOL> model = get_user_model ( ) <EOL> exclude = ( '<STR_LIT>' , '<STR_LIT:password>' , '<STR_LIT>' ) <EOL> depth = <NUM_LIT:1> <EOL> class RalphUserViewSet ( RalphAPIViewSet ) : <EOL> queryset = get_user_model ( ) . objects . all ( ) <EOL> serializer_class = RalphUserSerializer <EOL> _assets_queryset = BackOfficeAsset . objects . select_related ( <EOL> * BackOfficeAssetViewSet . select_related <EOL> ) . prefetch_related ( '<STR_LIT>' ) <EOL> prefetch_related = [ <EOL> '<STR_LIT>' , '<STR_LIT>' , <EOL> Prefetch ( '<STR_LIT>' , queryset = LicenceUser . objects . select_related ( <EOL> * LicenceUserViewSet . select_related <EOL> ) ) , <EOL> Prefetch ( '<STR_LIT>' , queryset = _assets_queryset ) , <EOL> Prefetch ( '<STR_LIT>' , queryset = _assets_queryset ) , <EOL> ] <EOL> permission_classes = RalphAPIViewSet . permission_classes + [ <EOL> IsSuperuserOrReadonly <EOL> ] <EOL> http_method_names = [ <EOL> m for m in RalphAPIViewSet . http_method_names if m != '<STR_LIT>' <EOL> ] <EOL> class RegionSerializer ( RalphAPISerializer ) : <EOL> class Meta : <EOL> model = Region <EOL> class RegionViewSet ( RalphAPIViewSet ) : <EOL> queryset = Region . objects . all ( ) <EOL> serializer_class = RegionSerializer <EOL> class TeamSerializer ( RalphAPISerializer ) : <EOL> class Meta : <EOL> model = Team <EOL> class TeamViewSet ( RalphAPIViewSet ) : <EOL> queryset = Team . objects . all ( ) <EOL> serializer_class = TeamSerializer <EOL> router . register ( r'<STR_LIT>' , GroupViewSet ) <EOL> router . register ( r'<STR_LIT>' , RalphUserViewSet ) <EOL> router . register ( r'<STR_LIT>' , RegionViewSet ) <EOL> router . register ( r'<STR_LIT>' , TeamViewSet ) <EOL> urlpatterns = [ ] </s>
