Ejemplo n.º 1
0
class BookingRequestForm(RequestForm):
    fields = field.Fields(IBookingRequestForm)
    fields['captcha'].widgetFactory = CaptchaFieldWidget
    ignoreContext = True
    email_view = 'booking-request-email'
    label = _(u"Request booking")  # noqa
    description = _(u'Form to make request booking')
Ejemplo n.º 2
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        if 'captcha' in data:
            captcha = CaptchaValidator(self.context, self.request, None,
                                       IRequestForm['captcha'], None)
            try:
                captcha.validate(data['captcha'])
            except WrongCaptchaCode:
                # import ipdb; ipdb.set_trace()
                message = _(u'Wrong captcha code')
                api.portal.show_message(message=message,
                                        request=self.request,
                                        type='error')
                return

            # else;

        # Do something with valid data here
        # data['site_title'] = api.portal.get_registry_record('plone.site_title')
        # Set status on this form page
        # (this status message is not bind to the session and does not go thru redirects)
        self.send_message(data)
        message = _(u'Your request has been send to the owner')
        self.status = message
        api.portal.show_message(message=message,
                                request=self.request,
                                type='info')
        self.request.response.redirect(self.context.absolute_url())
Ejemplo n.º 3
0
    def send_message(self, data):
        subject = _(u'Request booking')

        portal = api.portal.get()
        registry = getUtility(IRegistry)
        mail_settings = registry.forInterface(IMailSchema, prefix='plone')
        send_to_address = api.portal.get_registry_record(
            'collective.realestate.owner_email', )
        if not send_to_address:
            send_to_address = mail_settings.email_from_address
        from_address = send_to_address
        registry = getUtility(IRegistry)
        encoding = registry.get('plone.email_charset', 'utf-8')
        host = getToolByName(self.context, 'MailHost')

        data['url'] = portal.absolute_url()

        try:
            # This actually sends out the mail
            host.send(self.message(data, encoding),
                      send_to_address,
                      from_address,
                      subject=subject,
                      charset=encoding)
        except (SMTPException, RuntimeError), e:
            logger.error(e)
            plone_utils = getToolByName(portal, 'plone_utils')
            exception = plone_utils.exceptionString()
            message = _(u'Unable to send mail: ${exception}',
                        mapping={u'exception': exception})
            IStatusMessage(self.request).add(message, type=u'error')
Ejemplo n.º 4
0
 def __call__(self, context):
     # Fix context if you are using the vocabulary in DataGridField.
     # See https://github.com/collective/collective.z3cform.datagridfield/issues/31:  # NOQA: 501
     if not IDexterityContent.providedBy(context):
         req = getRequest()
         context = req.PARENTS[0]
     terms = []
     terms.append(SimpleTerm(value='sale', token='sale', title=_(u'Sale')))
     terms.append(SimpleTerm(value='rent', token='rent', title=_(u'Rent')))
     return SimpleVocabulary(terms)
Ejemplo n.º 5
0
class IBookingRequestForm(IRequestForm):
    """ Define form fields """

    start = schema.Date(
        title=_(u'Start of booking'),
        defaultFactory=start_default_value,
    )
    end = schema.Date(
        title=_(u'End of booking'),
        defaultFactory=end_default_value,
    )
Ejemplo n.º 6
0
class IBooking(model.Schema):
    """ Marker interface for Booking
    """
    title = schema.TextLine(
        title=_(u"Customer's name"),
        required=False,
    )

    start = schema.Date(title=_(u'Start of booking'), )

    end = schema.Date(title=_(u'End of booking'), )
Ejemplo n.º 7
0
class RealEstateSettingsEditForm(RegistryEditForm):
    """
    Define form logic
    """
    schema = IRealEstateSettings
    schema_prefix = 'collective.realestate'
    label = _(u'Real Estate settings')
