Exemplo n.º 1
0
    def subscribeNotified(self):
        # use the adapter to configure the subscribers
        obj = self.context.aq_inner
        adapted = ISubscriptionManager(obj)
        form = self.request.form
        if form.has_key('persons'):
            adapted.setSubscribedMembers(form['persons'])

            if form.has_key('notified'):
                sendNotification(self, obj)
        else:
            persons = self.context.getProperty('object_subscribers')
            for person in persons:
                adapted.unsubscribeMember(person)

        ksscore = self.getCommandSet('core')

        #cp_view = zope.component.getMultiAdapter((obj, self.request, self), name='zopen.subscription')
        #content_html = cp_view.render()
        #print content_html

        #ksscore.replaceInnerHTML('dl.GeditNotified', content_html)

        ksscore.replaceHTML("#subscription", self.column_two())
        self.getCommandSet('plone').issuePortalMessage(
            translate(_(u'modified_success', default="Modified success."),
                      context=self.request),
            translate(_(u'Info', default='Info'), context=self.request))

        return self.render()
Exemplo n.º 2
0
    def subscribeNotified(self):
        # use the adapter to configure the subscribers
        obj = self.context.aq_inner
        adapted = ISubscriptionManager(obj)
        form = self.request.form
        if form.has_key('persons'):
            adapted.setSubscribedMembers(form['persons'])

            if form.has_key('notified'):
                sendNotification(self, obj)
        else:
            persons = self.context.getProperty('object_subscribers')
            for person in persons:
                adapted.unsubscribeMember(person)


        ksscore = self.getCommandSet('core')

        #cp_view = zope.component.getMultiAdapter((obj, self.request, self), name='zopen.subscription') 
        #content_html = cp_view.render()
        #print content_html
        
        #ksscore.replaceInnerHTML('dl.GeditNotified', content_html)

        ksscore.replaceHTML("#subscription", self.column_two())
        self.getCommandSet('plone').issuePortalMessage(
                translate(_(u'modified_success', default="Modified success."), context=self.request),
                translate(_(u'Info', default='Info'), context=self.request))
        

        return self.render()
Exemplo n.º 3
0
    def _addTodoItem(self, folder, id, title='', notify=False, responsibleParty='',\
            subject='', endDate='', year='', month='', day='', createmilestone=False):
        """Create Todo Item"""

        ksscore = self.getCommandSet('core')



        folder.invokeFactory('TodoItem', id)
        o = getattr(folder, id)
        o.setTitle(title)
        # o.setDescription(self.context.Title())
        if subject:
            o.setSubject([subject])
        if endDate is not None:
            o.setEndDate(endDate)
        if responsibleParty:
            o.setResponsibleParty(responsibleParty)

        o.reindexObject()

        if notify:
            sendNotification(self, o)

        # 将创建人和负责人做为任务的订阅人
        p = [o.getResponsibleParty(), o.Creator()]
        sm = ISubscriptionManager(o)
        sm.setSubscribedMembers(p)
        
        if createmilestone and endDate:
             folder_aq = folder.aq_inner.aq_parent
             createMilestone(folder_aq, title, endDate, responsibleParty, notify=False)
             
        return o
