Example #1
0
 def move_to_slot_links(self, day, slot, gate):
     '''
     Returns the url to move the booking in this slot
     '''
     if not self.prenotazioni_view.is_valid_day(day):
         return []
     if self.prenotazioni_view.maximum_bookable_date:
         if day > self.prenotazioni_view.maximum_bookable_date.date():
             return []
     date = day.strftime("%Y-%m-%d")
     params = {
         'form.actions.move': 1,
         'data': self.request.form.get('data', ''),
         'form.gate': gate
     }
     times = slot.get_values_hr_every(300)
     urls = []
     base_url = "/".join((self.context.absolute_url(), 'prenotazione_move'))
     now_str = tznow().strftime("%Y-%m-%d %H:%M")
     for t in times:
         form_booking_date = " ".join((date, t))
         params['form.booking_date'] = form_booking_date
         urls.append({
             'title': t,
             'url': urlify(base_url, params=params),
             'class': t.endswith(':00') and 'oclock' or None,
             'future': (now_str <= form_booking_date),
         })
     return urls
Example #2
0
    def action_move(self, action):
        '''
        Book this resource
        '''
        data, errors = self.extractData()

        data['tipology'] = self.context.getTipologia_prenotazione()
        conflict_manager = self.prenotazioni_view.conflict_manager
        current_data = self.context.getData_prenotazione()
        current = {'booking_date': current_data, 'tipology': data['tipology']}
        current_slot = conflict_manager.get_choosen_slot(current)
        current_gate = self.context.getGate()
        exclude = {current_gate: [current_slot]}

        if conflict_manager.conflicts(data, exclude=exclude):
            msg = _(u'Sorry, this slot is not available or does not fit your '
                    u'booking.')
            api.portal.show_message(msg, self.request, type="error")
            raise ActionExecutionError(Invalid(msg))
        if self.exceedes_date_limit(data):
            msg = _(u'Sorry, you can not book this slot for now.')
            api.portal.show_message(msg, self.request, type="error")
            raise ActionExecutionError(Invalid(msg))

        obj = self.do_move(data)
        obj  # pyflakes
        msg = _('booking_moved')
        IStatusMessage(self.request).add(msg, 'info')
        booking_date = data['booking_date'].strftime('%d/%m/%Y')
        target = urlify(self.prenotazioni_folder.absolute_url(),
                        paths=['prenotazioni_week_view'],
                        params={'data': booking_date})
        return self.request.response.redirect(target)
Example #3
0
    def action_book(self, action):
        '''
        Book this resource
        '''
        data, errors = self.extractData()
        parsed_data = self.get_parsed_data(data)

        start_date = data['start_date']
        if self.has_slot_conflicts(parsed_data):
            msg = _('slot_conflict_error',
                    u'This gate has some booking schedule in this time '
                    u'period.')
            raise ActionExecutionError(
                Invalid(msg)
            )

        elif not self.prenotazioni.is_valid_day(start_date):
            msg = _('day_error',
                    u'This day is not valid.')
            raise ActionExecutionError(
                Invalid(msg)
            )

        self.do_book(parsed_data)
        qs = {'data': data['start_date'].strftime('%d/%m/%Y')}
        target = urlify(self.context.absolute_url(), params=qs)
        return self.request.response.redirect(target)
Example #4
0
 def back_to_booking_url(self):
     ''' This goes back to booking view.
     '''
     qs = {
         'data': (self.context.getData_prenotazione().strftime('%d/%m/%Y'))
     }
     return urlify(self.prenotazioni_folder.absolute_url(), params=qs)
