Ejemplo n.º 1
0
class DiscoveryQueries(graphene.ObjectType):
    featuredLists = graphene.List(
        FeaturedList,
    )
    relatedLists = graphene.List(
        ListType,
        list=ListSelectInput(required=True)
    )

    @staticmethod
    def resolve_featuredLists(self, info):
        return FeaturedListModel.objects.all().order_by('-timestamp')[:6]

    @staticmethod
    def resolve_relatedLists(self, info, list):
        lists = List.objects.filter((Q(slug=list.slug) | Q(id=list.id)))
        if lists.count() == 1:
            l = lists.first()
            relatedListByUser = List.objects.filter(
                Q(curator=l.curator)
            ).exclude(id=l.id)
            relatedListByTopics = List.objects.filter(
                Q(topic=l.topic)
            ).exclude(id=l.id)
            qs = relatedListByUser.intersection(relatedListByTopics)
            if qs.count() < 5:
                qs = qs.union(relatedListByTopics)
            if qs.count() < 5:
                qs = qs.union(relatedListByUser)
            return qs[:5]
        else:
            raise APIException('Invalid list passed', code="INVALID_LIST")
Ejemplo n.º 2
0
 class Arguments:
     object = graphene.Argument(ItemInput,
                                required=True,
                                description='Item object')
     list = ListSelectInput()
     position = graphene.Int(
         required=False,
         description=
         'Requested position in the list for the submitted entry be added')
Ejemplo n.º 3
0
class ListQueries(graphene.ObjectType):
    list = graphene.Field(
        ListObj,
        slug=graphene.String(required=True),
        username=graphene.String(required=False)
    )
    lists = graphene.Field(
        ListQuery,
        query=ListQueryInput(required=True),
        count=graphene.Int(),
        after=graphene.String()
    )
    listEntries = graphene.Field(
        ListEntryQuery,
        list=ListSelectInput(required=True),
        count=graphene.Int(),
        after=graphene.String()
    )

    @staticmethod
    def resolve_list(self, info, slug, username=None, **kwargs):
        try:
            if username is not None:
                listObj = List.objects.get(slug=slug, curator__username=username)
            else:
                listObj = List.objects.get(slug=slug)
            if listObj.isActive:
                if not listObj.isPrivate:
                    return listObj
                else:
                    user = info.context.user
                    if user is None:
                        raise APIException("The list is private. Login required to view the list", code='LOGIN_REQUIRED')
                    # @todo check if user is following owner, and owner allowed user
                    try:
                        UserSubscription.objects.get(user=listObj.curator, subscriber=user)
                        return listObj
                    except UserSubscription.DoesNotExist:
                        raise APIException("The list is private, you need to subscription required to view this list", code='NO_SUBSCRIPTION')
            else:
                # @todo find reason and return exact reason for being inactive
                raise APIException("The list has been taken down or removed.", code='LIST_INACTIVE')

        except List.DoesNotExist:
            raise APIException("The list queried does not exit", code='LIST_NOT_FOUND')

    @staticmethod
    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
        )

    @login_required
    @user_can_edit_list
    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")
Ejemplo n.º 4
0
 class Arguments:
     list = ListSelectInput(required=True)
Ejemplo n.º 5
0
 class Arguments:
     list = ListSelectInput(required=True)
     input = graphene.Argument(
         ListInput,
         description='Fields to be updated in the list',
         required=True)
Ejemplo n.º 6
0
 class Arguments:
     list = ListSelectInput(required=True)
     itemID = graphene.String(required=True)
Ejemplo n.º 7
0
 class Arguments:
     list = ListSelectInput()
     subject = graphene.String(required=True)
     remarks = graphene.String()
Ejemplo n.º 8
0
 class Arguments:
     list = ListSelectInput()
     direction = graphene.Argument(
         graphene.Enum('Direction', [('up', 1), ('down', 0)]))
     id = graphene.String(required=True)
Ejemplo n.º 9
0
 class Arguments:
     list = ListSelectInput()
     id = graphene.String(required=True)
     object = graphene.Argument(ItemInput, required=True)