Beispiel #1
0
 def resolve_topicsFeatured(self, info, count=10, after=None, **kwargs):
     qs = Topic.objects.all()
     paginator = CursorPaginator(qs, ordering=('-id', ))
     page = paginator.page(first=count, after=after)
     return TopicQuery(
         topics=page,
         hasNext=page.has_next,
         lastCursor=paginator.cursor(page[-1]) if page else None)
Beispiel #2
0
 def resolve_createList(self, info, count=10, after=None):
     qs = List.objects.filter(
         isActive=True,
         curator__in=self,
     ).annotate(user_id=F('curator'), timestamp=F('timestampCreated'))
     paginator = CursorPaginator(qs, ordering=('-timestampCreated', '-id'))
     page = paginator.page(first=count, after=after)
     return UserCreateListActivity(
         stories=page,
         hasNext=page.has_next,
         lastCursor=paginator.cursor(page[-1]) if page else None)
Beispiel #3
0
    def resolve_contributeItem(self, info, count=10, after=None):
        from request.models import ListEntry

        qs = ListEntry.objects.filter(
            contributor__in=self,
            position__isnull=False,
        ).annotate(user_id=F('contributor'))
        paginator = CursorPaginator(qs, ordering=('-timestamp', '-id'))
        page = paginator.page(first=count, after=after)
        return UserContributeItemActivity(
            stories=page,
            hasNext=page.has_next,
            lastCursor=paginator.cursor(page[-1]) if page else None)
Beispiel #4
0
 def resolve_lists(self, info, query, count=10, after=None, **kwargs):
     if query and query.username is not None:
         username = query.username
     else:
         username = '******'
     qs = List.objects.filter(curator__username=username, isActive=True)
     paginator = CursorPaginator(qs, ordering=('-timestampCreated', '-id'))
     page = paginator.page(first=count, after=after)
     return ListQuery(
         lists=page,
         hasNext=page.has_next,
         lastCursor=paginator.cursor(page[-1]) if page else None
     )
Beispiel #5
0
 def resolve_listEntries(self, info, list, count=10, after=None):
     lists = List.objects.filter((Q(slug=list.slug) | Q(id=list.id)) & Q(isActive=True))
     if lists.count() == 1:
         qs = ListEntry.objects.filter(
             position__isnull=True,
             list=lists.first()
         )
         resultCount = qs.count()
         paginator = CursorPaginator(qs, ordering=('-timestamp', '-id'))
         page = paginator.page(first=count, after=after)
         return ListEntryQuery(
             entries=page,
             totalCount=resultCount,
             hasNext=page.has_next,
             lastCursor=paginator.cursor(page[-1]) if page else None
         )
     else:
         raise Exception(AttributeError, "Invalid list passed")
Beispiel #6
0
    def resolve_startedFollowing(self, info, count=10, after=None):
        qs = UserSubscription.objects.filter(user=info.context.user)
        paginator = CursorPaginator(qs, ordering=('-createdTimestamp', '-id'))
        page = paginator.page(first=count, after=after)

        followers = list()
        if page.items:
            for i in page.items:
                followers.append({
                    "actor": i.subscriber.username,
                    "timestamp": i.createdTimestamp,
                    "actionType": "STARTED_FOLLOWING",
                    "actionPhrase": "started following you",
                    "actionURL": "/" + i.subscriber.username,
                })

        return NotificationQuery(
            notifications=followers,
            hasNext=page.has_next,
            lastCursor=paginator.cursor(page[-1]) if page else None)
Beispiel #7
0
    def resolve_events(
        self,
        info,
        parentID: str = None,
        eventType: int = None,
        count: int = 25,
        after: str = None,
    ):
        qs = Event.objects.filter(parent_id=parentID)

        if eventType is not None:
            qs = qs.filter(type=eventType)

        paginator = CursorPaginator(qs, ordering=('id', 'name'))
        page = paginator.page(first=count, after=after)
        return EventsQuery(
            events=page,
            totalCount=qs.count(),
            hasNext=page.has_next,
            lastCursor=paginator.cursor(page[-1]) if page else None)
Beispiel #8
0
    def resolve_gallery(self, info, eventID=None, count=10, after=None):
        from event.models import Participant, Submission
        PIDs = Submission.objects.filter(isPublic=True,
                                         participant__approver__isnull=False,
                                         event__enableGallery=True)
        if eventID is not None:
            PIDs = PIDs.filter(event_id=eventID)

        PIDs = PIDs.order_by('-timestamp').values_list('participant_id',
                                                       flat=True)

        qs = Participant.objects.filter(id__in=PIDs)

        paginator = CursorPaginator(qs, ordering=('-timestampApproved', ))
        page = paginator.page(first=count, after=after)
        return GalleryQuery(
            posts=page,
            totalCount=qs.count(),
            hasNext=page.has_next,
            lastCursor=paginator.cursor(page[-1]) if page else None)