Example #5
0
 def get_booking_urls(self, day, slot, slot_min_size=0):
     ''' Returns, if possible, the booking urls
     '''
     # we have some conditions to check
     if not self.is_valid_day(day):
         return []
     if self.maximum_bookable_date:
         if day > self.maximum_bookable_date.date():
             return []
     date = day.strftime("%Y-%m-%d")
     params = self.remembered_params.copy()
     times = slot.get_values_hr_every(300, slot_min_size=slot_min_size)
     base_url = self.base_booking_url
     urls = []
     now_str = tznow().strftime("%Y-%m-%d %H:%M")
     for t in times:
         form_booking_date = " ".join((date, t))
         params['form.booking_date'] = form_booking_date
         booking_date = DateTime(
             params['form.booking_date']).asdatetime()  # noqa
         urls.append({
             'title': t,
             'url': urlify(base_url, params=params),
             'class': t.endswith(':00') and 'oclock' or None,
             'booking_date': booking_date,
             'future': (now_str <= form_booking_date),
         })
     return urls
 def move_to_slot_links(self, day, slot, gate):
     '''
     Returns the url to move the booking in this slot
     '''
     if not self.prenotazioni_view.is_valid_day(day):
         return []
     if self.prenotazioni_view.maximum_bookable_date:
         if day > self.prenotazioni_view.maximum_bookable_date.date():
             return []
     date = day.strftime("%Y-%m-%d")
     params = {'form.buttons.action_move': 'Move',
               'data': self.request.form.get('data', ''),
               'form.widgets.gate': gate}
     times = slot.get_values_hr_every(300)
     urls = []
     base_url = "/".join((self.context.absolute_url(),
                          'prenotazione_move'))
     now_str = tznow().strftime("%Y-%m-%d %H:%M")
     for t in times:
         form_booking_date = " ".join((date, t))
         params['form.widgets.booking_date'] = form_booking_date
         urls.append(
             {
                 'title': t,
                 'url': addTokenToUrl(urlify(base_url, params=params)),
                 'class': t.endswith(':00') and 'oclock' or None,
                 'future': (now_str <= form_booking_date),
             }
         )
     return urls
 def get_booking_urls(self, day, slot, slot_min_size=0):
     """ Returns, if possible, the booking urls
     """
     # we have some conditions to check
     if not self.is_valid_day(day):
         return []
     if self.maximum_bookable_date:
         if day > self.maximum_bookable_date.date():
             return []
     date = day.strftime("%Y-%m-%d")
     params = self.remembered_params.copy()
     times = slot.get_values_hr_every(300, slot_min_size=slot_min_size)
     base_url = self.base_booking_url
     urls = []
     now_str = tznow().strftime("%Y-%m-%d %H:%M")
     for t in times:
         form_booking_date = " ".join((date, t))
         params['form.booking_date'] = form_booking_date
         booking_date = DateTime(params['form.booking_date']).asdatetime()  # noqa
         urls.append(
             {
                 'title': t,
                 'url': urlify(base_url, params=params),
                 'class': t.endswith(':00') and 'oclock' or None,
                 'booking_date': booking_date,
                 'future': (now_str <= form_booking_date),
             }
         )
     return urls
 def move_url(self):
     ''' move this booking visiting this url
     '''
     booking_date = self.booking_date
     target = '/'.join((self.context.absolute_url(), 'prenotazione_move'))
     if booking_date:
         qs = {'data': booking_date.strftime('%d/%m/%Y')}
         target = urlify(target, params=qs)
     return target
 def move_url(self):
     ''' move this booking visiting this url
     '''
     booking_date = self.booking_date
     target = '/'.join((self.context.absolute_url(), 'prenotazione_move'))
     if booking_date:
         qs = {'data': booking_date.strftime('%d/%m/%Y')}
         target = urlify(target, params=qs)
     return target
 def back_url(self):
     ''' Go back parent prenotazioni folder in the right day
     '''
     booking_date = self.booking_date
     target = self.prenotazioni_folder.absolute_url()
     if booking_date:
         qs = {'data': booking_date.strftime('%d/%m/%Y')}
         target = urlify(target, params=qs)
     return target
 def back_to_booking_url(self):
     ''' This goes back to booking view.
     '''
     params = self.prenotazioni.remembered_params.copy()
     b_date = self.booking_DateTime
     if b_date:
         params['data'] = b_date.strftime('%d/%m/%Y')
     target = urlify(self.context.absolute_url(), params=params)
     return target