Ejemplo n.º 8
0
class IRequestForm(model.Schema):
    name = schema.TextLine(title=_(u'Your name'))
    email = Email(
        title=_(u'Your e-mail'),
        required=True,
    )
    phone = schema.TextLine(
        title=_(u'Your phone number'),
        description=_(
            u'Your phone will be used only to take contact with you.'),  # noqa
        required=False,
    )
    text = schema.Text(
        title=_(u'Your questions or notices'),
        required=False,
    )
    captcha = schema.TextLine(title=_(u'Captcha'), required=False)
Ejemplo n.º 9
0
    def __call__(self, context):
        # Fix context if you are using the vocabulary in DataGridField.
        # See https://github.com/collective/collective.z3cform.datagridfield/issues/31:  # NOQA: 501
        if not IDexterityContent.providedBy(context):
            req = getRequest()
            context = req.PARENTS[0]

        terms = []
        types = {
            "appart": _(u"Apartment"),
            "house": _(u"House / Villa"),
            "garage": _(u"Garage"),
            "lots": _(u"Lots / Land"),
            "businesses": _(u"Businesses"),
            "new": _(u"New real estate"),
        }
        for id, item in types.items():
            terms.append(SimpleTerm(value=id, token=id, title=item))
        return SimpleVocabulary(terms)
Ejemplo n.º 10
0
class RequestForm(form.Form):
    """ Define Form handling

    This form can be accessed as
    http://yoursite/real-estate-id/@@booking-request

    """
    # schema = IBookingRequestForm
    fields = field.Fields(IRequestForm)
    fields['captcha'].widgetFactory = CaptchaFieldWidget
    ignoreContext = True
    email_view = 'request-email'

    label = _(u'Request')
    description = _(u'Form to make request')

    @button.buttonAndHandler(_(u'Send'))
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return

        if 'captcha' in data:
            captcha = CaptchaValidator(self.context, self.request, None,
                                       IRequestForm['captcha'], None)
            try:
                captcha.validate(data['captcha'])
            except WrongCaptchaCode:
                # import ipdb; ipdb.set_trace()
                message = _(u'Wrong captcha code')
                api.portal.show_message(message=message,
                                        request=self.request,
                                        type='error')
                return

            # else;

        # Do something with valid data here
        # data['site_title'] = api.portal.get_registry_record('plone.site_title')
        # Set status on this form page
        # (this status message is not bind to the session and does not go thru redirects)
        self.send_message(data)
        message = _(u'Your request has been send to the owner')
        self.status = message
        api.portal.show_message(message=message,
                                request=self.request,
                                type='info')
        self.request.response.redirect(self.context.absolute_url())

    @button.buttonAndHandler(_(u'Cancel'))
    def handleCancel(self, action):
        """User cancelled. Redirect back to the front page.
        """
        self.status = _(u'See you next time!')
        self.request.response.redirect(self.context.absolute_url())

    def generate_mail(self, variables, encoding='utf-8'):
        template = self.context.restrictedTraverse(self.email_view)
        variables['realestate_url'] = self.context.absolute_url()
        return template(self.context, **variables).encode(encoding)

    def message(self, data, encoding):
        message = self.generate_mail(data, encoding)
        message = MIMEText(message, 'html', encoding)
        message['Reply-To'] = data['email']
        return message

    def send_message(self, data):
        subject = _(u'Request booking')

        portal = api.portal.get()
        registry = getUtility(IRegistry)
        mail_settings = registry.forInterface(IMailSchema, prefix='plone')
        send_to_address = api.portal.get_registry_record(
            'collective.realestate.owner_email', )
        if not send_to_address:
            send_to_address = mail_settings.email_from_address
        from_address = send_to_address
        registry = getUtility(IRegistry)
        encoding = registry.get('plone.email_charset', 'utf-8')
        host = getToolByName(self.context, 'MailHost')

        data['url'] = portal.absolute_url()

        try:
            # This actually sends out the mail
            host.send(self.message(data, encoding),
                      send_to_address,
                      from_address,
                      subject=subject,
                      charset=encoding)
        except (SMTPException, RuntimeError), e:
            logger.error(e)
            plone_utils = getToolByName(portal, 'plone_utils')
            exception = plone_utils.exceptionString()
            message = _(u'Unable to send mail: ${exception}',
                        mapping={u'exception': exception})
            IStatusMessage(self.request).add(message, type=u'error')
