def get_context_data(self, **kwargs): """ Pass initial data to a view template so that the React.js front end can render. """ context = super(EarnerPortal, self).get_context_data(**kwargs) user_collections = CollectionSerializer( Collection.objects.filter(owner=self.request.user), many=True).data user_badges = LocalBadgeInstanceUploadSerializer( LocalBadgeInstance.objects.filter( recipient_user=self.request.user), many=True).data context.update({ 'initial_data': json.dumps({ 'earner_collections': user_collections, 'earner_badges': user_badges, 'installed_apps': installed_apps_list(), 'user': UserProfileField(self.request.user, context=kwargs).data, 'STATIC_URL': settings.STATIC_URL }), }) return context
def to_representation(self, user): view_data = {} earner_collections = Collection.objects.filter(owner=user) earner_collections_serializer = CollectionSerializer( earner_collections, many=True, context=self.context ) earner_badges = StoredBadgeInstance.objects.filter( recipient_user=user ) earner_badges_serializer = EarnerBadgeSerializer( earner_badges, many=True, context=self.context ) view_data['earner_collections'] = earner_collections_serializer.data view_data['earner_badges'] = earner_badges_serializer.data view_data['installed_apps'] = installed_apps_list() return view_data
def to_representation(self, user): view_data = {} user_issuers = ( Issuer.objects.filter(Q(owner__id=user.id) | Q(staff__id=user.id)).distinct().select_related("badgeclasses") ) user_issuer_badgeclasses = chain.from_iterable(i.badgeclasses.all() for i in user_issuers) issuer_data = IssuerSerializer(user_issuers, many=True, context=self.context) badgeclass_data = BadgeClassSerializer(user_issuer_badgeclasses, many=True, context=self.context) view_data["issuer_issuers"] = issuer_data.data view_data["issuer_badgeclasses"] = badgeclass_data.data view_data["installed_apps"] = installed_apps_list() return view_data
def to_representation(self, user): view_data = {} earner_collections = Collection.objects.filter(owner=user) earner_collections_serializer = CollectionSerializer( earner_collections, many=True, context=self.context) earner_badges = StoredBadgeInstance.objects.filter(recipient_user=user) earner_badges_serializer = EarnerBadgeSerializer(earner_badges, many=True, context=self.context) view_data['earner_collections'] = earner_collections_serializer.data view_data['earner_badges'] = earner_badges_serializer.data view_data['installed_apps'] = installed_apps_list() return view_data
def to_representation(self, user): view_data = {} user_issuers = user.cached_issuers() user_issuer_badgeclasses = user.cached_badgeclasses() issuer_data = IssuerSerializer(user_issuers, many=True, context=self.context) badgeclass_data = BadgeClassSerializer(user_issuer_badgeclasses, many=True, context=self.context) view_data['issuer_issuers'] = issuer_data.data view_data['issuer_badgeclasses'] = badgeclass_data.data view_data['installed_apps'] = installed_apps_list() return view_data
def to_representation(self, user): view_data = {} user_issuers = Issuer.objects.filter( Q(owner__id=user.id) | Q(staff__id=user.id)).distinct().select_related('badgeclasses') user_issuer_badgeclasses = chain.from_iterable(i.badgeclasses.all() for i in user_issuers) issuer_data = IssuerSerializer(user_issuers, many=True, context=self.context) badgeclass_data = BadgeClassSerializer(user_issuer_badgeclasses, many=True, context=self.context) view_data['issuer_issuers'] = issuer_data.data view_data['issuer_badgeclasses'] = badgeclass_data.data view_data['installed_apps'] = installed_apps_list() return view_data
def to_representation(self, user): view_data = {} user_issuers = user.cached_issuers() user_issuer_badgeclasses = user.cached_badgeclasses() issuer_data = IssuerSerializer( user_issuers, many=True, context=self.context ) badgeclass_data = BadgeClassSerializer( user_issuer_badgeclasses, many=True, context=self.context ) view_data['issuer_issuers'] = issuer_data.data view_data['issuer_badgeclasses'] = badgeclass_data.data view_data['installed_apps'] = installed_apps_list() return view_data