コード例 #1
0
ファイル: kssview.py プロジェクト: austgl/everydo-project
    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
コード例 #2
0
ファイル: kssview.py プロジェクト: austgl/everydo-project
    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()
コード例 #3
0
def sendNotification(self, msg):
    sm = ISubscriptionManager(msg)

    portal_url = getToolByName(msg, 'portal_url')
    portal = portal_url.getPortalObject()
    subject = '[%s] %s' % (portal.Title(), msg.Title())

    mtool = getToolByName(msg, 'portal_membership')
    member = mtool.getAuthenticatedMember()
    fullname = member.getProperty('fullname')
    email = member.getProperty('email')

    body = translate(_(
        u'mail_body',
        default=
        'A file submitted. DO NOT REPLY TO THIS EMAIL.\n\nSubmitted by ${user_name} <${user_email}>: \n\nFile: ${filename}\nDownload: ${file_url}\n\n${description}',
        mapping={
            u'file_url': msg.absolute_url() + '/@@file_view',
            u'user_name': fullname or member.getId(),
            u'user_email': email,
            u'filename': msg.Title(),
            u'description': msg.Description()
        }),
                     context=self.request)
    sm.sendMail(subject=subject, body=body, includeme=True)
コード例 #4
0
def sendNotification(self, obj):
    sm = ISubscriptionManager(obj)

    portal_url = getToolByName(obj, 'portal_url')
    project = obj.getProject()
    company = project.getCompany()

    subject = '[%s] %s' % (project.Title(), obj.Title())

    mtool = getToolByName(obj, 'portal_membership')
    member = mtool.getAuthenticatedMember()
    fullname = member.getProperty('fullname')
    email = member.getProperty('email')
    body = translate(_(
        u'body_email',
        default=
        '${user_name} <${user_email}> invitation you view ${obj_title}. \n\nVisit URL:  ${obj_url} \n \n--\nDO NOT REPLY TO THIS EMAIL.\nTo comment on this content, visit: \n${obj_url}',
        mapping={
            u'obj_url': obj.absolute_url(),
            u'user_name': fullname or member.getId(),
            u'user_email': email,
            u'obj_title': obj.Title()
        }),
                     context=self.request)

    sm.sendMail(subject=subject, body=body, includeme=True)
コード例 #5
0
def sendNotification(self, msg):
    sm = ISubscriptionManager(msg)

    portal_url = getToolByName(msg, "portal_url")
    portal = portal_url.getPortalObject()
    subject = "[%s] %s" % (portal.Title(), msg.Title())

    mtool = getToolByName(msg, "portal_membership")
    member = mtool.getAuthenticatedMember()
    fullname = member.getProperty("fullname")
    email = member.getProperty("email")

    body = translate(
        _(
            u"mail_body",
            default="A file submitted. DO NOT REPLY TO THIS EMAIL.\n\nSubmitted by ${user_name} <${user_email}>: \n\nFile: ${filename}\nDownload: ${file_url}\n\n${description}",
            mapping={
                u"file_url": msg.absolute_url() + "/@@file_view",
                u"user_name": fullname or member.getId(),
                u"user_email": email,
                u"filename": msg.Title(),
                u"description": msg.Description(),
            },
        ),
        context=self.request,
    )
    sm.sendMail(subject=subject, body=body, includeme=True)
