Exemple #1
0
    def post(self, user_token):
        json_data = request.get_json(force=True)
        user = User.objects(token=user_token).first()
        if user is None:
            return { 'status': 'Error' }

        if 'subscribe' in json_data:
            status = subscribe(user, json_data['subscribe'])
            return { 'status': 'Ok' if status else 'Error' }

        if 'unsubscribe' in json_data:
            status = unsubscribe(user, json_data['unsubscribe'])
            return { 'status': 'Ok' if status else 'Error' }

        if 'country' in json_data:
            user.country = json_data['country']

        if 'crunchyroll_premium' in json_data:
            user.crunchyroll_premium = True if json_data['crunchyroll_premium'] else False

        if 'funimation_premium' in json_data:
            user.funimation_premium = True if json_data['funimation_premium'] else False

        user.save()
        return { 'status': 'Ok' }
Exemple #2
0
    def get(self, user_token):
        user = User.objects(token=user_token).first()
        if user is None:
            user = User()
            user.token = user_token
            user.save()

        return user.json()
Exemple #3
0
    def get(self, series_id=None, network_id=None, user_token=None, **kwargs):
        singleton = False
        limit_results = True
        if series_id is not None:
            singleton = True
            kwargs.update({ '_id': series_id })

        if user_token is not None:
            limit_results = False
            user = User.objects(token=user_token).first()
            subscriptions = user.subscriptions if user is not None else []
            kwargs.update({ '_id__in': map(lambda s: s._id, subscriptions) })

        if network_id is not None:
            kwargs.update({ 'network': network_id })

        query = request.args.get('q', None)
        data = super(SeriesResource, self).get(Series, singleton, limit_results, **kwargs)
        if query is not None and data['count'] <= self.THRESHOLD:
            search_from_television(query, limit=self.SEARCH_LIMIT)
            return super(SeriesResource, self).get(Series, singleton, limit_results, **kwargs)
        return data