Example #12
0
 def action_book(self, action, data):
     '''
     Book this resource
     '''
     parsed_data = self.get_parsed_data(data)
     self.do_book(parsed_data)
     qs = {'data': data['start_date'].strftime('%d/%m/%Y')}
     target = urlify(self.context.absolute_url(), params=qs)
     return self.request.response.redirect(target)
 def back_url(self):
     ''' Go back parent prenotazioni folder in the right day
     '''
     booking_date = self.booking_date
     target = self.prenotazioni_folder.absolute_url()
     if booking_date:
         qs = {'data': booking_date.strftime('%d/%m/%Y')}
         target = urlify(target, params=qs)
     return target
Example #14
0
    def action_book(self, action):
        '''
        Book this resource
        '''
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        if not data.get('booking_date'):
            raise WidgetActionExecutionError(
                'booking_date',
                Invalid(_(u"Please provide a booking date"))
            )

        conflict_manager = self.prenotazioni.conflict_manager
        if conflict_manager.conflicts(data):
            msg = _(u'Sorry, this slot is not available anymore.')
            raise WidgetActionExecutionError(
                'booking_date',
                Invalid(msg)
            )
        if self.exceedes_date_limit(data):
            msg = _(u'Sorry, you can not book this slot for now.')
            raise WidgetActionExecutionError(
                'booking_date',
                Invalid(msg)
            )

        captcha = getMultiAdapter(
            (aq_inner(self.context), self.request),
            name='recaptcha'
        )

        if 'captcha' in data and not captcha.verify():
            msg=_(u"Please check the captcha")
            raise ActionExecutionError(Invalid(msg))

        obj = self.do_book(data)
        if not obj:
            msg = _(u'Sorry, this slot is not available anymore.')
            api.portal.show_message(
                message=msg,
                type='warning',
                request=self.request)
            target = self.back_to_booking_url
            return self.request.response.redirect(target)
        msg = _('booking_created')
        api.portal.show_message(message=msg, type='info', request=self.request)
        booking_date = data['booking_date'].strftime('%d/%m/%Y')
        params = {'data': booking_date,
                  'uid': obj.UID()}
        target = urlify(self.context.absolute_url(),
                        paths=["@@prenotazione_print"],
                        params=params)
        return self.request.response.redirect(target)
 def csv_url(self):
     ''' The CSV url to get those data
     '''
     params = {
         'form.actions.csv': 1,
         'form.start': self.request.form['form.start'],
         'form.end': self.request.form['form.end'],
         'form.user': self.request.form['form.user'],
     }
     return urlify(self.context.absolute_url(), [self.__name__], params)
Example #16
0
 def action_move(self, action, data):
     '''
     Book this resource
     '''
     obj = self.do_move(data)
     obj  # pyflakes
     msg = _('booking_moved')
     IStatusMessage(self.request).add(msg, 'info')
     booking_date = data['booking_date'].strftime('%d/%m/%Y')
     target = urlify(self.prenotazioni_folder.absolute_url(),
                     paths=['prenotazioni_week_view'],
                     params={'data': booking_date})
     return self.request.response.redirect(target)
 def action_book(self, action, data):
     '''
     Book this resource
     '''
     obj = self.do_book(data)
     msg = _('booking_created')
     IStatusMessage(self.request).add(msg, 'info')
     booking_date = data['booking_date'].strftime('%d/%m/%Y')
     params = {'data': booking_date, 'uid': obj.UID()}
     target = urlify(self.context.absolute_url(),
                     paths=["@@prenotazione_print"],
                     params=params)
     return self.request.response.redirect(target)
Example #18
0
 def toggle_columns_url(self):
     """ The link to enable/disable the columns
     """
     params = self.prenotazioni.remembered_params.copy()
     if ('disable_plone.leftcolumn' in params or 'disable_plone.rightcolumn' in params):  # noqa
         params.pop('disable_plone.leftcolumn', '')
         params.pop('disable_plone.rightcolumn', '')
     else:
         params['disable_plone.leftcolumn'] = 1
         params['disable_plone.rightcolumn'] = 1
     data = self.request.form.get('data', '')
     if data:
         params['data'] = data
     return urlify(self.request.getURL(), params=params)
