def get(self, request): """ Fetch the specified Allocation """ user = request.user allocation_results = [] memberships = only_active_memberships(user) for membership in memberships: strat = AllocationStrategy.objects.get( provider=membership.identity.provider) allocation_result = strat.execute( membership.identity, membership.allocation) allocation_results.append(allocation_result) serialized_data = AllocationResultSerializer( allocation_results, many=True).data return Response(serialized_data)
def current_identity_memberships(self): return self.identity_memberships.filter(only_active_memberships())
def current_providers(self): provider_ids = self.identity_memberships.filter( only_active_memberships()).values_list('identity__provider', flat=True) return Provider.objects.filter(id__in=provider_ids)
def current_identities(self): identity_ids = self.identity_memberships.filter( only_active_memberships()).values_list('identity', flat=True) return Identity.objects.filter(only_current_provider(), only_active_provider(), id__in=identity_ids)
def is_active(self, user=None): if user: return self.identity_memberships.filter( only_active_memberships(), member__user=user).count() > 0 return self.provider.is_active()
def current_providers(self): provider_ids = self.identity_memberships.filter( only_active_memberships()).values_list('identity__provider',flat=True) return Provider.objects.filter(id__in=provider_ids)
def current_identities(self): identity_ids = self.identity_memberships.filter( only_active_memberships()).values_list('identity',flat=True) return Identity.objects.filter(only_current_provider(), only_active_provider(), id__in=identity_ids)