Exemplo n.º 1
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
     guests = guests_from_request(self.request)
     # Call the base implementation first to get a context
     context = super(HotelDetail, self).get_context_data(**kwargs)
     context['tab'] = 'description'
     context['city'] = self.object.city
     context['hotels_in_city'] = Hotel.objects.filter(city=self.object.city).count()
     context['title_line'] = self.object.get_name
     context['hotel_options'] = self.object.option.order_by('category','order_in_list','name')
     context['search_url'] = self.object.get_absolute_url()
     try:
         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
             f_date, t_date = t_date, f_date
         context['free_room'] = self.object.free_room(from_date,to_date,guests)
         search_data = {'from_date':f_date, 'to_date':t_date, 'guests':guests, 'city':self.object.city}
         context['search'] = 1
         context['search_data'] = search_data
         context['search_count'] = Hotel.objects.filter(city=self.object.city).count()
     except :
         pass
     return context
Exemplo n.º 2
0
def client_days_booking(context):
    search_data = context['search_data']
    f_date = search_data['from_date']
    t_date = search_data['to_date']
    from_date = convert_to_date(f_date)
    to_date = convert_to_date(t_date)
    delta = (to_date - from_date).days
    return int(delta)
Exemplo n.º 3
0
def client_days_booking(context):
    search_data = context["search_data"]
    f_date = search_data["from_date"]
    t_date = search_data["to_date"]
    from_date = convert_to_date(f_date)
    to_date = convert_to_date(t_date)
    delta = (to_date - from_date).days
    return int(delta)
Exemplo n.º 4
0
def dates_guests_from_context(context):
    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
    date_period = (from_date, to_date - timedelta(days=1))
    return from_date, to_date, date_period, delta, guests
Exemplo n.º 5
0
def dates_guests_from_context(context):
    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
    date_period = (from_date, to_date - timedelta(days=1))
    return from_date, to_date, date_period, delta, guests
Exemplo n.º 6
0
 def get_queryset(self):
     try:
         f_date = self.request.GET.get('from')
         from_date = convert_to_date(f_date)
         t_date = self.request.GET.get('to')
         to_date = convert_to_date(t_date)
         if from_date > to_date:
             from_date, to_date = to_date, from_date
         return Booking.objects.filter(date__range=(from_date, to_date))
     except :
         return Booking.objects.all()
Exemplo n.º 7
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)
Exemplo n.º 8
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)
Exemplo n.º 9
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
     guests = guests_from_request(self.request)
     if f_date and t_date and guests and ('room' in self.kwargs.keys()):
         try:
             room_id = int(self.kwargs['room'])
         except ValueError:
             raise Http404
         room = get_object_or_404(Room,id=room_id)
         if room.hotel.payment_method.count() <1:
             raise Http404
         s = SettlementVariant.objects.filter(room=room).values_list('settlement', flat=True)
         if guests > max(s):
             raise Http404
         from_date = convert_to_date(f_date)
         to_date = convert_to_date(t_date)
         if from_date > to_date:
             f_date,t_date = t_date,f_date
             from_date,to_date = to_date,from_date
         if (from_date-datetime.now()).days < -1:
             raise Http404
         avail_count = Availability.objects.filter(room=room,
             date__range=(from_date, to_date-timedelta(days=1)),placecount__gt=0).count()
         if avail_count <> (to_date-from_date).days:
             raise Http404
         settlement = SettlementVariant.objects.filter(room=room,
             settlement__gte=guests, enabled=True).order_by('settlement')[0]
         #settlement = get_object_or_404(SettlementVariant,room=room,settlement=guests,enabled=True)
         valid_price_count = PlacePrice.objects.filter(settlement=settlement,
             date__range=(from_date, to_date-timedelta(days=1)),amount__gt=0).count()
         if valid_price_count <> (to_date-from_date).days:
             raise Http404
         context = super(ClientBooking, 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'] = _('booking')
         context['room_id'] = room_id
         context['room'] = room
         context['settlements'] = s
         context['search_data'] = {'from_date':f_date, 'to_date':t_date, 'guests':guests}
         return context
     else :
         raise Http404
Exemplo n.º 10
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
Exemplo n.º 11
0
def get_booking_amount(request):
    try:
        room_id = request.REQUEST['room_id']
        s = request.REQUEST['guests']
        from_date = convert_to_date(request.REQUEST['from'])
        to_date = convert_to_date(request.REQUEST['to'])
        room = Room.objects.get(id=room_id)
        settlement = SettlementVariant.objects.filter(room=room, settlement=s)
        delta = to_date-from_date
        all_amount = 0
        on_date = from_date
        while on_date < to_date:
            price = PlacePrice.objects.get(settlement=settlement, date = on_date)
            all_amount +=int(price.amount)
            on_date = on_date+timedelta(days=1)
        all_amount = str(all_amount)+price.currency.code
        payload = {'success': True, 'dayscount':delta.days, 'amount':all_amount}
    except :
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Exemplo n.º 12
0
 def get_queryset(self):
     self.object = self.get_object()
     f_date = self.request.GET.get('from') or None
     t_date = self.request.GET.get('to') or None
     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)
     else :
         from_date = datetime.now()
         to_date = from_date+timedelta(days=14)
         f_date = datetime.strftime(from_date,"%d.%m.%Y")
         t_date = datetime.strftime(to_date,"%d.%m.%Y")
     if from_date < to_date:
         self.search_dates = {'from_date':f_date, 'to_date':t_date}
     else:
         from_date, to_date = to_date, from_date
         self.search_dates = {'from_date':t_date, 'to_date':f_date}
     return Bill.objects.for_object(self.object)