Example #19
0
 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 backurl(self):
        ''' We need an URL to redirect to

        This URL is passed as form.backurl
        if no form.backurl is given use http://example.com
        '''
        form = {}
        for key in self.request.form.copy():
            if not key in self.banned_redirect_keys:
                value = self.request.form[key]
                if isinstance(value, unicode):
                    value = value.encode('utf8')
                form[key] = value
        backurl = self.request.form.get('form.backurl', 'http://example.com/')
        return urlify(backurl, params=form)
 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 get_confirm_url(self, data):
        ''' The URL that send to the confirm form
        '''
        request_form = self.request.form
        params = {}
        for key in request_form.keys():
            if (
                key.startswith('form.')
                and (not key.startswith('form.actions.'))
            ):
                value = request_form[key]
                if isinstance(value, unicode):
                    value = value.encode('utf8')
                params[key] = value
        params["form.checksum"] = self.get_data_checksum(data)

        return urlify(
            self.context.absolute_url(),
            '@@prenotazione_confirm',
            params=params
        )
Example #23
0
    def get_search_gate_url(self, gate, day):
        ''' Search a a gate
        '''
        params = {
            'start': day,
            'end': day,
            'actions.search': 1
        }
        vr = getVocabularyRegistry()
        voc = vr.get(self.context, 'rg.prenotazioni.gates')

        try:
            params['gate'] = voc.getTerm(gate).token
        except LookupError:
            params['text'] = gate

        return urlify(
            self.context.absolute_url(),
            '@@prenotazioni_search',
            params=params
        )
    def action_move(self, action):
        '''
        Book this resource
        '''
        data, errors = self.extractData()

        data['tipology'] = self.context.getTipologia_prenotazione()
        conflict_manager = self.prenotazioni_view.conflict_manager
        current_data = self.context.getData_prenotazione()
        current = {'booking_date': current_data,
                   'tipology': data['tipology']}
        current_slot = conflict_manager.get_choosen_slot(current)
        current_gate = self.context.getGate()
        exclude = {current_gate: [current_slot]}

        if conflict_manager.conflicts(data, exclude=exclude):
            msg = _(u'Sorry, this slot is not available or does not fit your '
                    u'booking.')
            api.portal.show_message(msg, self.request, type="error")
            raise ActionExecutionError(
                Invalid(msg)
            )
        if self.exceedes_date_limit(data):
            msg = _(u'Sorry, you can not book this slot for now.')
            api.portal.show_message(msg, self.request, type="error")
            raise ActionExecutionError(
                Invalid(msg)
            )

        obj = self.do_move(data)
        obj  # pyflakes
        msg = _('booking_moved')
        IStatusMessage(self.request).add(msg, 'info')
        booking_date = data['booking_date'].strftime('%d/%m/%Y')
        target = urlify(self.prenotazioni_folder.absolute_url(),
                        paths=['prenotazioni_week_view'],
                        params={'data': booking_date})
        return self.request.response.redirect(target)
    def action_book(self, action):
        '''
        Book this resource
        '''
        data, errors = self.extractData()
        parsed_data = self.get_parsed_data(data)

        start_date = data['start_date']
        if self.has_slot_conflicts(parsed_data):
            msg = _(
                'slot_conflict_error',
                u'This gate has some booking schedule in this time '
                u'period.')
            raise ActionExecutionError(Invalid(msg))

        elif not self.prenotazioni.is_valid_day(start_date):
            msg = _('day_error', u'This day is not valid.')
            raise ActionExecutionError(Invalid(msg))

        self.do_book(parsed_data)
        qs = {'data': data['start_date'].strftime('%d/%m/%Y')}
        target = urlify(self.context.absolute_url(), params=qs)
        return self.request.response.redirect(target)
Example #26
0
 def next_week_url(self):
     """ The link to the next week
     """
     qs = {'data': self.next_week}
     qs.update(self.prenotazioni.remembered_params)
     return urlify(self.request.getURL(), params=qs)
 def back_to_booking_url(self):
     ''' This goes back to booking view.
     '''
     qs = {'data': (self.context.getData_prenotazione()
                    .strftime('%d/%m/%Y'))}
     return urlify(self.prenotazioni_folder.absolute_url(), params=qs)
Example #28
0
 def additional_parameters(self):
     ''' Get some additional parameteres
     '''
     params = self.request.form.copy()
     params.pop('booking_date', '')
     return urlify(params=params)