Exemplo n.º 1
0
    def setUp(self):
        reader = XFormReader(XFORM_FILE)

        self.data = reader.to_json_dict()
        self.data['name'] = 'test_repo'

        serializer = RepoSerializer()
        self.repos = serializer.serialize(Repository.objects.all())
Exemplo n.º 2
0
    def setUp( self ):
        reader = XFormReader( XFORM_FILE )

        self.data = reader.to_json_dict()
        self.data[ 'name' ] = 'test_repo'

        serializer = RepoSerializer()
        self.repos = serializer.serialize( Repository.objects.all() )
Exemplo n.º 3
0
    def dehydrate( self, bundle ):
        '''
            Serialize the current bundle.object using the RepoSerializer which
            converts the model into a JSON compatible python dictionary.

            - fields:
                Fields are grabbed from MongoDB and appended to the bundle
                dictionary.
        '''
        # First serialize the repo metadata.
        serializer = RepoSerializer()
        bundle.data = serializer.serialize( [bundle.obj] )[0]

        return bundle
Exemplo n.º 4
0
    def dehydrate( self, bundle ):
        '''
            Serialize the current bundle.object using the RepoSerializer which
            converts the model into a JSON compatible python dictionary.

            - fields:
                Fields are grabbed from MongoDB and appended to the bundle
                dictionary.
        '''
        # First serialize the repo metadata.
        serializer = RepoSerializer()
        bundle.data = serializer.serialize( [bundle.obj] )[0]

        return bundle
Exemplo n.º 5
0
def user_dashboard(request, username):
    '''
        Dashboard seen when a user signs in or views another user's profile.

        The dashboard contains links to a users the private/public data repos.
        Private repos are only shown if the user has permission to view them.
    '''
    # Are we looking at our own profile or someone elses?
    is_other_user = request.user.username != username

    user = get_object_or_404(User, username=username)

    # Find all the organization this user belongs to
    organizations = OrganizationUser.objects.filter(user=user)

    # Grab a list of forms uploaded by the user
    if is_other_user:
        user_repos = Repository.objects.list_by_user(
            user=user, organizations=organizations, public=True)
        user_studies = []
    else:
        user_repos = Repository.objects.list_by_user(
            user=user, organizations=organizations)
        user_studies = Study.objects.filter(user=user)

        # Get repos shared with orgs user is a member of
        orgs = OrganizationUser.objects.filter(user=user)
        orgs = map(lambda ou: ou.organization, orgs)
        for org in orgs:
            user_repos = user_repos | get_objects_for_group(
                org, 'view_repository', Repository)

    serializer = RepoSerializer()
    repo_json = json.dumps(serializer.serialize(user_repos))

    serializer = StudySerializer()
    study_json = json.dumps(serializer.serialize(user_studies))

    return render_to_response('dashboard.html', {
        'user_studies': study_json,
        'user_repos': repo_json,
        'is_other_user': is_other_user,
        'account': user,
        'organizations': organizations
    },
                              context_instance=RequestContext(request))
Exemplo n.º 6
0
def user_dashboard( request, username ):
    '''
        Dashboard seen when a user signs in or views another user's profile.

        The dashboard contains links to a users the private/public data repos.
        Private repos are only shown if the user has permission to view them.
    '''
    # Are we looking at our own profile or someone elses?
    is_other_user = request.user.username != username

    user = get_object_or_404( User, username=username )

    # Find all the organization this user belongs to
    organizations = OrganizationUser.objects.filter( user=user )

    # Grab a list of forms uploaded by the user
    if is_other_user:
        user_repos = Repository.objects.list_by_user( user=user,
                                                      organizations=organizations,
                                                      public=True )
        user_studies = []
    else:
        user_repos = Repository.objects.list_by_user( user=user,
                                                      organizations=organizations )
        user_studies = Study.objects.filter( user=user )


    serializer = RepoSerializer()
    repo_json = json.dumps( serializer.serialize( user_repos ) )

    serializer = StudySerializer()
    study_json = json.dumps( serializer.serialize( user_studies ) )

    return render_to_response( 'dashboard.html',
                               { 'user_studies': study_json,
                                 'user_repos': repo_json,
                                 'is_other_user': is_other_user,
                                 'account': user,
                                 'organizations': organizations },
                               context_instance=RequestContext(request) )