Beispiel #1
0
def booking_sysadm(request, pk, action):
    if not request.is_ajax():
        raise Http404
    try:
        if not request.user.is_superuser:
            raise UserNotAllowed
        booking = Booking.objects.select_related().get(id=pk)
        if action == 'delete':
            from_date = booking.from_date
            to_date = booking.to_date
            settlement = booking.settlement
            while from_date < to_date:
                avail = Availability.objects.get(room=settlement.room, date=from_date)
                avail.placecount += 1
                avail.save()
                from_date += timedelta(days=1)
            booking_delete_client_mail(booking)
            booking.delete()
            url = reverse_lazy('bookings_list')
        elif action == 'enable':
            booking.enabled = True
            booking.save()
            booking_new_hotel_mail(booking)
            url = reverse_lazy('booking_admin_detail', args=[booking.uuid, ])
        else:
            raise UserNotAllowed
        payload = {'success': True, 'location': url}
    except UserNotAllowed:
        payload = {'success': False, 'error_msg': _('You are not allowed for this action.')}
    except:
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Beispiel #2
0
def booking_sysadm(request, pk, action):
    if not request.is_ajax():
        raise Http404
    try:
        if not request.user.is_superuser:
            raise UserNotAllowed
        booking = Booking.objects.select_related().get(id=pk)
        if action == 'delete':
            from_date = booking.from_date
            to_date = booking.to_date
            settlement = booking.settlement
            while from_date < to_date:
                avail = Availability.objects.get(room=settlement.room,
                                                 date=from_date)
                avail.placecount += 1
                avail.save()
                from_date += timedelta(days=1)
            booking_delete_client_mail(booking)
            booking.delete()
            url = reverse_lazy('bookings_list')
        elif action == 'enable':
            booking.enabled = True
            booking.save()
            booking_new_hotel_mail(booking)
            url = reverse_lazy('booking_admin_detail', args=[
                booking.uuid,
            ])
        else:
            raise UserNotAllowed
        payload = {'success': True, 'location': url}
    except UserNotAllowed:
        payload = {
            'success': False,
            'error_msg': _('You are not allowed for this action.')
        }
    except:
        payload = {'success': False}
    return AjaxLazyAnswer(payload)
Beispiel #3
0
 def form_valid(self, form):
     use_card = False
     p_m = self.request.REQUEST.get('payment_method') or None
     if p_m:
         payment_method = PaymentMethod.objects.get(pk=int(p_m))
         card_number = self.request.REQUEST.get('card_number') or None
         card_holder = self.request.REQUEST.get('card_holder') or None
         card_valid = self.request.REQUEST.get('card_valid') or None
         card_cvv2 = self.request.REQUEST.get('card_cvv2') or None
         if payment_method.use_card:
             if card_number and card_holder and card_valid and card_cvv2:
                 if not is_luhn_valid(card_number):
                     payload = {'success': False, 'engine_error':_('Card number is wrong.')}
                     return AjaxLazyAnswer(payload)
                 else:
                     use_card = True
                     try:
                         if len(card_cvv2) <> 3:
                             raise ValueError
                         if len(card_valid) <> 5:
                             raise ValueError
                         card_cvv2 = int(card_cvv2)
                     except ValueError:
                         payload = {'success': False, 'engine_error':_('Card CVV2 is wrong.')}
                         return AjaxLazyAnswer(payload)
             else:
                 payload = {'success': False, 'engine_error':_('You enter not all data of card.')}
                 return AjaxLazyAnswer(payload)
     else:
         payload = {'success': False, 'engine_error':_('You are not select payment method.')}
         return AjaxLazyAnswer(payload)
     self.object = form.save(commit=False)
     if self.request.user.is_authenticated():
         self.object.user = self.request.user
     room = Room.objects.get(id=form.cleaned_data.get('room_id'))
     settlement = SettlementVariant.objects.get(room=room,
         settlement=form.cleaned_data.get('settlement'))
     self.object.settlement = settlement
     self.object.hotel = settlement.room.hotel
     self.object.status = STATUS_ACCEPTED
     self.object.date = datetime.now()
     from_date = self.object.from_date
     to_date = self.object.to_date
     all_amount = Decimal(0)
     commission = Decimal(0)
     on_date = from_date
     while on_date < to_date:
         price = PlacePrice.objects.get(settlement=settlement, date = on_date)
         percent = self.object.hotel.get_percent_on_date(on_date)
         commission += (price.amount*percent)/100
         all_amount += price.amount
         avail = Availability.objects.get(room=room, date = on_date)
         avail.placecount -= 1
         avail.save()
         on_date = on_date+timedelta(days=1)
     self.object.amount = all_amount
     self.object.hotel_sum = all_amount - commission
     self.object.commission = commission
     currency = Currency.objects.get(code=CURRENCY)
     self.object.currency = currency
     self.object.ip = self.request.META['REMOTE_ADDR']
     self.object.user_agent = self.request.META['HTTP_USER_AGENT']
     if use_card:
         self.object.card_number = card_number
         self.object.card_holder = card_holder
         self.object.card_valid = card_valid
         self.object.card_cvv2 = card_cvv2
     self.object.save()
     self.success_url = self.object.get_client_url()
     if self.request.user.is_authenticated:
         booking_new_client_mail(self.object, self.request.user.username)
     else:
         booking_new_client_mail(self.object)
     booking_new_hotel_mail(self.object)
     return super(ClientAddBooking, self).form_valid(form)