コード例 #6
0
def sendNotification(self, msg):
        sm = ISubscriptionManager(msg)

        portal_url = getToolByName(msg, 'portal_url')
        project = msg.getProject()
        company =project.getCompany()

        # attachments in msg
        attachments_msg = ''
        attachments = msg.getAttachedImagesAndFiles()
        image_urls = [img.absolute_url() for img in attachments[0]]
        file_urls = [file.absolute_url() for file in attachments[1]]
        len_attachments = len(image_urls + file_urls)

        if image_urls or file_urls:
            attachments_msg = translate(_(u'attachment_msg_msg', default='This message contains ${len_attachments} attachment(s):\n ', mapping={u'len_attachments':len_attachments}), context=self.request)
            for url in (image_urls + file_urls):
                url = url + '\n'
                attachments_msg+=url

        subject = '[%s] %s' % (project.Title(), msg.Title())

        mtool = getToolByName(msg, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        fullname = member.getProperty('fullname')
        email = member.getProperty('email')
        body = translate(_(u'body_email',
                           default='A new message has been posted. DO NOT REPLY TO THIS EMAIL. To comment on this message, visit: \n ${msg_url} \n \n${user_name} <${user_email}> said:\n--------------------------------------------------------------- \n${msg_body} \n${attachments} \n \n--\nDO NOT REPLY TO THIS EMAIL.\nTo comment on this message, visit: \n${msg_url}',
            mapping={u'msg_url':msg.absolute_url(),
                     u'user_name':fullname or member.getId(),
                     u'user_email':email,
                     u'msg_body':msg.getRawText(),
                     u'attachments':attachments_msg}),context=self.request)

        sm.sendMail(subject=subject, body=body, includeme=True)
コード例 #7
0
    def unsubscribeAuthenticatedMember(self):
        sm = ISubscriptionManager(self.context)
        sm.unsubscribeAuthenticatedMember()

        core = self.getCommandSet("core")
        core.replaceInnerHTML("#subscription", self.column_two())

        return self.render()
コード例 #8
0
ファイル: kssview.py プロジェクト: austgl/everydo-project
    def unsubscribeAuthenticatedMember(self):
        sm = ISubscriptionManager(self.context)
        sm.unsubscribeAuthenticatedMember()

        core = self.getCommandSet("core")
        core.replaceInnerHTML("#subscription", self.column_two())

        return self.render()
コード例 #9
0
    def getSubscribedMembers(self):

        sm = ISubscriptionManager(self.context)
        subscribers = sm.getSubscribedMembers()

        project = self.context.getProject()
        adapter = IOrganizedEmployess(project.teams)

        return adapter.caculateCompanyPeople(subscribers)
コード例 #10
0
    def getSubscribedMembers(self):

        sm = ISubscriptionManager(self.context)
        subscribers = sm.getSubscribedMembers()

        project = self.context.getProject()
        adapter = IOrganizedEmployess(project.teams)

        return adapter.caculateCompanyPeople(subscribers)
コード例 #11
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())
コード例 #12
0
ファイル: kssview.py プロジェクト: austgl/everydo-project
def sendNotification(self, obj):
        sm = ISubscriptionManager(obj)

        portal_url = getToolByName(obj, 'portal_url')
        project = obj.getProject()
        company =project.getCompany()

        subject = '[%s] %s' % (project.Title(), obj.Title())

        mtool = getToolByName(obj, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        fullname = member.getProperty('fullname')
        email = member.getProperty('email')
        body = translate(_(u'body_email', default='${user_name} <${user_email}> invitation you view ${obj_title}. \n\nVisit URL:  ${obj_url} \n \n--\nDO NOT REPLY TO THIS EMAIL.\nTo comment on this content, visit: \n${obj_url}',
            mapping={u'obj_url':obj.absolute_url(),
                     u'user_name':fullname or member.getId(),
                     u'user_email':email,
                     u'obj_title':obj.Title()}),context=self.request)

        sm.sendMail(subject=subject, body=body, includeme=True)
コード例 #13
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()
コード例 #14
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())
コード例 #15
0
ファイル: writeboard.py プロジェクト: austgl/everydo-project
    def createWriteboard(self, title, category, description, text_format='', private=False):
        category_folder = getattr(self.context.aq_inner, category)
        id = str(random.randrange(100000, 999999))
        while id in category_folder.objectIds():
            id = str(random.randrange(100000, 999999))

        category_folder.invokeFactory('Document', id)

        doc = getattr(category_folder, id)
        doc.setTitle(title)
        doc.setDescription(description)
        if text_format:
            doc.setContentType(text_format)
        if private:
            wftool = getToolByName(self.context, 'portal_workflow')
            wftool.doActionFor(doc, 'hide')
        doc.unmarkCreationFlag()
        doc.reindexObject()

        notify(WriteboardCreatedEvent(doc))
        sm = ISubscriptionManager(doc)
        sm.subscribeAuthenticatedMember()

        self.request.response.redirect(doc.absolute_url()+'?edit=true')