Ejemplo n.º 11
0
 def handleCancel(self, action):
     """User cancelled. Redirect back to the front page.
     """
     self.status = _(u'See you next time!')
     self.request.response.redirect(self.context.absolute_url())
Ejemplo n.º 12
0
class IRealEstateSettings(Interface):
    """ Define settings data structure """

    owner_email = zchema.ASCIILine(
        title=_(u'Owner e-mail'),
        description=_(u'Default e-mail use to send request reservation.'))

    start_high = zchema.TextLine(
        title=_(u'High season starting'),
        description=_(u'Date like 01/07 for first July'),
        default=_(u'01/07'),
        required=False)

    start_low = zchema.TextLine(
        title=_(u'High season starting'),
        description=_(u'Date like 01/10 for first October'),
        default=_(u'01/10'),
        required=False)

    directives.widget(condition=WysiwygFieldWidget)
    condition = zchema.Text(
        title=_(u'General condition'),
        description=_(u'This text is added below all real estate.'),
        required=False)

    marker_icons = zchema.ASCIILine(title=_(u'Marker icons'),
                                    description=_(u'Update marker path.'),
                                    required=False)
    latitude = zchema.TextLine(title=_(u'Latitude'), required=False)
    longitude = zchema.TextLine(title=_(u'Longitude'), required=False)
Ejemplo n.º 13
0
class Widget(AbstractWidget):
    """ Widget
    """

    widget_type = "moreorless"
    widget_label = _("More or less field")

    groups = (DefaultSchemata, LayoutSchemata)
    index = ViewPageTemplateFile("widget.pt")

    # @property
    # def css_class(self):
    #     css = super(Widget, self).css_class
    #     css += ' col-xs-12 col-sm-6 col-lg-6 users'
    #     return css

    @property
    def default(self):
        """ Return default
        """
        default = self.data.get("default", "")
        if not default:
            return ""
        return default

    def query(self, form):
        """ Get value from form and return a catalog dict query
        """
        query = {}

        # import ipdb; ipdb.set_trace()
        index = self.data.get("index", "")
        moreorless = self.data.get("moreorless", "")
        index = index.encode("utf-8", "replace")
        value = None
        if not index:
            return query

        if self.hidden:
            value = self.default
        else:
            value = form.get(self.data.getId(), "")

        if not value:
            return query
        # check if there are other criteria with same index
        second_value = None
        second_moreorless = None
        criteria = ICriteria(self.context)
        for cid, criterion in criteria.items():
            if cid in form.keys() and cid != self.data.getId():
                if criterion.index == index:
                    second_value = form.get(cid)
                    second_moreorless = criterion.moreorless

        value = int(value)
        # portal_catalog({'price':{'query':[2,1000],'range':'min:max'}})
        if moreorless == u"more" and not second_value:
            range = "min"
        elif moreorless == u"less" and not second_value:
            range = "max"
        else:
            range = "min:max"
            if second_moreorless == u"more":
                value = [int(second_value), value]

        query[index] = {"query": value, "range": range}
        return query
