[Zope-CMF] Easy Content-Add script
Jeffrey P Shell
jeffrey@cuemedia.com
Tue, 13 Nov 2001 09:45:01 -0700
On Tuesday, November 13, 2001, at 07:10 AM, Jan Torben Heuer wrote:
> Am Dienstag, 13. November 2001 00:17 schrieb Jeffrey P Shell:
>
>> And I designed the app so that the users never saw the
>> 'folder_contents' view, or the CMF "Add" page (after much arm
>> wrestling with various action providers).
>
> That sounds nice.
> Do you offer me a part form your Sourcecode? Or is that Tool itsself
> OpenSource?
I can probably offer part of the source, hoping that it doesn't get
too mangled in the mail. It's not open source, but it was for a
customer (and the project got pulled before it could be completed).
class FilmTool(UniqueObject, SimpleItem):
id = 'film_tool'
meta_type = '...Film Tool'
### all code below belongs to the class, it's just outdented
### for mailing purposes.
### Film submission and validation helpers and policies
_killnoise = re.compile(r'\W').sub # non-alphanumeric chars
security.declarePublic('generateFilmId')
def generateFilmId(self, filmtitle, repl='', location=None):
"""\
Remove all non-alphanumeric characters. This method may
eventually be expanded to do more advanced ID generation.
"""
return self._killnoise(repl, filmtitle).lower()
security.declarePublic('createFilm')
def createFilm(self, newfilm, contact, comments="", target="films"):
"""\
Instantiate a new film object in the target location.
"""
if not newfilm.title:
raise ValueError('Film MUST have a title')
### Get all the needed tools
purl = getToolByName(self, 'portal_url')
workflow = getToolByName(self, 'portal_workflow')
typestool = getToolByName(self, 'portal_types')
discussion = getToolByName(self, 'portal_discussion')
membership = getToolByName(self, 'portal_membership')
### Get the destination (where the film wil be created)
proot = purl.getPortalObject()
dest = proot.unrestrictedTraverse(target)
### Instantiate the film, and populate fields and Contact info
film_id = self.generateFilmId(newfilm.title)
filmtype = typestool.getTypeInfo('Film')
obj = filmtype.constructInstance(dest, film_id)
obj.edit(...))
obj.setSubmitter(...)
### Tack on the comments from the submitter
if comments:
talkback = discussion.getDiscussionFor(obj)
if membership.isAnonymousUser():
creator = 'Submitter (%s, %s)' % (contact.lastname,
contact.firstname)
else:
creator = membership.getAuthenticatedMember().getUserName()
talkback.createReply(
title='Submitters Comments', text=comments,
Creator=creator
)
obj.indexObject()
workflow.notifyCreated(obj)
return obj