class IPauseTableRow(model.Schema):
    def get_options():  # noqa
        """ Return the options for the day widget
        """
        options = [
            SimpleTerm(value=None, token=None, title=_("Select a day")),
            SimpleTerm(value=0, token=0, title=_("Monday")),
            SimpleTerm(value=1, token=1, title=_("Tuesday")),
            SimpleTerm(value=2, token=2, title=_("Wednesday")),
            SimpleTerm(value=3, token=3, title=_("Thursday")),
            SimpleTerm(value=4, token=4, title=_("Friday")),
            SimpleTerm(value=5, token=5, title=_("Saturday")),
            SimpleTerm(value=6, token=6, title=_("Sunday")),
        ]
        return SimpleVocabulary(options)

    day = schema.Choice(
        title=_("day_label", default="Day of week"),
        required=True,
        source=get_options(),
    )
    pause_start = schema.Choice(
        title=_("pause_start_label", default="Pause start"),
        vocabulary="redturtle.prenotazioni.VocOreInizio",
        required=False,
    )
    pause_end = schema.Choice(
        title=_("pause_end_label", default="Pause end"),
        vocabulary="redturtle.prenotazioni.VocOreInizio",
        required=False,
    )
class IWeekTableRow(model.Schema):

    day = schema.TextLine(title=_("day_label", default="Day of week"),
                          required=True,
                          default="")
    morning_start = schema.Choice(
        title=_("morning_start_label", default="Start time in the morning"),
        vocabulary="redturtle.prenotazioni.VocOreInizio",
        required=False,
    )
    morning_end = schema.Choice(
        title=_("morning_end_label", default="End time in the morning"),
        vocabulary="redturtle.prenotazioni.VocOreInizio",
        required=False,
    )

    afternoon_start = schema.Choice(
        title=_("afternoon_start_label",
                default="Start time in the afternoon"),
        vocabulary="redturtle.prenotazioni.VocOreInizio",
        required=False,
    )

    afternoon_end = schema.Choice(
        title=_("afternoon_end_label", default="End time in the afternoon"),
        vocabulary="redturtle.prenotazioni.VocOreInizio",
        required=False,
    )
    def delete_reservation(self):
        self.reservation_deleted = False
        prenotazione = self.prenotazione
        if not prenotazione:
            self.say_status(
                _("You can't delete your reservation; please contact"
                  " the office"),
                "error",
            )
            return
        adapter = IDeleteTokenProvider(prenotazione)
        is_valid_token = adapter.is_valid_token(self.delete_token)
        if is_valid_token == "invalid":
            self.say_status(
                _("You can't delete your reservation; please contact"
                  " the office"),
                "error",
            )
        elif is_valid_token == "expired":
            self.say_status(
                _("You can't delete your reservation; it's too late"), "error")

        else:
            with api.env.adopt_roles(["Manager", "Member"]):
                # api.content.delete(obj=prenotazione)
                day_folder = prenotazione.aq_parent
                day_folder.manage_delObjects(prenotazione.id)
                self.reservation_deleted = True
                self.say_status(_("Your reservation has been deleted"), "info")
class IBookingTypeRow(Interface):
    name = schema.TextLine(title=_("Typology name"), required=True)
    duration = schema.Choice(
        title=_("Duration value"),
        required=True,
        vocabulary="redturtle.prenotazioni.VocDurataIncontro",
    )
class BookingUserPhoneSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The phone number of the user who made the reservation.")

    def safe_call(self):
        return getattr(self.context, "phone", "")
class BookingHRDateStartSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking human readable date")

    def safe_call(self):
        # we need something like martedì 8 settembre 2020 alle ore 11:15

        date = getattr(self.context, "data_prenotazione", "")
        if not date:
            return ""

        if not have_spell_date:
            return "SPELL_DATE_NOT_AVAILABLE"

        info = spell_date(self.context.data_prenotazione, self.context)
        day = "{day_name} {day_number} {month_name} {year} alle ore {hour}:{minute}".format(  # noqa
            day_name=info["wkday_name"],
            day_number=info["day"],
            month_name=info["month_name"],
            year=info["year"],
            hour=info["hour"],
            minute=info["minute2"],
        )
        return day
class GateSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The gate booked.")

    def safe_call(self):
        return getattr(self.context, "gate", "")
class BookingTypeSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking type.")

    def safe_call(self):
        return getattr(self.context, "tipologia_prenotazione", "")
class BookingUserEmailSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The email address of the user who made the reservation.")

    def safe_call(self):
        return getattr(self.context, "email", "")
