Beispiel #1
0
    def get(self,
            account=None,
            task_uuid=None,
            start=None,
            end=None,
            lapse='hours',
            page_num=1):
        '''
            Get tasks
        '''
        # request query arguments
        query_args = self.request.arguments
        # get the current frontend username from token
        username = self.get_username_token()
        # if the user don't provide an account we use the username as last resort
        account = (query_args.get('account', [username])[0] if not account else account)
        # query string checked from string to boolean
        checked = str2bool(str(query_args.get('checked', [False])[0]))
        # getting pagination ready
        page_num = int(query_args.get('page', [page_num])[0])

        search = (query_args.get('search', [search])[0] if not search else search)
        
        # rage against the finite state machine
        status = 'all'
        # init message on error
        message = {'error':True}
        # init status that match with our message
        self.set_status(400)
        # check if we're list processing
        if not task_uuid and search:
            message = yield self.quick_search(account, start, end, lapse, status, page_num, fields, search)
            self.set_status(200)
        elif not task_uuid:
            message = yield self.get_task_list(account,
                                               start,
                                               end,
                                               lapse,
                                               status,
                                               page_num)
            self.set_status(200)
        # single task received
        else:
            # first try to get stuff from cache
            task_uuid = task_uuid.rstrip('/')
            # get cache data
            message = self.cache.get('tasks:{0}'.format(task_uuid))
            if message is not None:
                logging.info('tasks:{0} done retrieving!'.format(task_uuid))
                self.set_status(200)
            else:
                message = yield self.get_task(account, task_uuid)
                if self.cache.add('tasks:{0}'.format(task_uuid), message, 1):
                    logging.info('new cache entry {0}'.format(str(task_uuid)))
                    self.set_status(200)
        # so long and thanks for all the fish
        self.finish(message)
Beispiel #2
0
    def get(self,
            account=None,
            task_uuid=None,
            start=None,
            end=None,
            lapse='hours',
            page_num=1):
        '''
            Get tasks
        '''
        # request query arguments
        query_args = self.request.arguments
        # get the current frontend username from token
        username = self.get_username_token()
        # if the user don't provide an account we use the username as last resort
        account = (query_args.get('account', [username])[0]
                   if not account else account)
        # query string checked from string to boolean
        checked = str2bool(str(query_args.get('checked', [False])[0]))
        # getting pagination ready
        page_num = int(query_args.get('page', [page_num])[0])

        search = (query_args.get('search', [search])[0]
                  if not search else search)

        # rage against the finite state machine
        status = 'all'
        # init message on error
        message = {'error': True}
        # init status that match with our message
        self.set_status(400)
        # check if we're list processing
        if not task_uuid and search:
            message = yield self.quick_search(account, start, end, lapse,
                                              status, page_num, fields, search)
            self.set_status(200)
        elif not task_uuid:
            message = yield self.get_task_list(account, start, end, lapse,
                                               status, page_num)
            self.set_status(200)
        # single task received
        else:
            # first try to get stuff from cache
            task_uuid = task_uuid.rstrip('/')
            # get cache data
            message = self.cache.get('tasks:{0}'.format(task_uuid))
            if message is not None:
                logging.info('tasks:{0} done retrieving!'.format(task_uuid))
                self.set_status(200)
            else:
                message = yield self.get_task(account, task_uuid)
                if self.cache.add('tasks:{0}'.format(task_uuid), message, 1):
                    logging.info('new cache entry {0}'.format(str(task_uuid)))
                    self.set_status(200)
        # so long and thanks for all the fish
        self.finish(message)
Beispiel #3
0
 def get(self,
         account=None,
         user_uuid=None,
         start=None,
         end=None,
         lapse='hours',
         page_num=1):
     '''
         Get user accounts
     '''
     # request query arguments
     query_args = self.request.arguments
     username = False  # TODO: get the username from a front-end token!
     # if the user don't provide an account use the username as last resort
     account = (query_args.get('account', [username])[0]
                if not account else account)
     # query string checked from string to boolean
     checked = str2bool(str(query_args.get('checked', [False])[0]))
     logging.info('Why? what are u checking? {0}'.format(checked))
     # getting pagination ready
     page_num = int(query_args.get('page', [page_num])[0])
     # rage against the state machine
     status = 'all'  # TODO: Why 'all' ?
     # init message on error
     message = {'error': True}
     # init status that match with our message
     self.set_status(400)
     # check if we're list processing
     if not user_uuid:
         # TODO: missing account, start, end, lapse and status support!
         message = yield self.get_user_list(account, start, end, lapse,
                                            status, page_num)
         self.set_status(200)
     else:
         user_uuid = user_uuid.rstrip('/')
         message = yield self.get_user(account, user_uuid)
         self.set_status(200)
     # so long and thanks for all the fish
     self.finish(message)