Back to index

plone3  3.1.7
link.py
Go to the documentation of this file.
00001 #  ATContentTypes http://plone.org/products/atcontenttypes/
00002 #  Archetypes reimplementation of the CMF core types
00003 #  Copyright (c) 2003-2006 AT Content Types development team
00004 #
00005 #  This program is free software; you can redistribute it and/or modify
00006 #  it under the terms of the GNU General Public License as published by
00007 #  the Free Software Foundation; either version 2 of the License, or
00008 #  (at your option) any later version.
00009 #
00010 #  This program is distributed in the hope that it will be useful,
00011 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
00012 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00013 #  GNU General Public License for more details.
00014 #
00015 #  You should have received a copy of the GNU General Public License
00016 #  along with this program; if not, write to the Free Software
00017 #  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00018 #
00019 """
00020 
00021 
00022 """
00023 __author__  = 'Christian Heimes <tiran@cheimes.de>'
00024 __docformat__ = 'restructuredtext'
00025 __old_name__ = 'Products.ATContentTypes.types.ATLink'
00026 
00027 import urlparse
00028 from urllib import quote
00029 
00030 from Products.CMFCore.permissions import View
00031 from Products.CMFCore.permissions import ModifyPortalContent
00032 from AccessControl import ClassSecurityInfo
00033 
00034 from Products.Archetypes.atapi import Schema
00035 from Products.Archetypes.atapi import StringField
00036 from Products.Archetypes.atapi import StringWidget
00037 
00038 from Products.ATContentTypes.config import PROJECTNAME
00039 from Products.ATContentTypes.content.base import registerATCT
00040 from Products.ATContentTypes.content.base import ATCTContent
00041 from Products.ATContentTypes.interfaces import IATLink
00042 from Products.ATContentTypes.content.schemata import ATContentTypeSchema
00043 from Products.ATContentTypes.content.schemata import finalizeATCTSchema
00044 
00045 from Products.ATContentTypes import ATCTMessageFactory as _
00046 
00047 ATLinkSchema = ATContentTypeSchema.copy() + Schema((
00048     StringField('remoteUrl',
00049         required=True,
00050         searchable=True,
00051         primary=True,
00052         default = "http://",
00053         # either mailto, absolute url or relative url
00054         validators = (),
00055         widget = StringWidget(
00056             description = '',
00057             label = _(u'label_url', default=u'URL')
00058             )),
00059     ))
00060 finalizeATCTSchema(ATLinkSchema)
00061 
00062 class ATLink(ATCTContent):
00063     """A link to an internal or external resource."""
00064 
00065     schema         =  ATLinkSchema
00066 
00067     portal_type    = 'Link'
00068     archetype_name = 'Link'
00069     _atct_newTypeFor = {'portal_type' : 'CMF Link', 'meta_type' : 'Link'}
00070     assocMimetypes = ()
00071     assocFileExt   = ('link', 'url', )
00072     cmf_edit_kws   = ('remote_url', )
00073 
00074     __implements__ = ATCTContent.__implements__, IATLink
00075 
00076     security       = ClassSecurityInfo()
00077 
00078     security.declareProtected(ModifyPortalContent, 'setRemoteUrl')
00079     def setRemoteUrl(self, value, **kwargs):
00080         """remute url mutator
00081 
00082         Use urlparse to sanify the url
00083         Also see http://dev.plone.org/plone/ticket/3296
00084         """
00085         if value:
00086             value = urlparse.urlunparse(urlparse.urlparse(value))
00087         self.getField('remoteUrl').set(self, value, **kwargs)
00088 
00089     security.declareProtected(View, 'remote_url')
00090     def remote_url(self):
00091         """CMF compatibility method
00092         """
00093         return self.getRemoteUrl()
00094 
00095     security.declarePrivate('cmf_edit')
00096     def cmf_edit(self, remote_url=None, **kwargs):
00097         if not remote_url:
00098             remote_url = kwargs.get('remote_url', None)
00099         self.update(remoteUrl = remote_url, **kwargs)
00100 
00101     security.declareProtected(View, 'getRemoteUrl')
00102     def getRemoteUrl(self):
00103         """Sanitize output
00104         """
00105         value = self.Schema()['remoteUrl'].get(self)
00106         if not value: value = '' # ensure we have a string
00107         return quote(value, safe='?$#@/:=+;$,&')
00108 
00109 registerATCT(ATLink, PROJECTNAME)