Beispiel #1
0
    def post(self):
        data = json_decode(self.request.body)
        schema = {
            # TODO get customer_id from session
            # and set like an additional(not required) field
            # if auth user is booking a room for third-part person
            'customer_id': {
                'type': 'integer',
                'required': True},
            'room_id': {
                'type': 'integer',
                'required': True},
            'from_date': {
                'type': 'string',
                'required': True},
            'to_date': {
                'type': 'string',
                'required': True},
        }
        if not self.valid_data(schema, data):
            return

        customer_id = data['customer_id']
        room_id = data['room_id']
        from_date = parse_date(data['from_date'])
        to_date = parse_date(data['to_date'])

        room = Room.get_available_between_dates_by_id(room_id, from_date.isoformat(), to_date.isoformat())

        if not room:
            self.set_response(
                content={'message': ('The room with id {} is not available '
                                     'for booking from {} to {}').format(room_id, from_date, to_date)},
                status=404)
            return

        # TODO add payment system
        # change on next step with payment system
        status = Status.get(name='reserved')

        # TODO get customer_id from session
        try:
            customer = Customer.get(id=customer_id)
        except Customer.DoesNotExist:
            self.set_response(
                {'message': 'Customer with id {} not found'.format(customer_id)},
                status=400)
            return

        booking = Booking.create(
            room=room,
            customer=customer,
            from_date=from_date,
            to_date=to_date,
            status=status)
        self.set_response(
            content=dict(booking=model_to_dict(booking)),
            status=201,
            headers={'Location': self.reverse_url('booking', booking.id)}
        )
Beispiel #2
0
 def _get_booking_date(self):
     from_date = self.get_argument('from', '')
     to_date = self.get_argument('to', '')
     if not (from_date or to_date):
         raise ValueError('Missing params: [from] or(and) [to]')
     from_date = parse_date(from_date)
     to_date = parse_date(to_date)
     if from_date >= to_date:
         raise ValueError('start date {} must be less stop date {}'.format(from_date, to_date))
     return from_date, to_date
def user(username, start_date, end_date, only_authored):
    try:
        if start_date == '':
            start_date = STEEM_START_DATE
        else:
            start_date = parse_date(start_date)

        if end_date == '':
            end_date = datetime.now().date()
        else:
            end_date = parse_date(end_date)
    except ValueError:
        print('Invalid date format, must be \'YYYY-MM-DD\'')
        exit()
    archive.archive_user_history(username, start_date, end_date, only_authored)
Beispiel #4
0
def fetch_user_history_rows(username, start_date, end_date, comment_keys,
                            only_authored):
    num_posts = 0
    num_comments = 0
    current_date = None

    # Iterate through the user history. Note that the comment operations returned from the history
    # api call are not the same as the full comments, they are missing certain information such as
    # root author and root permlink.
    for comment_op in fetch_user_comment_ops(username):
        op_date = parse_date(comment_op['timestamp'])
        if op_date > end_date:
            continue
        if op_date < start_date:
            break

        if op_date != current_date:
            current_date = op_date
            print_with_timestamp(f'Searching history for {current_date}')

        post_comments = fetch_comment_op_thread(comment_op, comment_keys,
                                                username, only_authored)
        num_posts += 1
        num_comments += len(post_comments)
        yield format_comment_rows(post_comments)

    print_with_timestamp(
        f'Fetched {num_posts} posts with {num_comments} comments')
Beispiel #5
0
def index(request):
    start_point = request.GET.get('from')
    end_point = request.GET.get('to')
    date = request.GET.get('date')

    start_points = Trip.objects.values('start_point').distinct()  # cache?
    end_points = Trip.objects.values('end_point').distinct()

    if start_point and end_point and date:
        start_point = start_point.upper().encode('utf-8')
        end_point = end_point.upper().encode('utf-8')
        date = date.encode('utf-8')
        formatted_date = helpers.parse_date(date)
        trips = Trip.objects.all().filter(start_point=start_point,
                                          end_point=end_point,
                                          date=formatted_date).order_by('-start_time').reverse()

        context_dict = {'start_point': start_point,
                        'end_point': end_point,
                        'date': date,
                        'start_points': start_points,
                        'end_points': end_points,
                        'trips': trips}
    else:
        context_dict = {'start_points': start_points,
                        'end_points': end_points,
                        'index_flag': True}

    return render(request, 'app/index.html', context_dict)
Beispiel #6
0
def comment_is_not_found(comment):
    return parse_date(comment['created']) == UNIX_DATE_0
Beispiel #7
0
 def test_parse_date(self):
     today = datetime.date.today()
     parsed = helpers.parse_date(today.strftime('%x'))
     self.assertEquals(today, parsed)
     with self.assertRaises(ValueError) as cm:
         helpers.parse_date('12/12-22')