示例#1
0
    def get(self, user_token):
        jwt = UserToken.query.filter_by(token=user_token).first()

        time = datetime.datetime.utcnow()

        if jwt and jwt.expires > time:
            return Result.custom({'isValid': True}, 200)

        return Result.custom({'isValid': False}, 400)
示例#2
0
    def get(self):

        ins_id = request.args.get('installation_id')

        if ins_id is None:
            raise HttpException('Missing required query string', 400)

        follow_ups = InstallationFollowUp.query.options(
            joinedload('alert_group'),
            joinedload('alert_group.users').load_only(User.first_name,
                                                      User.last_name, User.id,
                                                      User.email),
            lazyload('alert_group.users.roles'),
            lazyload('alert_group.users.attributes'),
            joinedload('comments'),
            joinedload('comments.user').load_only(User.first_name,
                                                  User.last_name, User.id,
                                                  User.email),
            lazyload('comments.user.roles'),
            lazyload('comments.user.attributes'),
        ).filter_by(installation_id=ins_id).all()

        result = []
        for follow_up in follow_ups:
            result.append({
                'next_follow_up':
                str(follow_up.next_follow_up.isoformat()),
                'alert_group': {
                    'name':
                    follow_up.alert_group.name,
                    'users': [{
                        'name':
                        '{} {}'.format(user.first_name, user.last_name),
                        'email':
                        user.email,
                        'id':
                        user.id
                    } for user in follow_up.alert_group.users]
                },
                'comments': [{
                    'comment': comment.comment,
                    'date': str(comment.date.isoformat()),
                    'user': {
                        'name':
                        '{} {}'.format(comment.user.first_name,
                                       comment.user.last_name),
                        'email':
                        comment.user.email,
                        'id':
                        comment.user.id
                    }
                } for comment in follow_up.comments]
            })

        return Result.custom(result)
示例#3
0
    def get(self):
        total_unread = UserMessage.query.filter_by(user_id=request.user.id, read=False).count()
        page = request.args.get('page', 1)
        paginator = Paginator(
            UserMessage.query.filter_by(user_id=request.user.id),
            int(page),
            request.args.get('orderBy', 'date'),
            request.args.get('orderDir', 'desc')
        )
        total_pages = paginator.total_pages

        return Result.custom(
            {'list': paginator.get_items(), 'page': page, 'total_pages': total_pages, 'total_unread': total_unread}
        )