class IVacationBooking(Interface):
    title = TextLine(
        title=_("label_title", u"Title"),
        description=_("description_title",
                      u"This text will appear in the calendar cells"),
        default=u"",
    )
    gate = Choice(
        title=_("label_gate", u"Gate"),
        description=_("description_gate",
                      u"The gate that will be unavailable"),
        default=u"",
        vocabulary="redturtle.prenotazioni.gates",
    )
    start_date = Date(
        title=_("label_start", u"Start date "),
        description=_(" format (YYYY-MM-DD)"),
        default=None,
    )
    start_time = TextLine(
        title=_("label_start_time", u"Start time"),
        description=_("invalid_time"),
        constraint=check_time,
        default=u"00:00",
    )
    end_time = TextLine(
        title=_("label_end_time", u"End time"),
        description=_("invalid_time"),
        constraint=check_time,
        default=u"23:59",
    )
class BookingOfficeContactFaxSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking office contact fax.")

    def safe_call(self):
        prenotazioni_folder = self.context.getPrenotazioniFolder()
        return getattr(prenotazioni_folder, "fax", "")
class BookingHowToGetToOfficeSubsitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(
        u"The information to reach the office where user book a" " reservation"
    )

    def safe_call(self):
        prenotazioni_folder = self.context.getPrenotazioniFolder()
        return getattr(prenotazioni_folder, "how_to_get_here", "")
class BookingUrlSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking print url.")

    def safe_call(self):
        return "{folder}/@@prenotazione_print?uid={uid}".format(
            folder=self.context.getPrenotazioniFolder().absolute_url(),
            uid=self.context.UID(),
        )
class BookingCodeSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking code.")

    def safe_call(self):
        code = self.context.getBookingCode()
        if not code:
            return ""
        return code
class BookingTimeEndSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking time end.")

    def safe_call(self):
        plone = self.context.restrictedTraverse("@@plone")
        date = getattr(self.context, "data_scadenza", "")
        if not date:
            return ""
        return plone.toLocalizedTime(date, time_only=True)
class MovedPrenotazioneEditForm(EditForm):
    """
    An edit form for the mail action
    """

    schema = IMovedPrenotazioneAction
    label = _(u"Edit moved booking Mail Action")
    description = _(
        u"A mail action that sends email notify when a booking is moved in "
        u"an other slot.")
    form_name = _(u"Configure element")
class BookingOfficeCompleteAddressSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(
        u"The complete address information of the office where"
        "user book a reservation"
    )

    def safe_call(self):
        prenotazioni_folder = self.context.getPrenotazioniFolder()
        return getattr(prenotazioni_folder, "complete_address", "")
class BookingDateSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booked date.")

    def safe_call(self):
        plone = self.context.restrictedTraverse("@@plone")
        date = getattr(self.context, "data_prenotazione", "")
        if not date:
            return ""
        return plone.toLocalizedTime(date)
class MovedPrenotazioneAddForm(ActionAddForm):
    """
    An add form for the mail action
    """

    schema = IMovedPrenotazioneAction
    label = _(u"Add moved booking Mail Action")
    description = _(
        u"A mail action that sends email notify when a booking is moved "
        u"in an other slot.")
    form_name = _(u"Configure element")
    Type = MovedPrenotazioneAction
    def get_options():
        """ Return the options for this widget
        """
        today = date.today().strftime("%Y/%m/%d")
        options = [
            SimpleTerm(value="yes", token="yes", title=_("Yes")),
            SimpleTerm(value="no", token="no", title=_("No")),
            SimpleTerm(value=today, token=today,
                       title=_("No, just for today")),
        ]

        return SimpleVocabulary(options)
