예제 #1
0
    def set_state(self, new_state, user):
        # Make sure it is a known state
        assert new_state in (Reservation.REQUESTED, Reservation.CONFIRMED,
                             Reservation.DENIED, Reservation.CANCELLED,
                             Reservation.WAITING_FOR_PAYMENT)

        old_state = self.state
        if new_state == old_state:
            if old_state == Reservation.CONFIRMED:
                reservation_modified.send(sender=self.__class__,
                                          instance=self,
                                          user=user)
            return

        if new_state == Reservation.CONFIRMED:
            self.approver = user
            reservation_confirmed.send(sender=self.__class__,
                                       instance=self,
                                       user=user)
        elif old_state == Reservation.CONFIRMED:
            self.approver = None

        user_is_staff = self.user is not None and self.user.is_staff

        # Notifications
        if new_state == Reservation.REQUESTED:
            self.send_reservation_requested_mail()
            self.send_reservation_requested_mail_to_officials()
        elif new_state == Reservation.CONFIRMED:
            if self.need_manual_confirmation():
                self.send_reservation_confirmed_mail()
            elif self.access_code:
                self.send_reservation_created_with_access_code_mail()
            else:
                if not user_is_staff:
                    # notifications are not sent from staff created reservations to avoid spam
                    self.send_reservation_created_mail()
        elif new_state == Reservation.DENIED:
            self.send_reservation_denied_mail()
        elif new_state == Reservation.CANCELLED:
            order = self.get_order()
            if order:
                if order.state == order.CANCELLED:
                    self.send_reservation_cancelled_mail()
            else:
                if user != self.user:
                    self.send_reservation_cancelled_mail()
            reservation_cancelled.send(sender=self.__class__,
                                       instance=self,
                                       user=user)

        self.state = new_state

        self.save()
예제 #2
0
    def set_state(self, new_state, user):
        # Make sure it is a known state
        assert new_state in (
            Reservation.REQUESTED, Reservation.CONFIRMED, Reservation.DENIED,
            Reservation.CANCELLED
        )

        old_state = self.state
        if new_state == old_state:
            if old_state == Reservation.CONFIRMED:
                reservation_modified.send(sender=self.__class__, instance=self,
                                          user=user)
            return

        if new_state == Reservation.CONFIRMED:
            self.approver = user
            reservation_confirmed.send(sender=self.__class__, instance=self,
                                       user=user)
        elif old_state == Reservation.CONFIRMED:
            self.approver = None

        user_is_staff = self.user is not None and self.user.is_staff

        # Notifications
        if new_state == Reservation.REQUESTED:
            self.send_reservation_requested_mail()
            self.send_reservation_requested_mail_to_officials()
        elif new_state == Reservation.CONFIRMED:
            if self.need_manual_confirmation():
                self.send_reservation_confirmed_mail()
            elif self.access_code:
                self.send_reservation_created_with_access_code_mail()
            else:
                if not user_is_staff:
                    # notifications are not sent from staff created reservations to avoid spam
                    self.send_reservation_created_mail()
        elif new_state == Reservation.DENIED:
            self.send_reservation_denied_mail()
        elif new_state == Reservation.CANCELLED:
            if user != self.user:
                self.send_reservation_cancelled_mail()
            reservation_cancelled.send(sender=self.__class__, instance=self,
                                       user=user)

        self.state = new_state
        self.save()
예제 #3
0
    def set_state(self, new_state, user):
        # Make sure it is a known state
        assert new_state in (Reservation.REQUESTED, Reservation.CONFIRMED,
                             Reservation.DENIED, Reservation.CANCELLED)

        old_state = self.state
        if new_state == old_state:
            if old_state == Reservation.CONFIRMED:
                reservation_modified.send(sender=self.__class__,
                                          instance=self,
                                          user=user)
            return

        if new_state == Reservation.CONFIRMED:
            self.approver = user
            reservation_confirmed.send(sender=self.__class__,
                                       instance=self,
                                       user=user)
        elif old_state == Reservation.CONFIRMED:
            self.approver = None

        # Notifications
        if new_state == Reservation.REQUESTED:
            self.send_reservation_requested_mail()
            self.send_reservation_requested_mail_to_officials()
        elif new_state == Reservation.CONFIRMED:
            if self.need_manual_confirmation():
                self.send_reservation_confirmed_mail()
            elif self.resource.is_access_code_enabled():
                self.send_reservation_created_with_access_code_mail()
            else:
                self.send_reservation_created_mail()
        elif new_state == Reservation.DENIED:
            self.send_reservation_denied_mail()
        elif new_state == Reservation.CANCELLED:
            if user != self.user:
                self.send_reservation_cancelled_mail()
            reservation_cancelled.send(sender=self.__class__,
                                       instance=self,
                                       user=user)

        self.state = new_state
        self.save()