Exemplo n.º 4
0
    def filerepos_add(self):
        files = self.request.form['file']

        file_manager = getUtility(IFileManager, 'file_manager')

        wtool = getToolByName(self.context, 'portal_workflow')
        #计数器
        count = 0
        for item in files:
            file_from_request = item.file
            if not file_from_request:
                continue
            else:
                count += 1

            # TODO:
            # automatically judge the type of the file,
            # to File, Image, or others.
            category = getattr(self.context, item.category)

            portal_membership = getToolByName(self.context,
                                              'portal_membership')
            member = portal_membership.getAuthenticatedMember()
            fileObj = file_manager.addFile(category, file_from_request)

            if item.has_key("description"):
                fileObj.setDescription(item["description"])

            if item.get("mark_private", 0):
                wtool.doActionFor(fileObj, 'hide')
                if item.get("submit", 0):
                    wtool.doActionFor(fileObj, 'privatesubmit')
            elif item.get("submit", 0):
                wtool.doActionFor(fileObj, 'submit')

            # use the adapter to configure the subscribers
            if self.request.form.has_key('persons'):
                adapted = ISubscriptionManager(fileObj)
                adapted.setSubscribedMembers(self.request.form['persons'])
                adapted.subscribeAuthenticatedMember()
                sendNotification(self, fileObj)

            fileObj.reindexObject()

        if count == 0:
            #当用户没有选择一个文件做为上传对象时,给予警告
            isNullFileField(self, '')
            return self.request.response.redirect(self.context.absolute_url())

        plone_utils = getToolByName(self.context, 'plone_utils')
        msg = translate(_(u'you added ${count} files success.',
                          default="You added ${count} files success.",
                          mapping={u'count': len(files)}),
                        context=self.request)
        plone_utils.addPortalMessage(msg, 'info')

        # back to the folder
        self.request.response.redirect(self.context.absolute_url())
Exemplo n.º 5
0
    def edit_file(self, fileViewUrl=None):
        form = self.request.form
        fileObj = self.context.aq_inner
        # info("%r" % form)

        category = fileObj.aq_parent
        filerepos = category.aq_parent
        file_from_request = form['file']

        # 移动位置
        if category.getId() != form['category']:
            cat_m = ICategoryManager(filerepos)
            fileObj = cat_m.setContentCategory(fileObj, form['category'])

        portal_membership = getToolByName(self.context, 'portal_membership')
        member = portal_membership.getAuthenticatedMember()

        if file_from_request:
            if hasattr(fileObj, 'setFile'):
                fileObj.setFile(file_from_request)
            else:
                fileObj.setImage(file_from_request)

        if form.has_key("description"):
            fileObj.setDescription(form["description"])

        # to get review_state and check and set
        #wtool = getToolByName(self.context, 'portal_workflow')
        #review_state = wtool.getInfoFor(fileObj, 'review_state', '')
        #if review_state == 'private':
        #    if not form.has_key("mark_private") or form["mark_private"] != 'on':
        #        wtool.doActionFor(fileObj, 'show')
        #else:
        #    if form.has_key("mark_private") and form["mark_private"]:
        #        wtool.doActionFor(fileObj, 'hide')

        # use the adapter to configure the subscribers
        if form.has_key('persons'):
            adapted = ISubscriptionManager(fileObj)
            adapted.setSubscribedMembers(form['persons'])
            adapted.subscribeAuthenticatedMember()
            sendNotification(self, fileObj)

        fileObj.reindexObject()

        plone_utils = getToolByName(self.context, 'plone_utils')
        msg = translate(_(u'modified success.', default="Modified success."),
                        context=self.request)
        plone_utils.addPortalMessage(msg, 'info')
        if fileViewUrl:
            self.request.response.redirect(fileObj.absolute_url() + '/@@' + \
                                            fileViewUrl)
        else:
            self.request.response.redirect(filerepos.absolute_url())
