Example #1
0
class AddForm(form.AddForm):
    fields = field.Fields(ITeaserPortlet)

    label = _(u"Add Teaser Portlet")
    description = _(u"Shows the given infos on the front-page.")

    def __init__(self, context, request):
        super(AddForm, self).__init__(context, request)
        self._finishedAdd = None
        self.status = None

    def updateWidgets(self):
        self.fields['teaserdesc'].widgetFactory[
            INPUT_MODE] = WysiwygFieldWidget
        self.fields['internal_target'].widgetFactory = ContentTreeFieldWidget

        super(AddForm, self).updateWidgets()

    def nextURL(self):
        editview = aq_parent(aq_inner(self.context))
        context = aq_parent(aq_inner(editview))
        url = str(
            getMultiAdapter((context, self.request), name=u"absolute_url"))
        return url

    @button.buttonAndHandler(_(u"label_save", default=u"Save"), name='add')
    def handleAdd(self, action):
        data, errors = self.extractData()
        if errors:
            self.status = self.formErrorsMessage
            return
        obj = self.createAndAdd(data)
        if obj is not None:
            # mark only as finished if we get the new object
            self._finishedAdd = True

    @button.buttonAndHandler(_(u"label_cancel", default=u"Cancel"),
                             name='cancel_add')
    def handleCancel(self, action):
        nextURL = self.nextURL()
        self.request.response.redirect(nextURL)

    def add(self, obj):
        ob = self.context.add(obj)
        self._finishedAdd = True
        return ob

    def create(self, data):

        portal_path_l = len(
            self.context.portal_url.getPortalObject().getPhysicalPath())
        assignment_context_path = '/'.join(
            self.context.__parent__.getPhysicalPath()[portal_path_l:])

        return Assignment(assignment_context_path=assignment_context_path,
                          **data)
Example #2
0
class EditForm(form.EditForm):
    fields = field.Fields(ITeaserPortlet)

    label = _(u"Edit Teaser Portlet")
    description = _(u"Shows the given infos on the front-page.")

    def updateWidgets(self):
        self.fields['teaserdesc'].widgetFactory[
            INPUT_MODE] = WysiwygFieldWidget
        self.fields['internal_target'].widgetFactory = ContentTreeFieldWidget
        super(EditForm, self).updateWidgets()
Example #3
0
 def _validate_addresses(self, address):
     """E-Mail address validation
     """
     address = address.strip()
     if not self.email_expression.match(address):
         msg = _(u"error_invalid_addresses", default=u"Your E-mail address is not valid.")
         raise Invalid(msg)
Example #4
0
 def _validate_addresses(self, address):
     """E-Mail address validation
     """
     address = address.strip()
     if not self.email_expression.match(address):
         msg = _(u'error_invalid_addresses',
                 default=u'Your E-mail address is not valid.')
         raise Invalid(msg)
Example #5
0
class ITeaserPortlet(IPortletDataProvider):
    """A portlet which can some given Infos
    """

    teasertitle = schema.TextLine(title=_(u'Title'),
                                  description=u'',
                                  required=True)

    teaserdesc = schema.Text(title=_(u'Description'),
                             description=u'',
                             required=True)

    internal_target = schema.Choice(title=_(u"Internal Target"),
                                    description=_(u"Find an internal target \
 for this image to link to"),
                                    required=False,
                                    source=UUIDSourceBinder({}))
    image = NamedImage(title=_(u'Image'), description=u'', required=True)

    imagetitle = schema.TextLine(
        title=_(
            u'label_imagetitle',
            default=u'Image Title',
        ),
        description=_(
            u'help_imagetitle',
            default=u'The provided image title will be used as alt-text.',
        ),
        required=True,
    )
Example #6
0
 def __call__(self, context):
     factory = getUtility(
         IVocabularyFactory,
         name='plone.app.vocabularies.AvailableContentLanguages',
         context=context)
     vocab = factory(context)
     terms = vocab._terms
     terms.append(vocab.createTerm("", "default", _(u"inherit_language", default=u"inherit language")))
     return SimpleVocabulary(terms)
Example #7
0
 def __call__(self, context):
     factory = getUtility(
         IVocabularyFactory,
         name='plone.app.vocabularies.AvailableContentLanguages',
         context=context)
     vocab = factory(context)
     terms = vocab._terms
     terms.append(
         vocab.createTerm(
             "", "default",
             _(u"inherit_language", default=u"inherit language")))
     return SimpleVocabulary(terms)