Exemplo n.º 13
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
     guests = guests_from_request(self.request)
     context = super(RoomDetail, self).get_context_data(**kwargs)
     if self.object.hotel is not None:
         context['city'] = self.object.hotel.city
         context['title_line'] = self.object.hotel.get_name
         context['hotels_in_city'] = Hotel.objects.filter(city=self.object.hotel.city).count()
         context['search_url'] = self.object.hotel.get_absolute_url()
     context['tab'] = 'description'
     context['room_options'] = self.object.option.order_by('category','order_in_list','name')
     if f_date and t_date and guests:
         from_date = convert_to_date(f_date)
         to_date = convert_to_date(t_date)
         if from_date > to_date:
             f_date, t_date = t_date, f_date
         search_data = {'from_date': f_date, 'to_date': t_date, 'guests': guests, 'city': self.object.hotel.city}
         context['search_data'] = search_data
         context['search'] = 1
         context['search_count'] = Hotel.objects.filter(city=self.object.hotel.city).count()
     return context
Exemplo n.º 14
0
def filter_hotels_on_map(request, hotels):
    try:
        searched = hotels
        f_date = request.POST.get("start_date") or None
        amount_min = request.POST.get("amount_min") or None
        amount_max = request.POST.get("amount_max") or None
        options = request.POST.getlist("options") or None
        stars = request.POST.getlist("stars") or None
        if amount_max and amount_min:
            if f_date:
                from_date = convert_to_date(f_date)
                hotels_with_amount = (
                    PlacePrice.objects.filter(date=from_date, amount__range=(amount_min, amount_max))
                    .values_list("settlement__room__hotel__pk", flat=True)
                    .distinct()
                )
            else:
                hotels_with_amount = (
                    PlacePrice.objects.filter(date=now(), amount__range=(amount_min, amount_max))
                    .values_list("settlement__room__hotel__pk", flat=True)
                    .distinct()
                )
            searched = searched.filter(pk__in=hotels_with_amount, work_on_request=False)
        if options:
            for option in options:
                searched = searched.filter(option=option)
        if stars:
            searched = searched.filter(starcount__in=stars)
        searched = searched.order_by("starcount")
        results = []
        for hotel in searched:
            answer = {
                "name": hotel.get_name,
                "latitude": hotel.latitude,
                "url": hotel.get_absolute_url(),
                "address": hotel.address,
                "id": hotel.pk,
                "starcount": hotel.starcount,
                "img": make_thumbnail(hotel.main_image, width=113, height=75, aspect=1),
                "longitude": hotel.longitude,
                "starcount_name": hotel.get_starcount_display(),
                "amount": str(int(hotel.current_amount)),
            }

            results.append(answer)
        payload = {"success": True, "hotels": results}
    except:
        payload = {"success": False}
    return ajax_answer_lazy(payload)
Exemplo n.º 15
0
def invoice_create(request, city, slug):
    try:
        if not request.user.is_superuser:
            raise AccessError
        hotel = Hotel.objects.get(city__slug=city, slug=slug)
        bill = Bill()
        bill.user = request.user
        bill.amount = request.POST['amount']
        bill.date_billed = convert_to_date(request.POST['date_billed'])
        bill.status = BILL_UNKNOWN
        bill.description_small = request.POST['description_small']
        bill.invoice_number = request.POST['invoice_number']
        bill.content_object = hotel
        bill.currency = Currency.objects.get(code=setting('DEFAULT_CURRENCY', 'RUB'))
        bill.save()
        payload = {'success': True}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Exemplo n.º 16
0
def invoice_create(request, city, slug):
    try:
        if not request.user.is_superuser:
            raise AccessError
        hotel = Hotel.objects.get(city__slug=city, slug=slug)
        bill = Bill()
        bill.user = request.user
        bill.amount = request.POST['amount']
        bill.date_billed = convert_to_date(request.POST['date_billed'])
        bill.status = BILL_UNKNOWN
        bill.description_small = request.POST['description_small']
        bill.invoice_number = request.POST['invoice_number']
        bill.content_object = hotel
        bill.currency = Currency.objects.get(code=setting('DEFAULT_CURRENCY', 'RUB'))
        bill.save()
        payload = {'success': True}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Exemplo n.º 17