Exemplo n.º 6
0
    def edit_file(self, fileViewUrl=None):
        form = self.request.form
        fileObj = self.context.aq_inner
        # info("%r" % form)

        category = fileObj.aq_parent
        filerepos = category.aq_parent
        file_from_request = form["file"]

        # 移动位置
        if category.getId() != form["category"]:
            cat_m = ICategoryManager(filerepos)
            fileObj = cat_m.setContentCategory(fileObj, form["category"])

        portal_membership = getToolByName(self.context, "portal_membership")
        member = portal_membership.getAuthenticatedMember()

        if file_from_request:
            if hasattr(fileObj, "setFile"):
                fileObj.setFile(file_from_request)
            else:
                fileObj.setImage(file_from_request)

        if form.has_key("description"):
            fileObj.setDescription(form["description"])

        # to get review_state and check and set
        # wtool = getToolByName(self.context, 'portal_workflow')
        # review_state = wtool.getInfoFor(fileObj, 'review_state', '')
        # if review_state == 'private':
        #    if not form.has_key("mark_private") or form["mark_private"] != 'on':
        #        wtool.doActionFor(fileObj, 'show')
        # else:
        #    if form.has_key("mark_private") and form["mark_private"]:
        #        wtool.doActionFor(fileObj, 'hide')

        # use the adapter to configure the subscribers
        if form.has_key("persons"):
            adapted = ISubscriptionManager(fileObj)
            adapted.setSubscribedMembers(form["persons"])
            adapted.subscribeAuthenticatedMember()
            sendNotification(self, fileObj)

        fileObj.reindexObject()

        plone_utils = getToolByName(self.context, "plone_utils")
        msg = translate(_(u"modified success.", default="Modified success."), context=self.request)
        plone_utils.addPortalMessage(msg, "info")
        if fileViewUrl:
            self.request.response.redirect(fileObj.absolute_url() + "/@@" + fileViewUrl)
        else:
            self.request.response.redirect(filerepos.absolute_url())
Exemplo n.º 7
0
    def _addTodoItem(self, folder, id, title='', notify=False, responsibleParty='',\
            subject='', endDate='', year='', month='', day='', createmilestone=False):
        """Create Todo Item"""

        ksscore = self.getCommandSet('core')

        folder.invokeFactory('TodoItem', id)
        o = getattr(folder, id)
        o.setTitle(title)
        # o.setDescription(self.context.Title())
        if subject:
            o.setSubject([subject])
        if endDate is not None:
            o.setEndDate(endDate)
        if responsibleParty:
            o.setResponsibleParty(responsibleParty)

        o.reindexObject()

        if notify:
            sendNotification(self, o)

        # 将创建人和负责人做为任务的订阅人
        p = [o.getResponsibleParty(), o.Creator()]
        sm = ISubscriptionManager(o)
        sm.setSubscribedMembers(p)

        if createmilestone and endDate:
            folder_aq = folder.aq_inner.aq_parent
            createMilestone(folder_aq,
                            title,
                            endDate,
                            responsibleParty,
                            notify=False)

        return o
Exemplo n.º 8
0
    def __call__(self):
        """ submit or show the form """

        form = self.request.form
        # info("%r", form)

        if not form.get('form.submitted',''):
            return self.template()

        title = form.get('title', '')
        text = form.get('text', '')
        private = form.get('private', '')
        category_id = form.get('category', '')
        category = getattr(self.context, category_id)

        subscribers = form.get('persons', [])
        milestone = form.get('milestone', '')
        complete = milestone and form.get('completes_milestone', False)

        ctool = getToolByName(self.context, 'portal_catalog')
        messages = ctool( path='/'.join(self.context.getPhysicalPath()), 
                   portal_type='Message')
        ids = [m.getId for m in messages]

        random_id = str(random.randrange(100000, 999999))
        while random_id in ids:
            random_id = str(random.randrange(100000, 999999))

        category.invokeFactory('Message', random_id)
        msg = getattr(category, random_id)
        msg.setTitle(title)
        msg.setText(text, mimetype=form.get('mimetype', 'text/x-web-intelligent'))

        if private:
            wftool = getToolByName(self.context, 'portal_workflow')
            wftool.doActionFor(msg, 'hide')

        if form.has_key("upload"):
            file_manager = getUtility(IFileManager, 'file_manager')
            filerepos = file_manager.getFilerepos(msg)
            files = []
            for request_file in form["upload"]:
                if not hasattr(request_file, 'file'):
                    continue
                file_cat = getattr(filerepos, request_file.category)
                the_file = file_manager.addFile(file_cat, request_file.file)

                if the_file is not None:
                    files.append(the_file)
                    if private:
                        wftool.doActionFor(the_file, 'hide')
            if files:
                msg.setRelatedItems(files)

        # 订阅
        sm = ISubscriptionManager(msg)
        sm.setSubscribedMembers(subscribers)
        msg.reindexObject()

        event.notify(ObjectModifiedEvent(msg))
    
        sendNotification(self, msg)
        sm.subscribeAuthenticatedMember()

        # 和milestone关联
        if milestone:
            brains = ctool(UID = milestone)
            if brains:
                obj = brains[0].getObject()
                obj.addRelatedItem( msg.UID() )
                obj.indexObject()

                if complete:
                    wftool = getToolByName(self.context, 'portal_workflow')
                    state = wftool.getInfoFor(obj, 'review_state')
                    if state != 'completed':
                        wftool.doActionFor(obj, 'complete')

        return self.request.response.redirect(self.context.absolute_url())