Example #8
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            return

        message = data.get("message")
        email = data.get("email")
        subject = data.get("subject")
        sender = data.get("sender")
        self.send_feedback(email, subject, message, sender)
        msg = _(u"info_email_sent", default=u"The email was sent.")
        IStatusMessage(self.request).addStatusMessage(msg, type="info")
        return self.redirect()
Example #9
0
    def handleApply(self, action):
        data, errors = self.extractData()
        if errors:
            return

        message = data.get('message')
        email = data.get('email')
        subject = data.get('subject')
        sender = data.get('sender')
        self.send_feedback(email, subject, message, sender)
        msg = _(u'info_email_sent', default=u'The email was sent.')
        IStatusMessage(self.request).addStatusMessage(msg, type='info')
        return self.redirect()
Example #10
0
class IContactForm(Interface):
    """Interface for z3c.form"""
    sender = schema.TextLine(title=_(u"Sender_Name", default=u"Name"),
                             required=True,
                             description=_(u"help_Sender",
                                           default="Please enter your Name"))
    email = schema.TextLine(title=_(u"mail_address", default="E-Mail"),
                            required=True,
                            description=_(u"help_mail_address",
                                          default="Please enter your e-mail"))
    subject = schema.TextLine(title=_(u"label_subject", default="Subject"),
                              required=True,
                              description=_(u"help_subject",
                                            default="Please enter a Subject"))
    message = schema.Text(title=_(u"label_message", default="Message"),
                          required=True,
                          description=_(u"help_message",
                                        default="Please enter a Message"))
Example #11
0
class ISubsiteSchema(model.Schema):
    """The Subsite schema"""

    directives.fieldset('subsite',
                        label=_(u'Subsite'),
                        fields=('logo', 'logo_alt_text', 'additional_css',
                                'language_references',
                                'link_site_in_languagechooser',
                                'force_language'))

    logo = NamedBlobImage(title=_(u'label_logo', default=u'Logo'),
                          description=_(u'help_logo', default=u''),
                          required=False)

    logo_alt_text = schema.TextLine(
        title=_(u'label_logo_alt_text',
                default=u'Alternative text of the logo'),
        required=False,
        default=u'',
    )

    additional_css = schema.Text(title=_(u'label_additional_css',
                                         default=u'Additional CSS'),
                                 description=_(u'help_additional_css',
                                               default=u''),
                                 required=False,
                                 missing_value='')

    language_references = RelationList(
        title=_(u'label_language_references', default=u'Languages'),
        default=[],
        missing_value=[],
        value_type=RelationChoice(title=u'Related Subsites',
                                  source=SubsiteLanguagObjPathSourceBinder()),
        required=False,
        description=_(u'help_language_references',
                      default=_(u'The language switch will only be '
                                'displayed, if the chosen Subsite(s)'
                                'has a value in the forcelangage '
                                'field')))

    link_site_in_languagechooser = schema.Bool(title=_(
        u'label_link_site_in_languagechooser',
        default=u'Link Plone Site in language chooser'),
                                               default=False,
                                               required=False)

    force_language = schema.Choice(
        title=_(u'label_forcelanguage', default=u'Subsite language'),
        description=_(u'help_forcelanguage',
                      default=u'The Subsite and it\'s content will be '
                      'delivered in the choosen language'),
        vocabulary='ftw.subsites.languages',
        required=False)

    from_name = schema.TextLine(title=_(u'label_fromname',
                                        default=u'Email Sendername'),
                                description=_(u'help_fromname', default=u''),
                                required=False)

    from_email = schema.TextLine(title=_(u'label_fromemail',
                                         default=u'Email Senderaddress'),
                                 description=_(u'help_fromname', default=u''),
                                 required=False)
Example #12
0
from plone.app.blob.field import ImageField
from plone.app.layout.navigation.interfaces import INavigationRoot
from Products.Archetypes import atapi
from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata
from zope.interface import implements