Beispiel #9
0
    def resolve_listRequests(self, info, count=10, after=None):
        qs = ListRequest.objects.filter(respondent=self, )
        paginator = CursorPaginator(qs, ordering=('-timestamp', '-id'))
        page = paginator.page(first=count, after=after)

        requests = list()
        if page.items:
            for i in page.items:
                requests.append({
                    "actor": i.requester.username,
                    "timestamp": i.timestamp,
                    "actionType": "LIST_REQUEST",
                    "actionPhrase": "requested for a list from you",
                    "actionURL": "/new",
                    "resourceTitle": i.subject,
                    "resourceType": "MESSAGE"
                })

        return NotificationQuery(
            notifications=requests,
            hasNext=page.has_next,
            lastCursor=paginator.cursor(page[-1]) if page else None)
 def resolve_participants(self,
                          info,
                          eventID,
                          count: int = 25,
                          after: str = None,
                          search: str = None,
                          publicListing=False,
                          eliminatorListing=False,
                          judgeListing=False,
                          filters: ParticipantQueryFilters = None):
     if publicListing:
         qs = Participant.objects.filter(event_id=eventID,
                                         approver__isnull=False)
     elif eliminatorListing:
         if EventManager.objects.filter(
                 user_id=info.context.userID,
                 event_id=eventID,
                 canEliminateParticipants=True).exists():
             qs = Participant.objects.filter(event_id=eventID,
                                             approver__isnull=False,
                                             eliminator__isnull=True)
         else:
             raise APIException('Not allowed', code='FORBIDDEN')
     elif judgeListing:
         if EventManager.objects.filter(user_id=info.context.userID,
                                        event_id=eventID,
                                        canJudgeParticipants=True).exists():
             qs = Participant.objects.filter(event_id=eventID,
                                             approver__isnull=False,
                                             eliminator__isnull=True)
         else:
             raise APIException('Not allowed', code='FORBIDDEN')
     elif EventManager.objects.filter(user_id=info.context.userID,
                                      event_id=eventID,
                                      canReviewRegistrations=True).exists():
         qs = Participant.objects.filter(event_id=eventID)
     else:
         raise APIException(
             'You are not allowed to view registrations from this event',
             code='FORBIDDEN')
     if filters is not None:
         if filters.type is not None:
             qs = qs.filter(user__type=filters.type)
         if filters.startDate is not None:
             qs = qs.filter(timestampRegistered__gte=filters.startDate)
         if filters.endDate is not None:
             qs = qs.filter(timestampRegistered__lte=filters.endDate)
         if filters.verificationRequired:
             qs = qs.exclude(
                 Q(
                     Q(user__isnull=False) & Q(
                         Q(approver__isnull=False)
                         | Q(user__affiliationTitle__isnull=True)
                         | Q(user__affiliationBody__isnull=True)
                         | Q(user__country__isnull=True)
                         | Q(user__type__isnull=True)
                         # Q(
                         #     Q(user__phone__isnull=True) &
                         #     Q(user__country__exact='India')
                         # )
                         # Q(user__IDCard='') |
                         # Q(user__IDCard__exact=None)
                     ))
                 | Q(Q(team__isnull=False) & Q(approver__isnull=False)))
         if filters.status:
             if filters.status == 'APPROVED':
                 qs = qs.filter(timestampApproved__isnull=False,
                                approver__isnull=False)
             elif filters.status == 'NO_ID':
                 qs = qs.filter(user__IDCard='')
             elif filters.status == 'EMAIL_UNVERIFIED':
                 qs = qs.filter(user__isEmailVerified=False)
             elif filters.status == 'PHONE_UNVERIFIED':
                 qs = qs.filter(user__isPhoneVerified=False)
     if search is not None:
         qs = qs.filter(
             Q(user__isnull=True) | Q(user__username__istartswith=search)
             | Q(user__name__istartswith=search)
             | Q(user__phone__contains=search)
             | Q(user__email__exact=search))
     qs = qs.prefetch_related('user')
     paginator = CursorPaginator(qs, ordering=('-timestampRegistered', ))
     page = paginator.page(first=count, after=after)
     return ParticipantsQuery(
         participants=page,
         totalCount=qs.count(),
         hasNext=page.has_next,
         lastCursor=paginator.cursor(page[-1]) if page else None)