Exemplo n.º 9
0
    def save_message(self):
        form = self.request.form
        # info("%r" % form)

        msg = self.context.aq_inner

        if form.has_key("title"):
            msg.setTitle(form["title"])
        if form.has_key("body"):
            msg.setText(form["body"], mimetype=form.get('mimetype', 'text/x-web-intelligent' ))
        if form.has_key("category"):
            # context is the message, parent is the category
            if self.context.aq_inner.aq_parent.getId() != form["category"]:
                cat_m = ICategoryManager(msg.aq_parent.aq_parent)
                # info("%r" % self.context)
                # info("%r" % self.context.aq_parent)
                # info("%r" % self.context.aq_inner.aq_parent)
                msg = cat_m.setContentCategory(msg, form["category"])

        if form.has_key("persons"):
            sm = ISubscriptionManager(msg)
            sm.setSubscribedMembers(form["persons"])
            sendNotification(self, msg)
            sm.subscribeAuthenticatedMember()

        wftool = getToolByName(msg, 'portal_workflow')
        review_state = self.review_state()
        private = form.has_key('private')
        if(private and review_state != 'private'): 
            wftool.doActionFor(msg, 'hide')
        elif(review_state == 'private' and not private):
            wftool.doActionFor(msg, 'show')

        comments = msg.contentValues()
        for msg_cmt in [msg] + comments:
            attachments = msg_cmt.getRelatedItems()
            for obj in attachments:
                obj_state = wftool.getInfoFor(obj, 'review_state') 
                if private and obj_state != 'private':
                    wftool.doActionFor(obj, 'hide')
                elif obj_state == 'private' and not private:
                    wftool.doActionFor(obj, 'show')

        if form.has_key("upload"):
            file_manager = getUtility(IFileManager, 'file_manager')
            filerepos = file_manager.getFilerepos(msg)
            files = msg.getRawRelatedItems()
            for request_file in form["upload"]:
                if not hasattr(request_file, 'file'):
                    continue
                file_cat = getattr(filerepos, request_file.category)
                the_file = file_manager.addFile(file_cat, request_file.file)

                if the_file is not None:
                    if private:
                        wftool.doActionFor(the_file, 'hide')
                    files.append(the_file.UID())
            msg.setRelatedItems(files)

        # 和milestone关联
        milestone = form.get('milestone', '')
        milestone_old = msg.getRelatedMilestones()
        milestone_obj = None
        milestone_changed = milestone != (milestone_old and milestone_old[0].UID or '')
        if milestone_changed:
            for brain in milestone_old:
                m = brain.getObject()
                m.removeRelatedItem(msg.UID())
                m.indexObject()

        if milestone:
            ctool = getToolByName(msg, 'portal_catalog')
            brains = ctool(UID = milestone)
            if brains:
                milestone_obj = brains[0].getObject()

            if milestone_changed:
                milestone_obj.addRelatedItem(msg.UID())
                milestone_obj.indexObject()

        if form.get('completes_milestone', '') and (milestone_obj is not None):
            wftool = getToolByName(msg, 'portal_workflow')
            state = wftool.getInfoFor(milestone_obj, 'review_state')
            if state != 'completed':
                wftool.doActionFor(milestone_obj, 'complete')

        msg.reindexObject()

        event.notify(ObjectEditedEvent(msg))
        event.notify(ObjectModifiedEvent(msg))
        self.request.response.redirect(msg.aq_parent.aq_parent.absolute_url())