schema = atapi.Schema((
    ImageField(
        name='logo',
        required=False,
        storage=atapi.AnnotationStorage(),
        schemata='subsite',
        widget=atapi.ImageWidget(
            label=_(u'label_logo',
                    default=u'Logo'),
            description=_(u'help_logo',
                          default=u''))),

    atapi.TextField(
            name='additional_css',
            storage=atapi.AnnotationStorage(),
            schemata='subsite',
            allowable_content_types=('text/plain', ),
            default_content_type='text/plain',
            default_input_type='text/plain',
            default_output_type='text/plain',
            widget=atapi.TextAreaWidget(
                rows=15,
                label=_(u'label_additional_css',
                        default=u'Additional CSS'),
Example #13
0
class ContactForm(form.Form):
    label = _(u"label_send_feedback", default=u"Send Feedback")
    fields = field.Fields(IContactForm)
    # don't use context to get widget data
    ignoreContext = True

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

        message = data.get('message')
        email = data.get('email')
        subject = data.get('subject')
        sender = data.get('sender')
        self.send_feedback(email, subject, message, sender)
        msg = _(u'info_email_sent', default=u'The email was sent.')
        IStatusMessage(self.request).addStatusMessage(msg, type='info')
        return self.redirect()

    @button.buttonAndHandler(_(u'button_cancel', default=u'Cancel'))
    def handle_cancel(self, action):
        return self.redirect()

    def redirect(self):
        """Redirect back
        """
        url = self.context.absolute_url()
        return self.request.RESPONSE.redirect(url)

    def send_feedback(self, recipient, subject, message, sender):
        """Send a feedback email to the email address defined in subsite.
        """
        mh = getToolByName(self.context, 'MailHost')
        portal = getToolByName(self.context, 'portal_url').getPortalObject()
        nav_root = None
        if not '/'.join(portal.getPhysicalPath()) == getNavigationRoot(
                self.context):
            nav_root = self.context.restrictedTraverse(
                getNavigationRoot(self.context))
        if nav_root:
            site_title = nav_root.Title()
            site_url = nav_root.absolute_url()
        else:
            site_title = portal.Title()
            site_url = portal.absolute_url()

        text = translate(
            u'feedback_mail_text',
            domain='ftw.subsite',
            default=
            '${sender} sends you a message from your site ${site_title}(${site_url}):\n${msg}',
            context=self.request,
            mapping={
                'sender': "%s (%s)" % (sender, recipient),
                'msg': message,
                'site_title': site_title,
                'site_url': site_url
            })

        # create the message root with from, to, and subject headers
        msg = MIMEText(text.encode('windows-1252'), 'plain', 'windows-1252')
        msg['Subject'] = Header(subject, 'windows-1252')

        default_from_name = portal.getProperty('email_from_name', '')
        default_from_email = portal.getProperty('email_from_address', '')

        if nav_root:
            email_from_name = nav_root.from_name or default_from_name
            email_from_email = nav_root.from_email or default_from_email
        else:
            email_from_name = default_from_name
            email_from_email = default_from_email
        msg['From'] = "%s <%s>" % (email_from_name, email_from_email)

        msg['reply-to'] = "%s <%s>" % (sender, recipient)

        # send the message
        mh.send(msg, mto=email_from_email, mfrom=[email_from_email])
Example #14
0
from ftw.subsite import _
from ftw.subsite.config import PROJECTNAME
from ftw.subsite.interfaces import ISubsite
from plone.app.blob.field import ImageField
from plone.app.layout.navigation.interfaces import INavigationRoot
from Products.Archetypes import atapi
from Products.ATContentTypes.content import folder
from Products.ATContentTypes.content import schemata
from zope.interface import implements

schema = atapi.Schema(
    (ImageField(name='logo',
                required=False,
                storage=atapi.AnnotationStorage(),
                schemata='subsite',
                widget=atapi.ImageWidget(label=_(u'label_logo',
                                                 default=u'Logo'),
                                         description=_(u'help_logo',
                                                       default=u''))),
     atapi.TextField(name='additional_css',
                     storage=atapi.AnnotationStorage(),
                     schemata='subsite',
                     allowable_content_types=('text/plain', ),
                     default_content_type='text/plain',
                     default_input_type='text/plain',
                     default_output_type='text/plain',
                     widget=atapi.TextAreaWidget(
                         rows=15,
                         label=_(u'label_additional_css',
                                 default=u'Additional CSS'),
                         description=_(u'help_additional_css', default=u''))),
     atapi.ReferenceField(