예제 #4
0
    def send_messages(self, new_state, user):
        # Notifications
        # Someone needs to rewrite this spaghetti monster

        if new_state == Reservation.REQUESTED:
            self.send_reservation_requested_mail()
            # self.send_reservation_requested_mail_to_officials()
        elif new_state == Reservation.CONFIRMED:
            # If a payment is required, await for purchase to complete before sending confirmation mail
            if self.resource.ceepos_payment_required and self.resource.product_code and not self.purchase and self.resource.need_manual_confirmation and not self.staff_event:
                if self.manual_price != '':
                    p = Purchase.objects.create(purchase_code = self.resource.product_code,\
                                             price_vat = float(self.manual_price))
                else:
                    p = Purchase.objects.create(purchase_code = self.resource.product_code, \
                                            price_vat = float(self.resource.min_price_per_hour) * (self.end - self.begin).total_seconds() / 3600)
                p.request_payment()
                self.set_purchase(p)
                self.send_payment_email()
                return
            elif self.resource.ceepos_payment_required and not self.resource.need_manual_confirmation:
                return
            elif not self.need_manual_confirmation():
                self.send_reservation_confirmed_mail()

            if self.need_manual_confirmation():
                self.send_reservation_confirmed_mail()
            elif self.resource.is_access_code_enabled():
                self.send_reservation_created_with_access_code_mail()
        elif new_state == Reservation.DENIED:
            self.send_reservation_denied_mail()
        elif new_state == Reservation.CANCELLED:
            if user != self.user:
                self.send_reservation_cancelled_mail()
            reservation_cancelled.send(sender=self.__class__,
                                       instance=self,
                                       user=user)
예제 #5
0
파일: reservation.py 프로젝트: pnuz3n/respa
    def set_state(self, new_state, user):
        # Make sure it is a known state
        assert new_state in (Reservation.REQUESTED, Reservation.CONFIRMED,
                             Reservation.DENIED, Reservation.CANCELLED,
                             Reservation.WAITING_FOR_PAYMENT)
        old_state = self.state
        if new_state == old_state:
            if old_state == Reservation.CONFIRMED:
                reservation_modified.send(sender=self.__class__,
                                          instance=self,
                                          user=user)
            return
        if new_state == Reservation.CONFIRMED:
            self.approver = user if user and user.is_authenticated else None
            if user and user.is_authenticated or self.resource.authentication == 'unauthenticated':
                reservation_confirmed.send(sender=self.__class__,
                                           instance=self,
                                           user=user)
        elif old_state == Reservation.CONFIRMED:
            self.approver = None

        user_is_staff = self.user is not None and self.user.is_staff

        # Notifications
        if new_state == Reservation.REQUESTED:
            if not user_is_staff:
                self.send_reservation_requested_mail()
                self.notify_staff_about_reservation(
                    NotificationType.RESERVATION_REQUESTED_OFFICIAL)
            else:
                if self.reserver_email_address != self.user.email:
                    self.send_reservation_requested_mail(
                        action_by_official=True)
        elif new_state == Reservation.CONFIRMED:
            if self.need_manual_confirmation():
                self.send_reservation_confirmed_mail()
            elif self.access_code:
                if not user_is_staff:
                    self.send_reservation_created_with_access_code_mail()
                    self.notify_staff_about_reservation(
                        NotificationType.
                        RESERVATION_CREATED_WITH_ACCESS_CODE_OFFICIAL)
                else:
                    if self.reserver_email_address != self.user.email:
                        self.send_reservation_created_with_access_code_mail(
                            action_by_official=True)
            else:
                if not user_is_staff:
                    self.send_reservation_created_mail()
                    self.notify_staff_about_reservation(
                        NotificationType.RESERVATION_CREATED_OFFICIAL)
                else:
                    if self.reserver_email_address != self.user.email:
                        self.send_reservation_created_mail(
                            action_by_official=True)
                        self.notify_staff_about_reservation(
                            NotificationType.RESERVATION_CREATED_OFFICIAL)
        elif new_state == Reservation.DENIED:
            self.send_reservation_denied_mail()
        elif new_state == Reservation.CANCELLED:
            if self.user:
                order = self.get_order()
                if order:
                    if order.state == order.CANCELLED:
                        self.send_reservation_cancelled_mail()
                else:
                    if user.is_staff and (user.email != self.user.email
                                          ):  # Assume staff cancelled it
                        self.send_reservation_cancelled_mail(
                            action_by_official=True)
                    else:
                        self.send_reservation_cancelled_mail()
                        self.notify_staff_about_reservation(
                            NotificationType.RESERVATION_CANCELLED_OFFICIAL)
            reservation_cancelled.send(sender=self.__class__,
                                       instance=self,
                                       user=user)
        self.state = new_state
        self.save()