Exemplo n.º 10
0
    def save_as_new_version(self, fileViewUrl=None):
        """更新文件版本"""
        form = self.request.form
        file_from_request = form['file']
        fileObj = self.context.aq_inner
        category = fileObj.aq_parent
        filerepos = category.aq_parent
        if isNullFileField(self, file_from_request):
            return self.request.response.redirect(filerepos.absolute_url())

        if category.getId() != form['category']:
            cat_m = ICategoryManager(filerepos)
            fileObj = cat_m.setContentCategory(fileObj, form['category'])

        rep_tool = getToolByName(self.context, 'portal_repository')
        comment = ''
        byte_size = fileObj.get_size()
        currentContributor = fileObj.Contributors() and \
                fileObj.Contributors()[0] or fileObj.Creator()
        rep_tool.save(fileObj, comment, { \
                "byte_size": byte_size, "title": fileObj.Title(),\
                "principal": currentContributor})
        history = rep_tool.getHistory(fileObj)
        portal_membership = getToolByName(self.context, 'portal_membership')
        member = portal_membership.getAuthenticatedMember()

        zpath = '/'.join(fileObj.getPhysicalPath())
        ext = zpath.split(".")[-1]
        archiveName = getArchiveTime(history[0]) + "." + ext
        tramline_archive_params = '|'.join(
            (zpath, member.getId(), archiveName, comment))
        self.request.response.setHeader("tramline_archive",
                                        tramline_archive_params)

        if file_from_request:
            if hasattr(fileObj, 'setFile'):
                fileObj.setFile(file_from_request)
            else:
                fileObj.setImage(file_from_request)

        if form.has_key("description"):
            fileObj.setDescription(form["description"])

        # to get review_state and check and set
        #wtool = getToolByName(self.context, 'portal_workflow')
        #review_state = wtool.getInfoFor(fileObj, 'review_state', '')
        #if review_state == 'private':
        #    if not form.has_key("mark_private") or form["mark_private"] != 'on':
        #        wtool.doActionFor(fileObj, 'show')
        #else:
        #    if form.has_key("mark_private") and form["mark_private"]:
        #        wtool.doActionFor(fileObj, 'hide')

        # use the adapter to configure the subscribers
        if form.has_key('persons'):
            adapted = ISubscriptionManager(fileObj)
            adapted.setSubscribedMembers(form['persons'])
            adapted.subscribeAuthenticatedMember()
            sendNotification(self, fileObj)

        fileObj.reindexObject()

        plone_utils = getToolByName(self.context, 'plone_utils')
        msg = translate(_(u'save as new version success.',
                          default="Save as new version  success."),
                        context=self.request)
        plone_utils.addPortalMessage(msg, 'info')
        if fileViewUrl:
            self.request.response.redirect(fileObj.absolute_url() + '/@@' + \
                                            fileViewUrl)
        else:
            self.request.response.redirect(filerepos.absolute_url())
