示例#1
0
    def dehydrate(self, bundle):
        """
        Always remove the password form the serialized bundle.
        """
        del bundle.data['password']

        user = bundle.obj

        if 'notifications' in bundle.request.GET and bundle.request.GET['notifications'].lower() == 'true':
            from panda.api.notifications import NotificationResource
            
            resource = NotificationResource()

            notifications = user.notifications.all()[:settings.PANDA_NOTIFICATIONS_TO_SHOW]

            bundles = [resource.build_bundle(obj=n) for n in notifications]
            notifications = [resource.full_dehydrate(b) for b in bundles]

            bundle.data['notifications'] = notifications

        if 'exports' in bundle.request.GET and bundle.request.GET['exports'].lower() == 'true':
            from panda.api.exports import ExportResource

            resource = ExportResource()

            exports = Export.objects.filter(creator=user)

            bundles = [resource.build_bundle(obj=e) for e in exports]
            exports = [resource.full_dehydrate(b) for b in bundles]

            bundle.data['exports'] = exports

        if 'datasets' in bundle.request.GET and bundle.request.GET['datasets'].lower() == 'true':
            from panda.api.datasets import DatasetResource

            resource = DatasetResource()

            datasets = user.datasets.all()

            bundles = [resource.build_bundle(obj=d) for d in datasets]
            datasets = [resource.simplify_bundle(resource.full_dehydrate(b)) for b in bundles]

            bundle.data['datasets'] = datasets

        if 'search_subscriptions' in bundle.request.GET and bundle.request.GET['search_subscriptions'].lower() == 'true':
            from panda.api.search_subscriptions import SearchSubscriptionResource

            resource = SearchSubscriptionResource()

            subscriptions = user.search_subscriptions.all()

            bundles = [resource.build_bundle(obj=s) for s in subscriptions]
            datasets = [resource.full_dehydrate(b) for b in bundles]

            bundle.data['subscriptions'] = datasets

        return bundle
示例#2
0
文件: views.py 项目: eads/panda
def make_user_login_response(user):
    """
    Generate a response to a login request.
    """
    nr = NotificationResource()

    notifications = user.notifications.filter(read_at__isnull=True)

    bundles = [nr.build_bundle(obj=n) for n in notifications]
    notifications = [nr.full_dehydrate(b) for b in bundles]

    return {
        'email': user.email,
        'api_key': user.api_key.key,
        'is_staff': user.is_staff,
        'notifications': notifications
    }
示例#3
0
def make_user_login_response(user):
    """
    Generate a response to a login request.
    """
    nr = NotificationResource()

    notifications = user.notifications.all()[:settings.PANDA_NOTIFICATIONS_TO_SHOW]

    bundles = [nr.build_bundle(obj=n) for n in notifications]
    notifications = [nr.full_dehydrate(b) for b in bundles]

    return {
        'id': user.id,
        'email': user.email,
        'is_staff': user.is_staff,
        'show_login_help': user.get_profile().show_login_help,
        'notifications': notifications
    }
示例#4
0
def make_user_login_response(user):
    """
    Generate a response to a login request.
    """
    nr = NotificationResource()

    notifications = user.notifications.all()[:settings.
                                             PANDA_NOTIFICATIONS_TO_SHOW]

    bundles = [nr.build_bundle(obj=n) for n in notifications]
    notifications = [nr.full_dehydrate(b) for b in bundles]

    return {
        'id': user.id,
        'email': user.email,
        'is_staff': user.is_staff,
        'show_login_help': user.get_profile().show_login_help,
        'notifications': notifications
    }
示例#5
0
def make_user_login_response(user):
    """
    Generate a response to a login request.
    """
    nr = NotificationResource()

    notifications = user.notifications.filter(read_at__isnull=True)

    bundles = [nr.build_bundle(obj=n) for n in notifications]
    notifications = [nr.full_dehydrate(b) for b in bundles]

    return {
        "id": user.id,
        "email": user.email,
        "api_key": user.api_key.key,
        "is_staff": user.is_staff,
        "show_login_help": user.get_profile().show_login_help,
        "notifications": notifications,
    }
示例#6
0
文件: users.py 项目: mattkiefer/panda
    def dehydrate(self, bundle):
        """
        Always remove the password form the serialized bundle.
        """
        del bundle.data['password']

        user = bundle.obj

        if 'notifications' in bundle.request.GET and bundle.request.GET[
                'notifications'].lower() == 'true':
            from panda.api.notifications import NotificationResource

            resource = NotificationResource()

            notifications = user.notifications.all(
            )[:settings.PANDA_NOTIFICATIONS_TO_SHOW]

            bundles = [resource.build_bundle(obj=n) for n in notifications]
            notifications = [resource.full_dehydrate(b) for b in bundles]

            bundle.data['notifications'] = notifications

        if 'exports' in bundle.request.GET and bundle.request.GET[
                'exports'].lower() == 'true':
            from panda.api.exports import ExportResource

            resource = ExportResource()

            exports = Export.objects.filter(creator=user)

            bundles = [resource.build_bundle(obj=e) for e in exports]
            exports = [resource.full_dehydrate(b) for b in bundles]

            bundle.data['exports'] = exports

        if 'datasets' in bundle.request.GET and bundle.request.GET[
                'datasets'].lower() == 'true':
            from panda.api.datasets import DatasetResource

            resource = DatasetResource()

            datasets = user.datasets.all()

            bundles = [resource.build_bundle(obj=d) for d in datasets]
            datasets = [
                resource.simplify_bundle(resource.full_dehydrate(b))
                for b in bundles
            ]

            bundle.data['datasets'] = datasets

        if 'search_subscriptions' in bundle.request.GET and bundle.request.GET[
                'search_subscriptions'].lower() == 'true':
            from panda.api.search_subscriptions import SearchSubscriptionResource

            resource = SearchSubscriptionResource()

            subscriptions = user.search_subscriptions.all()

            bundles = [resource.build_bundle(obj=s) for s in subscriptions]
            datasets = [resource.full_dehydrate(b) for b in bundles]

            bundle.data['subscriptions'] = datasets

        return bundle