0
def filter_hotels_on_map(request, hotels):
    try:
        searched = hotels
        f_date = request.POST.get('start_date') or None
        amount_min = request.POST.get('amount_min') or None
        amount_max = request.POST.get('amount_max') or None
        options = request.POST.getlist('options') or None
        stars = request.POST.getlist('stars') or None
        if amount_max and amount_min:
            if f_date:
                from_date = convert_to_date(f_date)
                hotels_with_amount = PlacePrice.objects.filter(date=from_date,
                    amount__range=(amount_min, amount_max)).values_list('settlement__room__hotel__pk',
                    flat=True).distinct()
            else:
                hotels_with_amount = PlacePrice.objects.filter(date=now(),
                    amount__range=(amount_min, amount_max)).values_list('settlement__room__hotel__pk',
                    flat=True).distinct()
            searched = searched.filter(pk__in=hotels_with_amount, work_on_request=False)
        if options:
            for option in options:
                searched = searched.filter(option=option)
        if stars:
            searched = searched.filter(starcount__in=stars)
        searched = searched.order_by('starcount')
        results = []
        for hotel in searched:
            answer = {'name': hotel.get_name, 'latitude': hotel.latitude, 'url': hotel.get_absolute_url(),
                      'address': hotel.address, 'id': hotel.pk, 'starcount': hotel.starcount,
                      'img': make_thumbnail(hotel.main_image, width=113, height=75, aspect=1),
                      'longitude': hotel.longitude, 'starcount_name': hotel.get_starcount_display(),
                      'amount': str(int(hotel.current_amount))}

            results.append(answer)
        payload = {'success': True, 'hotels': results}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Exemplo n.º 18
0
def filter_hotels_on_map(request, hotels):
    try:
        searched = hotels
        f_date = request.POST.get('start_date') or None
        amount_min = request.POST.get('amount_min') or None
        amount_max = request.POST.get('amount_max') or None
        options = request.POST.getlist('options') or None
        stars = request.POST.getlist('stars') or None
        if amount_max and amount_min:
            if f_date:
                from_date = convert_to_date(f_date)
                hotels_with_amount = PlacePrice.objects.filter(date=from_date,
                    amount__range=(amount_min, amount_max)).values_list('settlement__room__hotel__pk',
                    flat=True).distinct()
            else:
                hotels_with_amount = PlacePrice.objects.filter(date=now(),
                    amount__range=(amount_min, amount_max)).values_list('settlement__room__hotel__pk',
                    flat=True).distinct()
            searched = searched.filter(pk__in=hotels_with_amount, work_on_request=False)
        if options:
            for option in options:
                searched = searched.filter(option=option)
        if stars:
            searched = searched.filter(starcount__in=stars)
        searched = searched.order_by('starcount')
        results = []
        for hotel in searched:
            answer = {'name': hotel.get_name, 'latitude': hotel.latitude, 'url': hotel.get_absolute_url(),
                      'address': hotel.address, 'id': hotel.pk, 'starcount': hotel.starcount,
                      'img': make_thumbnail(hotel.main_image, width=113, height=75, aspect=1),
                      'longitude': hotel.longitude, 'starcount_name': hotel.get_starcount_display(),
                      'amount': str(int(hotel.current_amount))}

            results.append(answer)
        payload = {'success': True, 'hotels': results}
    except:
        payload = {'success': False}
    return ajax_answer_lazy(payload)
Exemplo n.º 19
0
def room_price_date(context, room, on_date):
    request = context['request']
    date = convert_to_date(on_date)
    room_price = room.amount_on_date(date)
    return amount_request_currency(request, room_price)
Exemplo n.º 20
0
def minprice_hotel_date(context, hotel, on_date):
    request = context['request']
    date = convert_to_date(on_date)
    hotel_price = hotel.amount_on_date(date)
    return amount_request_currency(request, hotel_price)
Exemplo n.º 21
0
def room_variant(context, room):
    search_data = context["search_data"]
    f_date = search_data["from_date"]
    guests = search_data["guests"]
    from_date = convert_to_date(f_date)
    return room.amount_on_date_guest_variant(from_date, guests)[1]
Exemplo n.º 22
0
def room_variant(context, room):
    search_data = context['search_data']
    f_date = search_data['from_date']
    guests = search_data['guests']
    from_date = convert_to_date(f_date)
    return room.amount_on_date_guest_variant(from_date, guests)[1]
