コード例 #1
0
    def get_queryset(self):
        queryset = (Member.objects.filter(
            user__is_active=True).select_related('user').exclude(
                user__username='******').order_by('user__username'))

        authorized_members = Q(datarequestprojectmember__authorized=True)
        not_revoked = Q(datarequestprojectmember__revoked=False)
        visible_members = Q(datarequestprojectmember__visible=True)

        if self.request.GET.get('filter'):
            activities = personalize_activities()
            filter_name = self.request.GET.get('filter')
            badge_exists = [
                activity for activity in activities
                if activity['badge']['label'] == filter_name
                or activity['source_name'] == filter_name
            ]

            if not badge_exists:
                raise Http404()

            project = id_label_to_project(filter_name)
            project_members = Q(datarequestprojectmember__project=project)
            queryset = queryset.filter(project_members & authorized_members
                                       & visible_members & not_revoked)

        sorted_members = queryset.annotate(
            num_badges=Count('datarequestprojectmember__project',
                             filter=(
                                 authorized_members & not_revoked
                                 & visible_members))).order_by('-num_badges')
        return sorted_members
コード例 #2
0
    def get_queryset(self):
        queryset = (
            Member.objects.filter(user__is_active=True)
            .select_related("user")
            .exclude(user__username="******")
            .order_by("user__username")
        )

        authorized_members = Q(datarequestprojectmember__authorized=True)
        not_revoked = Q(datarequestprojectmember__revoked=False)
        visible_members = Q(datarequestprojectmember__visible=True)

        if self.request.GET.get("filter"):
            filter_name = self.request.GET.get("filter")
            project = id_label_to_project(filter_name)
            project_members = Q(datarequestprojectmember__project=project)
            queryset = queryset.filter(
                project_members & authorized_members & visible_members & not_revoked
            )

        sorted_members = queryset.annotate(
            num_badges=Count(
                "datarequestprojectmember__project",
                filter=(authorized_members & not_revoked & visible_members),
            )
        ).order_by("-num_badges")
        return sorted_members
コード例 #3
0
 def requested_activities(self):
     activities = {}
     for source in self.project.request_sources_access:
         proj = id_label_to_project(source)
         if proj:
             activities[source] = activity_from_data_request_project(
                 proj, user=self.request.user)
     return activities
コード例 #4
0
ファイル: models.py プロジェクト: madprime/open-humans
def is_public(member, source):
    """
    Return whether a given member has publicly shared the given source.
    """
    project = id_label_to_project(source)
    return bool(
        member.public_data_participant.publicdataaccess_set.filter(
            project_membership__project=project, is_public=True))
コード例 #5
0
def is_public(member, source):
    """
    Return whether a given member has publicly shared the given source.
    """
    project = id_label_to_project(source)
    return bool(
        member.public_data_participant.publicdataaccess_set.filter(
            project_membership__project=project, is_public=True
        )
    )
コード例 #6
0
 def get_queryset(self):
     """
     Get the queryset and filter on project if provided.
     """
     source_project_label = self.request.GET.get("source_project_label", None)
     if source_project_label:
         source_project = id_label_to_project(source_project_label)
         queryset = source_project.registered_datatypes.all()
     else:
         queryset = DataType.objects.all()
     return queryset
コード例 #7
0
 def get_queryset(self):
     """
     Get the queryset and filter on project if provided.
     """
     source_project_label = self.request.GET.get("source_project_label",
                                                 None)
     if source_project_label:
         source_project = id_label_to_project(source_project_label)
         queryset = source_project.registered_datatypes.all()
     else:
         queryset = DataType.objects.all()
     return queryset
コード例 #8
0
 def get_queryset(self):
     """
     Get the queryset and filter on project if provided.
     """
     qs = DataRequestProject.objects.filter(approved=True)
     project_label = self.request.GET.get("id_label", None)
     if project_label:
         project = id_label_to_project(project_label)
         qs = qs.filter(id=project.id)
     proj_id = self.request.GET.get("id", None)
     if proj_id:
         qs = qs.filter(id=proj_id)
     return qs
コード例 #9
0
 def get_queryset(self):
     """
     Get the queryset and filter on project if provided.
     """
     qs = DataRequestProject.objects.filter(approved=True)
     project_label = self.request.GET.get("id_label", None)
     if project_label:
         project = id_label_to_project(project_label)
         qs = qs.filter(id=project.id)
     proj_id = self.request.GET.get("id", None)
     if proj_id:
         qs = qs.filter(id=proj_id)
     return qs
