Exemplo n.º 1
0
    def set_organization(user):
        groups = get_organization_groups(user)
        current_org = user.user_profile.current_organization

        if current_org not in groups:
            user.user_profile.current_organization = groups.first()

        user.user_profile.save(update_fields=['current_organization'])
Exemplo n.º 2
0
 def get_organizations(self, user):
     groups = get_organization_groups(user).order_by('name')
     serializer = GroupSerializer(data=groups, many=True)
     serializer.is_valid()
     return serializer.data
Exemplo n.º 3
0
 def validate_organization(self, org_id):
     user = self.context.get('request').user
     try:
         return get_organization_groups(user).get(pk=org_id)
     except Group.DoesNotExist:
         raise serializers.ValidationError('Invalid id')
Exemplo n.º 4
0
 def get_queryset(self):
     request = self.context.get('request', None)
     if not request:
         return None
     return get_organization_groups(request.user)