def sync_app_state(request):
    earliest_pickup_time = ceil_datetime(trim_seconds(default_tz_now()) + datetime.timedelta(minutes=asap_interval()), minutes=booking_interval())
    latest_pickup_time = earliest_pickup_time + datetime.timedelta(hours=(24*14))
    dt_options = list(datetimeIterator(earliest_pickup_time, latest_pickup_time, delta=datetime.timedelta(minutes=booking_interval())))

    response = {
        "logged_in": request.user.is_authenticated(),
        "pickup_datetime_options": [to_js_date(opt) for opt in dt_options],
        "pickup_datetime_default_idx": 0,
        "asap_as_default": True,
        "booking_data": request.session.get(CURRENT_BOOKING_DATA_KEY)
    }

    passenger = Passenger.from_request(request)
    response["show_url"] = "" # change to cause child browser to open with passed url

    if passenger:
        response["authenticated"] = True
        response["passenger_picture_url"] = passenger.picture_url

        ongoing_order = get_ongoing_order(passenger)
        if ongoing_order:
            response["ongoing_order_id"] = ongoing_order.id

        future_orders = get_future_orders_for(passenger)
        response["future_orders_count"] = len(future_orders)

    trimed_response = response.copy()
    trimed_response['pickup_datetime_options'] = response['pickup_datetime_options'][:9] + ['...']
    logging.info("get_initial_status: %s" % trimed_response)

    return JSONResponse(response)
Beispiel #2
0
    def get_closest_active(self, dt_target, dt_start, dt_end, delta):

        dt_itr = datetimeIterator(from_datetime=dt_start, to_datetime=dt_end, delta=delta)
        active_dts = []

        for dt in dt_itr:
            if self.is_active(dt):
                active_dts.append(dt)

        if active_dts:
            active_dts = sorted(active_dts, key=lambda dt: abs(dt - dt_target))
            return active_dts[0]

        return None
Beispiel #3
0
    def get_closest_active(self, dt_target, dt_start, dt_end, delta):

        dt_itr = datetimeIterator(from_datetime=dt_start,
                                  to_datetime=dt_end,
                                  delta=delta)
        active_dts = []

        for dt in dt_itr:
            if self.is_active(dt):
                active_dts.append(dt)

        if active_dts:
            active_dts = sorted(active_dts, key=lambda dt: abs(dt - dt_target))
            return active_dts[0]

        return None
Beispiel #4
0
    def get_dates(self, start_date=None, end_date=None):
        """
        Dates on which the rule is active.
        @param start_date: a datetime.date lower bound.
        @param end_date: a datetime.date upper bound.
        @return: a list of dates.
        """
        dates = []
        if self.from_date and self.to_date:
            if self.from_date == self.to_date and start_date <= self.from_date <= end_date:
                dates = [self.from_date]
            elif self.from_date < self.to_date:
                d1 = max(start_date, self.from_date) if start_date else self.from_date
                d2 = min(end_date, self.to_date) if end_date else self.to_date
                dates = list(datetimeIterator(d1, d2))

        return dates
Beispiel #5
0
    def get_dates(self, start_date=None, end_date=None):
        """
        Dates on which the rule is active.
        @param start_date: a datetime.date lower bound.
        @param end_date: a datetime.date upper bound.
        @return: a list of dates.
        """
        dates = []
        if self.from_date and self.to_date:
            if self.from_date == self.to_date and start_date <= self.from_date <= end_date:
                dates = [self.from_date]
            elif self.from_date < self.to_date:
                d1 = max(start_date,
                         self.from_date) if start_date else self.from_date
                d2 = min(end_date, self.to_date) if end_date else self.to_date
                dates = list(datetimeIterator(d1, d2))

        return dates