コード例 #10
0
ファイル: serializers.py プロジェクト: madprime/open-humans
    def to_representation(self, data):
        ret = OrderedDict()
        fields = self.get_fields()
        query_params = dict(self.context.get("request").query_params)
        if "source" in query_params:
            source = query_params["source"][0]
        else:
            source = "direct-sharing-{}".format(str(getattr(data, "id")))

        project = id_label_to_project(source)
        if getattr(data, "id") != project.id:
            return ret
        queryset = DataRequestProject.objects.filter(id=project.id)
        usernames = list(queryset.get().project_members.filter(
            joined=True, authorized=True, revoked=False,
            visible=True).values_list("member__user__username", flat=True))
        ret["source"] = source
        ret["name"] = getattr(data, "name")
        ret["usernames"] = usernames
        return ret
コード例 #11
0
    def get_queryset(self):
        queryset = (Member.objects.filter(
            user__is_active=True).select_related("user").exclude(
                user__username="******").order_by("user__username"))

        authorized_members = Q(datarequestprojectmember__authorized=True)
        not_revoked = Q(datarequestprojectmember__revoked=False)
        visible_members = Q(datarequestprojectmember__visible=True)

        if self.request.GET.get("filter"):
            filter_name = self.request.GET.get("filter")
            project = id_label_to_project(filter_name)
            project_members = Q(datarequestprojectmember__project=project)
            queryset = queryset.filter(project_members & authorized_members
                                       & visible_members & not_revoked)

        sorted_members = queryset.annotate(num_badges=Count(
            "datarequestprojectmember__project",
            filter=(authorized_members & not_revoked & visible_members),
        )).order_by("-num_badges")
        return sorted_members
コード例 #12
0
ファイル: views.py プロジェクト: mldulaney/open-humans
    def toggle_data(self, user, source, public):
        if source not in get_source_labels() and not source.startswith(
            "direct-sharing-"
        ):
            error_msg = (
                "Public sharing toggle attempted for "
                'unexpected source "{}"'.format(source)
            )
            django_messages.error(self.request, error_msg)

            if not settings.TESTING:
                raven_client.captureMessage(error_msg)
            return
        project = id_label_to_project(source)
        project_membership = DataRequestProjectMember.objects.get(
            member=user.member, project=project
        )

        participant = user.member.public_data_participant
        access, _ = PublicDataAccess.objects.get_or_create(
            participant=participant, project_membership=project_membership
        )
        access.is_public = False
        if public == "True":
            if not project.no_public_data:
                access.is_public = True
        access.save()

        if (
            project.approved
            and not ActivityFeed.objects.filter(
                member=user.member, project=project, action="publicly-shared"
            ).exists()
        ):
            event = ActivityFeed(
                member=user.member, project=project, action="publicly-shared"
            )
            event.save()
コード例 #13
0
    def to_representation(self, data):
        ret = OrderedDict()
        fields = self.get_fields()
        query_params = dict(self.context.get('request').query_params)
        if 'source' in query_params:
            source = query_params['source'][0]
        else:
            source = 'direct-sharing-{}'.format(str(getattr(data, 'id')))

        project = id_label_to_project(source)
        if getattr(data, 'id') != project.id:
            return ret
        queryset = DataRequestProject.objects.filter(id=project.id)
        usernames = list(queryset.get().project_members.filter(joined=True,
                                                               authorized=True,
                                                               revoked=False,
                                                               visible=True).values_list(
                                                                   'member__user__username',
                                                                   flat=True))
        ret['source'] = source
        ret['name'] = getattr(data, 'name')
        ret['usernames'] = usernames
        return ret
コード例 #14
0
    def to_representation(self, data):
        ret = OrderedDict()
        fields = self.get_fields()
        query_params = dict(self.context.get("request").query_params)
        if "source" in query_params:
            source = query_params["source"][0]
        else:
            source = "direct-sharing-{}".format(str(getattr(data, "id")))

        project = id_label_to_project(source)
        if getattr(data, "id") != project.id:
            return ret
        queryset = DataRequestProject.objects.filter(id=project.id)
        usernames = list(
            queryset.get()
            .project_members.filter(
                joined=True, authorized=True, revoked=False, visible=True
            )
            .values_list("member__user__username", flat=True)
        )
        ret["source"] = source
        ret["name"] = getattr(data, "name")
        ret["usernames"] = usernames
        return ret