Exemplo n.º 23
0
    def get_queryset(self):
        self.search_data = dict()
        order = self.request.GET.get('order') or None
        sort = self.request.GET.get('sort') or None
        options = self.request.GET.getlist('options') or None
        stars = self.request.GET.getlist('stars') or None
        notknowndates = self.request.GET.get('notknowndates') or None
        guests = guests_from_request(self.request)
        f_date = self.request.GET.get('from') or None
        t_date = self.request.GET.get('to') or None
        amount_min = self.request.GET.get('amount_min') or None
        amount_max = self.request.GET.get('amount_max') or None
        if amount_min:
            a_min = convert_from_client_currency(self.request, amount_min)
        if amount_max:
            a_max = convert_from_client_currency(self.request, amount_max)
        try:
            self.city = City.objects.get(slug=self.kwargs['slug'])
            hotels = Hotel.objects.filter(city=self.city)
        except :
            self.city = None
            hotels = Hotel.objects.all()
        self.tab = {'css_name':'asc','css_class':'desc','css_amount':'desc','css_review':'desc',
                    'order_name':'desc','order_class':'desc','order_amount':'desc','order_review':'desc',
                    'tab':'name'}

        if (notknowndates and self.city ) or (f_date and t_date and self.city):
            result = []
            try:
                from_date = convert_to_date(f_date)
                to_date = convert_to_date(t_date)
                if from_date > to_date:
                    self.search_data = {'from_date':t_date, 'to_date':f_date, 'guests':guests}
                    from_date, to_date = to_date, from_date
                else:
                    self.search_data = {'from_date':f_date, 'to_date':t_date, 'guests':guests}
                self.search_data['city'] = self.city
                for hotel in hotels:
                    if hotel.free_room(from_date,to_date,guests):
                        result.append(hotel.pk)
                search_hotel = Hotel.objects.filter(pk__in=result)
            except :
                search_hotel = hotels
            self.search = 1
        else :
            self.search = 0
            search_hotel = hotels
        if amount_max and amount_min:
            r = []
            for h in search_hotel:
                amount = h.min_current_amount
                if int(a_min) < amount < int(a_max):
                    r.append(h.pk)
            search_hotel = Hotel.objects.filter(pk__in=r)
        if options:
            for option in options:
                search_hotel = search_hotel.filter(option=option)
        if stars:
            search_hotel = search_hotel.filter(starcount__in=stars)
        if order:
            if order == 'name':
                self.tab['tab'] = 'name'
                if sort == 'desc':
                    result = search_hotel.order_by('-name')
                    self.tab['css_name'] = 'desc'
                    self.tab['order_name'] = 'asc'
                else:
                    result = search_hotel.order_by('name')
                    self.tab['css_name'] = 'asc'
                    self.tab['order_name'] = 'desc'
            elif order == 'class':
                self.tab['tab'] = 'class'
                if sort == 'asc':
                    result = search_hotel.order_by('starcount')
                    self.tab['css_class'] = 'asc'
                    self.tab['order_class'] = 'desc'
                else:
                    result = search_hotel.order_by('-starcount')
                    self.tab['css_class'] = 'desc'
                    self.tab['order_class'] = 'asc'
            elif order == 'amount':
                self.tab['tab'] = 'amount'
                if sort == 'asc':
                    result = search_hotel.order_by('current_amount')
                    self.tab['css_amount'] = 'asc'
                    self.tab['order_amount'] = 'desc'
                else:
                    result = search_hotel.order_by('-current_amount')
                    self.tab['css_amount'] = 'desc'
                    self.tab['order_amount'] = 'asc'
            elif order == 'review':
                self.tab['tab'] = 'review'
                if sort == 'asc':
                    result = search_hotel.order_by('point')
                    self.tab['css_review'] = 'asc'
                    self.tab['order_review'] = 'desc'
                else:
                    result = search_hotel.order_by('-point')
                    self.tab['css_review'] = 'desc'
                    self.tab['order_review'] = 'asc'
            else:
                pass
        else:
            result = search_hotel
        try:
            self.result_count = search_hotel.count()
        except:
            self.result_count = None
        return result
Exemplo n.º 24
0
 def get_queryset(self):
     on_date = convert_to_date(self.kwargs['on_date'])
     return Order.objects.filter(created_date__range=(on_date, on_date + timedelta(days=1)))
Exemplo n.º 25
0
 def get_queryset(self):
     on_date = convert_to_date(self.kwargs['on_date'])
     return Order.objects.filter(created_date__range=(on_date, on_date +
                                                      timedelta(days=1)))
Exemplo n.º 26
0
def room_price_date(context, room, on_date):
    request = context['request']
    date = convert_to_date(on_date)
    room_price = room.amount_on_date(date)
    return amount_request_currency(request, room_price)
Exemplo n.º 27
0
def minprice_hotel_date(context, hotel, on_date):
    request = context['request']
    date = convert_to_date(on_date)
    hotel_price = hotel.amount_on_date(date)
    return amount_request_currency(request, hotel_price)