Ejemplo n.º 14
0
class Widget(CountableWidget):
    """ Widget
    """
    widget_type = 'intselect'
    widget_label = _('Int Select')

    groups = (
        DefaultSchemata,
        LayoutSchemata,
        CountableSchemata,
        DisplaySchemata
    )

    index = ViewPageTemplateFile('widget.pt')

    # @property
    # def css_class(self):
    #     css = super(Widget, self).css_class
    #     css += ' col-xs-12 col-sm-6 col-lg-6 users'
    #     return css

    @property
    def default(self):
        """ Get default values
        """
        default = super(Widget, self).default or u''
        return default.encode('utf-8')

    def query(self, form):
        """ Get value from form and return a catalog dict query
        """
        query = {}
        index = self.data.get('index', '')
        index = index.encode('utf-8', 'replace')
        if not index:
            return query

        if self.hidden:
            value = self.default
        else:
            value = form.get(self.data.getId(), '')

        if not value:
            return query

        query[index] = int(value)
        return query

    def vocabulary(self, **kwargs):
        """ Return data vocabulary
        """
        reverse = safeToInt(self.data.get('sortreversed', 0))
        # import ipdb; ipdb.set_trace()
        self.data.catalog = 'portal_catalog'
        values = self.catalog_vocabulary()
        mapping = {}

        res = [(val, mapping.get(val, val)) for val in values]
        res.sort(key=operator.itemgetter(1), cmp=intcompare)

        if reverse:
            res.reverse()
        return res
Ejemplo n.º 15
0
 def __call__(self):
     self.msg = _(u'A small message')
     return self.index()
Ejemplo n.º 16
0
class Widget(AbstractWidget):
    """ Widget
    """

    widget_type = "intrange"
    widget_label = _("Int range field")

    groups = (DefaultSchemata, LayoutSchemata)
    index = ViewPageTemplateFile("widget.pt")

    # @property
    # def css_class(self):
    #     css = super(Widget, self).css_class
    #     css += ' col-xs-12 col-sm-6 col-lg-6 users'
    #     return css

    @property
    def default(self):
        """ Return default
        """
        default = self.data.get("default", "")
        if not default:
            return ("", "")
        default = default.split("=>")
        if len(default) != 2:
            return ("", "")

        min, max = default
        return (min, max)

    def query(self, form):
        """ Get value from form and return a catalog dict query
        """
        query = {}

        # import ipdb; ipdb.set_trace()
        index = self.data.get("index", "")
        index = index.encode("utf-8", "replace")
        value = None
        if not index:
            return query

        if self.hidden:
            min, max = self.default
        else:
            value = form.get(self.data.getId(), "")
            if not value or len(value) != 2:
                return query
            min, max = [int(x) if x else 0 for x in value]

        # import ipdb; ipdb.set_trace()
        if not value:
            return query
        # portal_catalog({'price':{'query':[2,1000],'range':'min:max'}})
        if min and not max:
            value = min
            range = "min"
        elif max and not min:
            value = max
            range = "max"
        else:
            value = [min, max]
            range = "min:max"
        query[index] = {"query": value, "range": range}
        return query
Ejemplo n.º 17
0
class IRealEstate(model.Schema):
    """ Marker interface and Dexterity Python Schema for RealEstate
    """

    # If you want, you can load a xml model created TTW here
    # and customize it in Python:

    # model.load('real_estate.xml')

    # directives.widget(level=RadioFieldWidget)
    sale_or_rent = schema.Choice(
        title=_(u"Sale or rent?"),
        vocabulary=u"collective.realestate.RealEstateFor")
    type = schema.Choice(
        title=_(u"Type of real estate"),
        vocabulary=u"collective.realestate.RealEstateTypes",
    )

    # text = RichText(
    #     title=_(u'Text'),
    #     required=False
    # )

    reference = schema.TextLine(title=_(u"Reference"), required=False)

    persons = schema.Int(title=_(u"Number of person(s)"), required=False)

    rooms = schema.Int(title=_(u"Number of bedroom(s)"), required=False)

    bathrooms = schema.Int(title=_(u"Number of bathroom(s)"), required=False)

    area = schema.Float(title=_(u"Area"),
                        description=_(u"Area in m²"),
                        required=False)

    parking = schema.Bool(title=_(u"Parking"),
                          description=_(u"Is there a free parking"),
                          required=False)

    pets = schema.Bool(title=_(u"Pets"),
                       description=_(u"Are pets authorised?"),
                       required=False)

    price = schema.Float(title=_(u"Price"), required=False)

    new = schema.Bool(title=_(u"New"), required=True, default=False)

    sold = schema.Bool(title=_(u"Sold ?"), required=True, default=False)