Example #1
0
 def check_min_days(self, from_date, to_date):
     need_days = (to_date - from_date).days
     date_gen = daterange(from_date, to_date)
     for d in date_gen:
         if Availability.objects.get(room=self, date=d).min_days > need_days:
             return False
     return True
Example #2
0
 def get_context_data(self, **kwargs):
     f_date = self.request.GET.get('from') or None
     t_date = self.request.GET.get('to') or None
     days_of_week = self.request.GET.getlist('days_of_week') or None
     # Call the base implementation first to get a context
     context = super(CabinetRates, self).get_context_data(**kwargs)
     context['hotel_count'] = Hotel.objects.filter(city=self.object.city).count()
     context['tab'] = 'rates'
     context['hotel'] = self.object
     context['title_line'] = _('private cabinet')
     if 'room' in self.kwargs.keys():
         context['room_id'] = int(self.kwargs['room'])
     else:
         try:
             context['room_id'] = Room.objects.filter(hotel=self.object)[0].id
         except IndexError:
             pass
     if f_date is not None and t_date is not None:
         from_date = convert_to_date(f_date)
         to_date = convert_to_date(t_date)
         if from_date > to_date:
             from_date, to_date = to_date, from_date
         if (to_date-from_date).days > 365:
             to_date = from_date+timedelta(days=365)
         date_gen = daterange(from_date, to_date+timedelta(days=1))
     else :
         from_date = datetime.now()
         to_date = from_date+timedelta(days=14)
         date_gen = daterange(from_date, to_date)
         f_date = datetime.strftime(from_date,"%d.%m.%Y")
         t_date = datetime.strftime(to_date,"%d.%m.%Y")
     if from_date < to_date:
         context['search_dates'] = {'from_date':f_date, 'to_date':t_date}
     else:
         context['search_dates'] = {'from_date':t_date, 'to_date':f_date}
     date_period = []
     for i in date_gen:
         if days_of_week:
             if str(i.isoweekday()) in days_of_week:
                 date_period.append(i)
         else:
             date_period.append(i)
     context['dates'] = date_period
     context['days_of_week'] = days_of_week
     return context
Example #3
0
def room_full_amount(context, room):
    request = context['request']
    search_data = context['search_data']
    f_date = search_data['from_date']
    t_date = search_data['to_date']
    guests = search_data['guests']
    from_date = convert_to_date(f_date)
    to_date = convert_to_date(t_date)
    delta = (to_date - from_date).days
    room_all_amount = 0
    for single_date in daterange(from_date, to_date):
        room_all_amount += room.amount_on_date_guest_variant(single_date, guests)[0]
    result = room_all_amount
    return amount_request_currency(request, result)
Example #4
0
def room_price_average(context, room):
    request = context["request"]
    search_data = context["search_data"]
    f_date = search_data["from_date"]
    t_date = search_data["to_date"]
    guests = search_data["guests"]
    from_date = convert_to_date(f_date)
    to_date = convert_to_date(t_date)
    delta = (to_date - from_date).days
    room_all_amount = 0
    for single_date in daterange(from_date, to_date):
        room_all_amount += room.amount_on_date_guest_variant(single_date, guests)[0]
    result = room_all_amount / delta
    return amount_request_currency(request, result)