Exemplo n.º 11
0
    def save_as_new_version(self, fileViewUrl=None):

        """更新文件版本"""
        form = self.request.form
        file_from_request = form["file"]
        fileObj = self.context.aq_inner
        category = fileObj.aq_parent
        filerepos = category.aq_parent
        if isNullFileField(self, file_from_request):
            return self.request.response.redirect(filerepos.absolute_url())

        if category.getId() != form["category"]:
            cat_m = ICategoryManager(filerepos)
            fileObj = cat_m.setContentCategory(fileObj, form["category"])

        rep_tool = getToolByName(self.context, "portal_repository")
        comment = ""
        byte_size = fileObj.get_size()
        currentContributor = fileObj.Contributors() and fileObj.Contributors()[0] or fileObj.Creator()
        rep_tool.save(
            fileObj, comment, {"byte_size": byte_size, "title": fileObj.Title(), "principal": currentContributor}
        )
        history = rep_tool.getHistory(fileObj)
        portal_membership = getToolByName(self.context, "portal_membership")
        member = portal_membership.getAuthenticatedMember()

        zpath = "/".join(fileObj.getPhysicalPath())
        ext = zpath.split(".")[-1]
        archiveName = getArchiveTime(history[0]) + "." + ext
        tramline_archive_params = "|".join((zpath, member.getId(), archiveName, comment))
        self.request.response.setHeader("tramline_archive", tramline_archive_params)

        if file_from_request:
            if hasattr(fileObj, "setFile"):
                fileObj.setFile(file_from_request)
            else:
                fileObj.setImage(file_from_request)

        if form.has_key("description"):
            fileObj.setDescription(form["description"])

        # to get review_state and check and set
        # wtool = getToolByName(self.context, 'portal_workflow')
        # review_state = wtool.getInfoFor(fileObj, 'review_state', '')
        # if review_state == 'private':
        #    if not form.has_key("mark_private") or form["mark_private"] != 'on':
        #        wtool.doActionFor(fileObj, 'show')
        # else:
        #    if form.has_key("mark_private") and form["mark_private"]:
        #        wtool.doActionFor(fileObj, 'hide')

        # use the adapter to configure the subscribers
        if form.has_key("persons"):
            adapted = ISubscriptionManager(fileObj)
            adapted.setSubscribedMembers(form["persons"])
            adapted.subscribeAuthenticatedMember()
            sendNotification(self, fileObj)

        fileObj.reindexObject()

        plone_utils = getToolByName(self.context, "plone_utils")
        msg = translate(
            _(u"save as new version success.", default="Save as new version  success."), context=self.request
        )
        plone_utils.addPortalMessage(msg, "info")
        if fileViewUrl:
            self.request.response.redirect(fileObj.absolute_url() + "/@@" + fileViewUrl)
        else:
            self.request.response.redirect(filerepos.absolute_url())
Exemplo n.º 12
0
    def filerepos_add(self):
        files = self.request.form["file"]

        file_manager = getUtility(IFileManager, "file_manager")

        wtool = getToolByName(self.context, "portal_workflow")
        # 计数器
        count = 0
        for item in files:
            file_from_request = item.file
            if not file_from_request:
                continue
            else:
                count += 1

            # TODO:
            # automatically judge the type of the file,
            # to File, Image, or others.
            category = getattr(self.context, item.category)

            portal_membership = getToolByName(self.context, "portal_membership")
            member = portal_membership.getAuthenticatedMember()
            fileObj = file_manager.addFile(category, file_from_request)

            if item.has_key("description"):
                fileObj.setDescription(item["description"])

            if item.get("mark_private", 0):
                wtool.doActionFor(fileObj, "hide")
                if item.get("submit", 0):
                    wtool.doActionFor(fileObj, "privatesubmit")
            elif item.get("submit", 0):
                wtool.doActionFor(fileObj, "submit")

            # use the adapter to configure the subscribers
            if self.request.form.has_key("persons"):
                adapted = ISubscriptionManager(fileObj)
                adapted.setSubscribedMembers(self.request.form["persons"])
                adapted.subscribeAuthenticatedMember()
                sendNotification(self, fileObj)

            fileObj.reindexObject()

        if count == 0:
            # 当用户没有选择一个文件做为上传对象时,给予警告
            isNullFileField(self, "")
            return self.request.response.redirect(self.context.absolute_url())

        plone_utils = getToolByName(self.context, "plone_utils")
        msg = translate(
            _(
                u"you added ${count} files success.",
                default="You added ${count} files success.",
                mapping={u"count": len(files)},
            ),
            context=self.request,
        )
        plone_utils.addPortalMessage(msg, "info")

        # back to the folder
        self.request.response.redirect(self.context.absolute_url())