class IMoveForm(Interface):

    """
    Interface for moving a prenotazione
    """

    booking_date = Datetime(
        title=_("label_booking_time", u"Booking time"), default=None
    )
    gate = TextLine(
        title=_("label_gate", u"Gate"), default=u"", required=False
    )
    def get_booked_prenotation_message(self, day, booking):
        """ Return prenotation slot
        """
        """ Return the foreseen booking time message
        """

        message = _(
            "booked_prenotation_message",
            default=
            u"${day}, ore ${booking_time}, prenotato da ${booked_by}, prenotazione: ${type_prenotation} durata: ${duration} minuti",
            mapping={
                "booking_time":
                booking.Date().strftime('%H:%M'),
                "day":
                "{} {}".format(
                    self.context.translate(self.get_day_msgid(day),
                                           domain="plonelocales"),
                    day.strftime('%d')),
                "booked_by":
                booking.Title(),
                "duration": (booking.getDuration().seconds // 60) % 60,
                "type_prenotation":
                booking.getTipologia_prenotazione()
            },
        )
        return message
    def do_book(self, data):
        """
        Execute the multiple booking
        """
        booker = IBooker(self.context.aq_inner)
        slots = self.get_slots(data)
        start_date = DateTime(data["start_date"].strftime("%Y/%m/%d"))
        for slot in slots:
            booking_date = start_date + (float(slot.lower_value) / 86400)
            slot.__class__ = BaseSlot
            duration = float(len(slot)) / 86400
            # duration = float(len(slot)) / 60
            slot_data = {
                "fullname": data["title"],
                "subject": u"",
                "agency": u"",
                "booking_date": booking_date,
                "phone": u"",
                "email": u"",
                "tipologia_prenotazione": u"",
            }
            booker.create(slot_data,
                          duration=duration,
                          force_gate=data.get("gate"))

        msg = _("booking_created")
        IStatusMessage(self.request).add(msg, "info")
class BookingPrintUrlWithDeleteTokenSubstitution(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking print url with delete token.")

    def safe_call(self):
        annotations = IAnnotations(self.context)
        token = annotations.get(DELETE_TOKEN_KEY, None)
        if not token:
            return ""
        return "{folder}/@@prenotazione_print?uid={uid}&{delete_token_key}={token}".format(  # noqa
            folder=self.context.getPrenotazioniFolder().absolute_url(),
            uid=self.context.UID(),
            delete_token_key=DELETE_TOKEN_KEY,
            token=token,
        )
Exemple #25
0
class PrenotazionePrint(BrowserView):

    """
    This is a view to proxy autorizzazione
    """

    print_action = "javascript:this.print();"

    description = _(
        "confirm_booking_waiting_message",
        u"Your booking has to be confirmed by the administrators",
    )

    @property
    @memoize
    def label(self):
        """ The lable of this view
        """
        title = self.prenotazione.getPrenotazioniFolder().Title()  # noqa
        return _(
            "reservation_request",
            u"Booking request for: ${name}",
            mapping={"name": title},
        )

    @property
    @memoize
    def prenotazione(self):
        """
        Get's the prenotazione by uid
        """
        uid = self.request.get("uid")
        if not uid:
            return
        pc = getToolByName(self.context, "portal_catalog")
        query = {"portal_type": "Prenotazione", "UID": uid}
        brains = pc.unrestrictedSearchResults(query)
        if len(brains) != 1:
            return None

        return brains[0]._unrestrictedGetObject()

    def __call__(self):
        """
        Se non c'e' la prenotazione vai all'oggetto padre
        """
        if not self.prenotazione:
            qs = {}
            data = self.request.get("data")
            if data:
                qs["data"] = data
            msg = "Not found"
            IStatusMessage(self.request).add(msg, "warning")
            target = urlify(self.context.absolute_url(), params=qs)
            return self.request.response.redirect(target)
        else:
            return super(PrenotazionePrint, self).__call__()

    def protect_url(self, url):
        return addTokenToUrl(url)
    def set_search_string(self, data):
        result = []
        MARKUP = "<strong>{}:</strong> {}"
        if "text" in data and data.get("text", None):
            result.append(
                MARKUP.format(
                    self.context.translate(_("label_text", u"Text to search")),
                    data["text"],
                ))
        if "review_state" in data and data.get("review_state", None):
            result.append(
                MARKUP.format(
                    self.context.translate(__("State"), ),
                    self.context.translate(__(data["review_state"])),
                ))

        if "gate" in data and data.get("gate", None):
            result.append(
                MARKUP.format(
                    self.context.translate(_("label_gate", u"Gate"), ),
                    data["gate"],
                ))

        if "start" in data and data.get("start", None):
            if isinstance(data.get("start"), str):
                data["start"] = datetime.strptime(data.get("start"),
                                                  "%Y-%m-%d")
            result.append(
                MARKUP.format(
                    self.context.translate(_("label_start", u"Start date ")),
                    data["start"].strftime("%d/%m/%Y"),
                ))

        if "end" in data and data.get("end", None):
            if isinstance(data.get("end"), str):
                data["end"] = datetime.strptime(data.get("end"), "%Y-%m-%d")
            result.append(
                MARKUP.format(
                    self.context.translate(_("label_end", u"End date")),
                    data["end"].strftime("%d/%m/%Y"),
                ))
        search_string = ""
        if result:
            search_string = "; ".join(result)
            search_string = "<p>{}</p>".format(search_string)
        return search_string
 def no_reservation_label(self):
     """ The lable of this view when no reservation is found
     """
     title = self.context.Title()  # noqa
     return _(
         "no_reservation",
         u"Seems your reservation is not existing",
     )
class BookingUrlWithDeleteToken(BaseSubstitution):

    category = _(u"Booking")
    description = _(u"The booking url with delete token")

    def safe_call(self):
        annotations = IAnnotations(self.context)
        token = annotations.get(DELETE_TOKEN_KEY, None)
        if not token:
            return ""

        return "{booking_url}/@@delete_reservation?uid={uid}&{delete_token_key}={token}".format(
            booking_url=self.context.getPrenotazioniFolder().absolute_url(),
            delete_token_key=DELETE_TOKEN_KEY,
            uid=self.context.UID(),
            token=token,
        )
 def deleted_label(self):
     """ The lable of this view when reservation is deleted
     """
     title = self.context.Title()  # noqa
     return _(
         "deleted_reservation",
         u"Your reservation has been deleted",
     )
 def label(self):
     """ The lable of this view
     """
     title = self.context.Title()  # noqa
     return _(
         "delete_reservation_request",
         u"Delete reservation request for: ${name}",
         mapping={"name": title},
     )