Ejemplo n.º 1
0
def _filter_timestamp(data):
    timestamp_filter = {}
    start = _get_data(data, 'timestamp_start')
    if start is not None:
        timestamp_filter['ge'] = util.parse_datetime(
            start, exception_handler.BadRequest
        )
    end = _get_data(data, 'timestamp_end')
    if end is not None:
        timestamp_filter['le'] = util.parse_datetime(
            end, exception_handler.BadRequest)
    range = _get_data_list(data, 'timestamp_range')
    if range:
        timestamp_filter['between'] = []
        for value in range:
            timestamp_filter['between'].append(
                util.parse_datetime_range(
                    value, exception_handler.BadRequest
                )
            )
    data['timestamp'] = timestamp_filter
    _clean_data(
        data,
        [
            'timestamp_start', 'timestamp_end',
            'timestamp_range'
        ]
    )
Ejemplo n.º 2
0
def _login(use_cookie):
    """User login helper function."""
    data = _get_request_data()
    if 'email' not in data or 'password' not in data:
        raise exception_handler.BadRequest(
            'missing email or password in data'
        )
    if 'expires' not in data:
        expire_timestamp = (
            datetime.datetime.now() + app.config['REMEMBER_COOKIE_DURATION']
        )
    else:
        expire_timestamp = util.parse_datetime(
            data['expires'], exception_handler.BadRequest
        )

    data['expire_timestamp'] = expire_timestamp
    user = auth_handler.authenticate_user(**data)
    if not login_user(user, remember=data.get('remember', False)):
        raise exception_handler.UserDisabled('failed to login: %s' % user)

    user_log_api.log_user_action(user.id, request.path)
    response_data = {'id': user.id}
    user_api.record_user_token(
        user, user.token, user.expire_timestamp
    )
    if not use_cookie:
        response_data['token'] = user.token
        response_data['expires'] = util.format_datetime(user.expire_timestamp)

    return utils.make_json_response(200, response_data)
Ejemplo n.º 3
0
 def test_correct_format(self):
     date_time = '2014-7-10 9:10:40'
     parsed_datetime = util.parse_datetime(date_time)
     expected_datetime = datetime.datetime(2014, 7, 10, 9, 10, 40)
     self.assertEqual(parsed_datetime, expected_datetime)
Ejemplo n.º 4
0
 def test_correct_format(self):
     date_time = '2014-7-10 9:10:40'
     parsed_datetime = util.parse_datetime(date_time)
     expected_datetime = datetime.datetime(2014, 7, 10, 9, 10, 40)
     self.assertEqual(parsed_datetime, expected_datetime)