コード例 #16
0
    def _addComment(self, text, attaches=[]):
        cm = ICommentsManager(self.context)
        comment = cm.addComment(text, attaches)

        # send notifications
        msg = self.context.aq_inner
        type_name = msg.portal_type
        sm = ISubscriptionManager(msg)

        portal_url = getToolByName(msg, 'portal_url')

        project = msg.getProject()
        company = project.getCompany()

        # attachments in msg
        attachments_msg = ''
        attachments = self.attachable() and comment.getCommentAttaches() or [(), ()]
        image_urls = [img.absolute_url() for img in attachments[0]]
        file_urls = [file.absolute_url() for file in attachments[1]]
        len_attachments = len(image_urls + file_urls)

        if image_urls or file_urls:
            attachments_msg = translate(_(u'attachments_msg',
                                        default='This comment contains ${len_attachments} attachment(s): \n ',
                                        mapping={u'len_attachments':len_attachments}),
                                        context=self.request) 
            for url in (image_urls + file_urls):
                url = url + '/@@file_view' + '\n'
                attachments_msg+=url

        subject = '[%s] %s' % (project.Title(), comment.Title())

        mtool = getToolByName(msg, 'portal_membership')
        member = mtool.getAuthenticatedMember()
        fullname = member.getProperty('fullname')
        email = member.getProperty('email')

        if type_name in ['Image', 'File']:
            bc_url = '%s/@@file_view' % msg.absolute_url()
        else:
            bc_url = msg.absolute_url()


        body = translate(_(u'mail_body',
                        default='${project_name} of the ${company_name} have a new comment posted. DO NOT REPLY TO THIS EMAIL. To comment on this message, visit:\n${msg_url}\n\n${user_name} <${user_email}> said:\n--------------------------------------------------------------------------\n${msg_body}\n\n${attachments}\n\n--\nDO NOT REPLY TO THIS EMAIL.\nTo comment on this message, visit:\n${msg_url}', 
                        mapping={u'company_name':company.Title(),
                               u'project_name':project.Title(),
                               u'msg_url':bc_url,
                               u'user_name':fullname or member.getId(),
                               u'user_email':email,
                               u'msg_body':text,
                               u'attachments':attachments_msg}),
                        context=self.request)
        sm.sendMail(subject=subject, body=body)
        sm.subscribeAuthenticatedMember()
        return comment
コード例 #17
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
コード例 #18
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())
コード例 #19
0
 def hasSubscriptionForAuthenticatedMember(self):
     sm = ISubscriptionManager(self.context)
     return sm.hasSubscriptionForAuthenticatedMember()
コード例 #20
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())
コード例 #21
0
 def hasSubscriptionForAuthenticatedMember(self):
     sm = ISubscriptionManager(self.context)
     return sm.hasSubscriptionForAuthenticatedMember()
コード例 #22
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())
コード例 #23
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())
コード例 #24
0
ファイル: comments.py プロジェクト: xiaoyanit/everydo-project
    def _addComment(self, text, attaches=[]):
        cm = ICommentsManager(self.context)
        comment = cm.addComment(text, attaches)

        # send notifications
        msg = self.context.aq_inner
        type_name = msg.portal_type
        sm = ISubscriptionManager(msg)

        portal_url = getToolByName(msg, "portal_url")

        project = msg.getProject()
        company = project.getCompany()

        # attachments in msg
        attachments_msg = ""
        attachments = self.attachable() and comment.getCommentAttaches() or [(), ()]
        image_urls = [img.absolute_url() for img in attachments[0]]
        file_urls = [file.absolute_url() for file in attachments[1]]
        len_attachments = len(image_urls + file_urls)

        if image_urls or file_urls:
            attachments_msg = translate(
                _(
                    u"attachments_msg",
                    default="This comment contains ${len_attachments} attachment(s): \n ",
                    mapping={u"len_attachments": len_attachments},
                ),
                context=self.request,
            )
            for url in image_urls + file_urls:
                url = url + "/@@file_view" + "\n"
                attachments_msg += url

        subject = "[%s] %s" % (project.Title(), comment.Title())

        mtool = getToolByName(msg, "portal_membership")
        member = mtool.getAuthenticatedMember()
        fullname = member.getProperty("fullname")
        email = member.getProperty("email")

        if type_name in ["Image", "File"]:
            bc_url = "%s/@@file_view" % msg.absolute_url()
        else:
            bc_url = msg.absolute_url()

        body = translate(
            _(
                u"mail_body",
                default="${project_name} of the ${company_name} have a new comment posted. DO NOT REPLY TO THIS EMAIL. To comment on this message, visit:\n${msg_url}\n\n${user_name} <${user_email}> said:\n--------------------------------------------------------------------------\n${msg_body}\n\n${attachments}\n\n--\nDO NOT REPLY TO THIS EMAIL.\nTo comment on this message, visit:\n${msg_url}",
                mapping={
                    u"company_name": company.Title(),
                    u"project_name": project.Title(),
                    u"msg_url": bc_url,
                    u"user_name": fullname or member.getId(),
                    u"user_email": email,
                    u"msg_body": text,
                    u"attachments": attachments_msg,
                },
            ),
            context=self.request,
        )
        sm.sendMail(subject=subject, body=body)
        sm.subscribeAuthenticatedMember()
        return comment
コード例 #25
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())
コード例 #26
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())