Back to index

plone3  3.1.7
site.py
Go to the documentation of this file.
00001 from zope.app.form.browser import TextAreaWidget
00002 from zope.interface import Interface
00003 from zope.component import adapts
00004 from zope.formlib.form import FormFields
00005 from zope.interface import implements
00006 from zope.schema import Bool
00007 from zope.schema import Text
00008 from zope.schema import TextLine
00009 from zope.schema import SourceText
00010 
00011 from Products.CMFCore.utils import getToolByName
00012 from Products.CMFDefault.formlib.schema import ProxyFieldProperty
00013 from Products.CMFDefault.formlib.schema import SchemaAdapterBase
00014 from Products.CMFPlone import PloneMessageFactory as _
00015 from Products.CMFPlone.interfaces import IPloneSiteRoot
00016 from Products.CMFPlone.utils import safe_unicode
00017 
00018 from form import ControlPanelForm
00019 
00020 class ISiteSchema(Interface):
00021 
00022     site_title = TextLine(title=_(u'Site title'),
00023                           description=_(u"This shows up in the title bar of "
00024                                         "browsers, in syndication feeds, "
00025                                         "etc."),
00026                           default=u'')
00027 
00028     site_description = Text(title=_(u'Site description'),
00029                            description=_(u"The site description is available "
00030                                "in syndicated content and in search engines. "
00031                                "Keep it brief."),
00032                            default=u'',
00033                            required=False)
00034 
00035     visible_ids = Bool(title=_(u"Show 'Short Name' on content?"),
00036                        description=_(u"Display and allow users to edit the "
00037                            "'Short name' content identifiers, which form the "
00038                            "URL part of a content item's address. Once "
00039                            "enabled, users will then be able to enable this "
00040                            "option in their preferences."),
00041                        default=False,
00042                        required=False)
00043 
00044     enable_inline_editing = Bool(title=_(u"Enable inline editing"),
00045                                  description=_(u"Check this to enable "
00046                                                 "inline editing on the site."),
00047                                  default=True,
00048                                  required=False)
00049 
00050     enable_link_integrity_checks = Bool(title=_(u"Enable link integrity "
00051                                                  "checks"),
00052                           description=_(u"Determines if the users should get "
00053                               "warnings when they delete or move content that "
00054                               "is linked from inside the site."),
00055                           default=True,
00056                           required=False)
00057 
00058     ext_editor = Bool(title=_(u'Enable External Editor feature'),
00059                           description=_(u"Determines if the external editor "
00060                               "feature is enabled. This feature requires a "
00061                               "special client-side application installed. The "
00062                               "users also have to enable this in their "
00063                               "preferences."),
00064                           default=False,
00065                           required=False)
00066 
00067     enable_sitemap = Bool(title=_(u"Expose sitemap.xml.gz in the portal root"),
00068                           description=_(u"Exposes your content as a file "
00069                               "according to the sitemaps.org standard. You "
00070                               "can submit this to compliant search engines "
00071                               "like Google, Yahoo and Microsoft. It allows "
00072                               "these search engines to more intelligently "
00073                               "crawl your site."),
00074                           default=False,
00075                           required=False)
00076 
00077     webstats_js = SourceText(title=_(u'JavaScript for web statistics support'),
00078                         description=_(u"For enabling web statistics support "
00079                               "from external providers (for e.g. Google "
00080                               "Analytics). Paste the code snippets provided. "
00081                               "It will be included in the rendered HTML as "
00082                               "entered near the end of the page."),
00083                         default=u'',
00084                         required=False)
00085 
00086 
00087 class SiteControlPanelAdapter(SchemaAdapterBase):
00088 
00089     adapts(IPloneSiteRoot)
00090     implements(ISiteSchema)
00091 
00092     def __init__(self, context):
00093         super(SiteControlPanelAdapter, self).__init__(context)
00094         self.portal = context
00095         pprop = getToolByName(self.portal, 'portal_properties')
00096         self.context = pprop.site_properties
00097         self.encoding = pprop.site_properties.default_charset
00098 
00099     def get_site_title(self):
00100         title = getattr(self.portal, 'title', u'')
00101         return safe_unicode(title)
00102 
00103     def set_site_title(self, value):
00104         self.portal.title = value.encode(self.encoding)
00105 
00106     def get_site_description(self):
00107         description = getattr(self.portal, 'description', u'')
00108         return safe_unicode(description)
00109 
00110     def set_site_description(self, value):
00111         if value is not None:
00112             self.portal.description = value.encode(self.encoding)
00113         else:
00114             self.portal.description = ''
00115 
00116     def get_webstats_js(self):
00117         description = getattr(self.context, 'webstats_js', u'')
00118         return safe_unicode(description)
00119 
00120     def set_webstats_js(self, value):
00121         if value is not None:
00122             self.context.webstats_js = value.encode(self.encoding)
00123         else:
00124             self.context.webstats_js = ''
00125 
00126     site_title = property(get_site_title, set_site_title)
00127     site_description = property(get_site_description, set_site_description)
00128     webstats_js = property(get_webstats_js, set_webstats_js)
00129 
00130     visible_ids = ProxyFieldProperty(ISiteSchema['visible_ids'])
00131     enable_inline_editing = ProxyFieldProperty(ISiteSchema['enable_inline_editing'])
00132     enable_link_integrity_checks = ProxyFieldProperty(ISiteSchema['enable_link_integrity_checks'])
00133     ext_editor = ProxyFieldProperty(ISiteSchema['ext_editor'])
00134     enable_sitemap = ProxyFieldProperty(ISiteSchema['enable_sitemap'])
00135 
00136 
00137 class SmallTextAreaWidget(TextAreaWidget):
00138 
00139     height = 5
00140 
00141 
00142 class SiteControlPanel(ControlPanelForm):
00143 
00144     form_fields = FormFields(ISiteSchema)
00145     form_fields['site_description'].custom_widget = SmallTextAreaWidget
00146 
00147     label = _("Site settings")
00148     description = _("Site-wide settings.")
00149     form_name = _("Site settings")