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())
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())
def changeCategory(self, value): fileObj = self.context.aq_inner category = fileObj.aq_parent filerepos = category.aq_parent if category.getId() != value: cat_m = ICategoryManager(filerepos) fileObj = cat_m.setContentCategory(fileObj, value) the_macro = self.filerepos_listing.macros["fileitem"] wtool = getToolByName(self.context, "portal_workflow") review_state = wtool.getInfoFor(fileObj, "review_state", "") content = self.header_macros(the_macro=the_macro, obj=fileObj, review_state=review_state, canEdit=1) content = force_unicode(content, "utf") ksscore = self.getCommandSet("core") file_id = "#file_%s" % fileObj.UID() ksscore.replaceHTML(file_id, content)
def changeCategory(self, value): fileObj = self.context.aq_inner category = fileObj.aq_parent filerepos = category.aq_parent if category.getId() != value: cat_m = ICategoryManager(filerepos) fileObj = cat_m.setContentCategory(fileObj, value) the_macro = self.filerepos_listing.macros['fileitem'] wtool = getToolByName(self.context, 'portal_workflow') review_state = wtool.getInfoFor(fileObj, 'review_state', '') content = self.header_macros(the_macro=the_macro, obj=fileObj, review_state=review_state, canEdit=1) content = force_unicode(content, 'utf') ksscore = self.getCommandSet('core') file_id = '#file_%s' % fileObj.UID() ksscore.replaceHTML(file_id, content)
def _createChatLog(self): wftool = getToolByName(self, 'portal_workflow') isPrivate = wftool.getInfoFor(self, 'review_state') == 'private' project = self.getProject() files = project.files.aq_inner if not hasattr(files, 'chatlogs'): cm = ICategoryManager(files) cm.addCategory('chatlogs', '讨论记录') id = self.generateUniqueId() + '.log' files.chatlogs.invokeFactory('ChatLog', id) chatlog = getattr(files.chatlogs, id) # self.setRelatedItems([chatlog]) if isPrivate: wftool.doActionFor(chatlog, 'hide') self.reindexObject(['getRawRealtedItems']) return chatlog
def _createChatLog(self): wftool = getToolByName(self, 'portal_workflow') isPrivate = wftool.getInfoFor(self, 'review_state') == 'private' project = self.getProject() files = project.files.aq_inner if not hasattr(files, 'chatlogs'): cm = ICategoryManager(files) cm.addCategory('chatlogs', '讨论记录') id = self.generateUniqueId() + '.log' files.chatlogs.invokeFactory('ChatLog', id) chatlog = getattr(files.chatlogs, id) # self.setRelatedItems([chatlog]) if isPrivate: wftool.doActionFor(chatlog, 'hide') self.reindexObject(['getRawRealtedItems']) return chatlog
def categoryTitle(self): category = self.request.get('category', '') return category and ICategoryManager( self.context).getCategoryTitle(category)
def canAdd(self): context = self.context.aq_inner.aq_parent.files # 只有自文件夹可以添加,才显示 return ICategoryManager(context).getCategories(addable=True)
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())
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())
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())