def inspectContentObject(self): """ Display detailed information about the current content object """ logger.debug("in inspectViewlet") context_state = getMultiAdapter((self.context, self.request), name=u'plone_context_state') template = ViewPageTemplateFile('panel_inspect_content_object.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = template.__of__(self) out = template(contentObject = self.context, parent = context_state.parent(), skinName = self.context.getCurrentSkinName(), templateName = context_state.view_template_id() ) # Dump the output to the inspector panel self.updatePanelBodyContent(out) # Highlight the element ksscore = self.getCommandSet('core') self.highlightElement(ksscore.getCssSelector('#glowormPageWrapper')) # And in the nav tree (Should this be here or in the nav tree viewlet code?) self.highlightInNavTree(ksscore.getCssSelector('#glowormPanelNavTree .inspectContentObject')) return self.render()
def showMoveViewletForm(self, viewlethash): """ Show the form for moving a viewlet between managers. """ unhashedViewletInfo = unhashViewletInfo(viewlethash) reg = findTemplateViewRegistrationFromHash(viewlethash) viewRegistrationInfo = list(registration.templateViewRegistrationInfos([reg]))[0] managerName = unhashedViewletInfo['managerName'] managerNames = self._getAllViewletManagerNames() managerNames.sort() # Remove the viewlet's current viewlet manager and the gloworm panel from the choices. managerNames.remove(unhashedViewletInfo['managerName']) managerNames.remove('gloworm.glowormPanel') template = ViewPageTemplateFile('panel_move_viewlet.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = template.__of__(self) out = template(viewlethash=viewlethash, viewletName = unhashedViewletInfo['viewletName'], managerNames = managerNames) # Dump the output to the inspector panel self.updatePanelBodyContent(out) return self.render()
def inspectField(self, fieldname): """ Display detailed information about one of current content object's fields """ field = self.context.getField(fieldname) template = ViewPageTemplateFile('panel_inspect_field.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = template.__of__(self) out = template(fieldName = fieldname, type = field.type, widget = type(field.widget).__name__, accessor = field.accessor, mutator = field.mutator, readPermission = field.read_permission, writePermission = field.write_permission ) # Dump the output to the inspector panel self.updatePanelBodyContent(out) # Highlight the element ksscore = self.getCommandSet('core') self.highlightElement(ksscore.getCssSelector('.kssattr-atfieldname-%s' % fieldname)) return self.render()
def inspectViewlet(self, viewlethash): """ Display detailed information about a particular viewlet. """ logger.debug("in inspectViewlet") # Unhash the viewlet info unhashedViewletInfo = unhashViewletInfo(viewlethash) # Get the registration information for this viewlet reg = findTemplateViewRegistrationFromHash(viewlethash) viewName = unhashedViewletInfo['viewletName'] managerName = unhashedViewletInfo['managerName'] cls = registration.getViewClassFromRegistration(reg) className = "%s.%s" % (cls.__module__, cls.__name__) try: viewRegistrationInfo = list(registration.templateViewRegistrationInfos([reg]))[0] except IndexError: # For some reason, there's no registration with portal_view_cusomtizations, # this appears to happen when there's no template defined for the viewlet and it instead # uses a "render" method. customizationExists = False customizationAllowed = False templatePath = "" else: template = viewRegistrationInfo['zptfile'] templatePath = registration.generateIdFromRegistration(reg) container = queryUtility(IViewTemplateContainer) customizationExists = templatePath in container customizationAllowed = True # Get the names of the hidden viewlets storage = getUtility(IViewletSettingsStorage) hiddenViewlets = frozenset(storage.getHidden(managerName, self.context.getCurrentSkinName())) isVisible = viewName not in hiddenViewlets template = ViewPageTemplateFile('panel_inspect_viewlet.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = template.__of__(self) out = template(viewName = viewName, managerName = managerName, template = template, className = className, templatePath = templatePath, customizationExists = customizationExists, customizationAllowed = customizationAllowed, visible = isVisible, viewletHash = viewlethash) # Dump the output to the output panel self.updatePanelBodyContent(out) # Highlight this element ksscore = self.getCommandSet('core') self.highlightElement(ksscore.getCssSelector('.kssattr-viewlethash-%s' % viewlethash)) # And in the nav tree (Should this be here or in the nav tree viewlet code?) self.highlightInNavTree(ksscore.getCssSelector('#glowormPanelNavTree .kssattr-forviewlet-%s' % viewlethash)) return self.render()
def customizeViewlet(self, viewlethash): """ Display an edit form for modifiying a viewlet's template """ logger.debug("in customizeViewlet") # Unhash the viewlet info unhashedViewletInfo = unhashViewletInfo(viewlethash) # Get the viewlet's registration information from portal_view_customizations container = queryUtility(IViewTemplateContainer) reg = findTemplateViewRegistrationFromHash(viewlethash) regInfo = list(registration.templateViewRegistrationInfos([reg]))[0] # TODO We should be looking at regInfo['customized'] to determine whether or not a customization exists. # It never seems to have a value though... check on this. templateName = registration.generateIdFromRegistration(reg) # Check to see if the viewlet has already been customized. Get the template code accordingly. if templateName not in container.objectIds(): viewzpt = registration.customizeTemplate(reg) sm = getSiteManager(self.context) sm.registerAdapter(viewzpt, required= reg.required, provided = reg.provided, name=reg.name) else: viewzpt = container[templateName] templateCode = viewzpt.read() template = ViewPageTemplateFile('panel_customize_viewlet.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = template.__of__(self) out = template(templateURL = viewzpt.absolute_url(), viewletHash = viewlethash, templateCode = templateCode) # Dump the output to the output panel self.updatePanelBodyContent(out) # Force a resize update of the panel so that the form elements are sized to the dimensions of the panel. kssglo = self.getCommandSet('gloWorm') kssglo.forceGlowormPanelResize() return self.render()
def fetchcomments(self, uid, itemindex, lasttimestamp, commentcount, lastcommentid, viewtype): query = {'UID': uid} pdt = getToolByName(self.context, 'portal_discussion', None) cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) if len(resbrains) == 1: zopecommands = self.getCommandSet('zope') ksscore = self.getCommandSet('core') jq = self.getCommandSet('jquery') listcommentcontainer = ksscore.getHtmlIdSelector( 'comcynapselistcommentscontainer' + itemindex) listcountspan = ksscore.getHtmlIdSelector('commentcountspan' + itemindex) nocommentsyet = ksscore.getCssSelector('.nocommentsyet') listtimeoutuid = ksscore.getHtmlIdSelector( 'comcynapsecyninfetchUID') listtimeoutindex = ksscore.getHtmlIdSelector( 'comcynapsecyninfetchindex') listtimeouttimestamp = ksscore.getHtmlIdSelector( 'comcynapselasttimestamp') listtimeoutlastcommentid = ksscore.getHtmlIdSelector( 'comcynapselastcommentid') listtimeoutcommentcount = ksscore.getHtmlIdSelector( 'comcynapsecommentcount') listcommentscount = ksscore.getHtmlIdSelector( 'listdiscussioncount' + itemindex) contobj = resbrains[0].getObject() isDiscussable = contobj.isDiscussable() canReply = self.canreply(contobj) if isDiscussable and canReply: passedcommentcount = 0 passedcommentcount = int(commentcount) flasttimestamp = float(lasttimestamp) datefromlasttimestamp = DateTime(flasttimestamp) newlastdate = datefromlasttimestamp.timeTime() disc_container = pdt.getDiscussionFor(contobj) newreplycount = disc_container.replyCount(contobj) allreplies = self.get_replies(pdt, contobj) if passedcommentcount <> newreplycount: alldiscussions = disc_container.objectValues() newlastcommentid = lastcommentid newlyaddedcomments = [ k for k in alldiscussions if k.modified().greaterThan(datefromlasttimestamp) and k.id not in (lastcommentid) ] newlyaddedcomments.sort( lambda x, y: cmp(x.modified(), y.modified())) lenofnewcomments = len(newlyaddedcomments) display_count = self.get_displaycountforlist() lastxdiscussions = [] if lenofnewcomments >= display_count: newlyaddedcomments.sort( lambda x, y: cmp(x.modified(), y.modified()), reverse=True) lastxdiscussions = newlyaddedcomments[:display_count] lastxdiscussions.sort( lambda x, y: cmp(x.modified(), y.modified())) ksscore.clearChildNodes(listcommentcontainer) else: lastxdiscussions = newlyaddedcomments if lenofnewcomments > 0 and len( alldiscussions) > display_count: alldiscussions.sort( lambda x, y: cmp(x.modified(), y.modified()), reverse=True) marker_discussion = alldiscussions[display_count - 1:display_count] if len(marker_discussion) > 0: #delete nodes before this item marker_node = ksscore.getHtmlIdSelector( 'commenttable' + marker_discussion[0].id) ksscore.deleteNodeBefore(marker_node) complete_output = '' list_reply_ids = [] for eachcomment in lastxdiscussions: reply = disc_container.getReply(eachcomment.id) if reply <> None: parentsInThread = reply.parentsInThread() depthvalue = 0 if viewtype.lower() == 'threadedview': lenofparents = len(parentsInThread) depthvalue = lenofparents - 1 prev_reply_id = self.findpreviouscommentid( allreplies, reply) newlastdate = reply.modified().timeTime() newlastcommentid = reply.id commenttemplate = ViewPageTemplateFile( 'ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__( self.context) replydict = [ { 'depth': depthvalue, 'object': reply, 'prev_id': prev_reply_id, 'view_type': viewtype, 'showoutput': False }, ] output = commenttemplate.render( reply_dict=replydict, allowdiscussion=isDiscussable, usercanreply=canReply) list_reply_ids.append(reply.id) complete_output += output if complete_output <> '' and len(lastxdiscussions) > 0: ksscore.insertHTMLAsLastChild(listcommentcontainer, complete_output) for erid in list_reply_ids: newcomment = ksscore.getHtmlIdSelector( 'commenttable' + erid) jq.serverEffect(newcomment, "fadeIn", "slow") ksscore.setAttribute(listtimeoutuid, 'value', uid) ksscore.setAttribute(listtimeoutindex, 'value', itemindex) ksscore.setAttribute(listtimeouttimestamp, 'value', str(newlastdate)) ksscore.setAttribute(listtimeoutlastcommentid, 'value', newlastcommentid) ksscore.setAttribute(listtimeoutcommentcount, 'value', str(newreplycount)) ksscore.setAttribute(listtimeoutuid, 'value', uid) if newreplycount > display_count: xmorecomments = newreplycount - display_count ksscore.replaceInnerHTML(listcommentscount, str(xmorecomments)) jq.serverEffect(nocommentsyet, "fadeOut", "fast") jq.serverEffect(listcountspan, "fadeIn", "slow") elif newreplycount > 0 and newreplycount <= display_count: jq.serverEffect(nocommentsyet, "fadeOut", "fast") jq.serverCall(listcommentcontainer, 'truncatetextonitemexpand')
def getDiscussionView(self, uid, itemindex, state, openeditemindex): ksscore = self.getCommandSet('core') zopecore = self.getCommandSet('zope') jq = self.getCommandSet('jquery') clickednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' + itemindex) listcommentcontainer = ksscore.getHtmlIdSelector('listitemdiscussrow' + itemindex) listtimeoutuid = ksscore.getHtmlIdSelector('comcynapsecyninfetchUID') listtimeoutindex = ksscore.getHtmlIdSelector( 'comcynapsecyninfetchindex') listtimeouttimestamp = ksscore.getHtmlIdSelector( 'comcynapselasttimestamp') listtimeoutlastcommentid = ksscore.getHtmlIdSelector( 'comcynapselastcommentid') listtimeoutcommentcount = ksscore.getHtmlIdSelector( 'comcynapsecommentcount') listitemdetailright = ksscore.getHtmlIdSelector('listitemdetail' + itemindex) if openeditemindex != itemindex: openednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' + openeditemindex) listopenedcommentcontainer = ksscore.getHtmlIdSelector( 'listitemdiscussrow' + openeditemindex) ksscore.setKssAttribute(openednode, 'state', 'closed') ksscore.replaceInnerHTML(listopenedcommentcontainer, '') if state.lower() != 'closed': ksscore.setKssAttribute(clickednode, 'state', 'closed') ksscore.replaceInnerHTML(listcommentcontainer, '') return query = {'UID': uid} pdt = getToolByName(self.context, 'portal_discussion') cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) if len(resbrains) == 1: contobj = resbrains[0].getObject() isDiscussable = contobj.isDiscussable() canReply = self.canreply(contobj) if isDiscussable and canReply: dobj = pdt.getDiscussionFor(contobj) alldiscussions = dobj.objectValues() alldiscussions.sort( lambda x, y: cmp(x.modified(), y.modified()), reverse=True) maxdispcomments = self.get_displaycountforlist() lastxdiscussions = alldiscussions[:maxdispcomments] commentscount = dobj.replyCount(contobj) if commentscount > maxdispcomments: showxmorelink = True xmorecomments = commentscount - maxdispcomments elif commentscount > 0 and commentscount <= maxdispcomments: showxmorelink = False xmorecomments = 0 else: showxmorelink = True commentscount = 0 xmorecomments = 0 lasttimestamp = DateTime().timeTime() lastcommentid = '0' if len(alldiscussions) > 0: lasttimestamp = alldiscussions[0].modified().timeTime() lastcommentid = alldiscussions[0].id commenttemplate = ViewPageTemplateFile( 'ksstemplates/listcomment.pt') commenttemplate = commenttemplate.__of__(self.context) replydict = [] lastxdiscussions.sort( lambda x, y: cmp(x.modified(), y.modified())) for eachdisc in lastxdiscussions: reply = dobj.getReply(eachdisc.id) if reply <> None: replydict.append({ 'depth': 0, 'object': reply, 'view_type': 'listview', 'showoutput': True }) output = commenttemplate.render(contobj=contobj, showxmorelink=showxmorelink, xmorecomments=xmorecomments, itemindex=itemindex, uid=uid, reply_dict=replydict, title=contobj.Title(), commentcount=commentscount, lasttimestamp=lasttimestamp, lastcommentid=lastcommentid, allowdiscussion=isDiscussable, usercanreply=canReply) detailtemplate = ViewPageTemplateFile( 'ksstemplates/listitemdetails.pt') detailtemplate = detailtemplate.__of__(self.context) item = resbrains[0] fullpath = item.getPath() splitpath = fullpath.split('/')[:-1] prettypath = '/' + '/'.join(splitpath) URLsuffix = getListingTemplateForContextParent(item) pathlink = self.context.portal_url( ) + prettypath + '/' + URLsuffix pathtitle = prettypath detail = detailtemplate.render( item_type=contobj.portal_type, portal_url=self.context.portal_url(), item_type_title=contobj.Type(), item=item, pathlink=pathlink, pathtitle=pathtitle, contobj=contobj) ksscore.replaceInnerHTML(listitemdetailright, force_unicode(detail, 'utf')) ksscore.replaceInnerHTML(listcommentcontainer, output) ksscore.setKssAttribute(clickednode, 'state', 'opened') ksscore.setAttribute(listtimeoutuid, 'value', uid) ksscore.setAttribute(listtimeoutindex, 'value', itemindex) ksscore.setAttribute(listtimeouttimestamp, 'value', str(lasttimestamp)) ksscore.setAttribute(listtimeoutlastcommentid, 'value', lastcommentid) ksscore.setAttribute(listtimeoutcommentcount, 'value', str(commentscount)) jq.serverCall(clickednode, 'truncatetextonitemexpand') jq.serverCall(clickednode, 'marklistedtags') jq.serverCall(listcommentcontainer, 'activateinputlabel')
def fetchnewcomments(self,lasttimestamp,commentcount,lastcommentid,viewtype): passedcommentcount = 0 passedcommentcount = int(commentcount) flasttimestamp = float(lasttimestamp) datefromlasttimestamp = DateTime(flasttimestamp) newlastdate = datefromlasttimestamp.timeTime() zopecommands = self.getCommandSet('zope') ksscore = self.getCommandSet('core') jq = self.getCommandSet('jquery') pdt = getToolByName(self.context, 'portal_discussion', None) if pdt <> None: allreplies = self.get_replies(pdt,self.context) disc_container = pdt.getDiscussionFor(self.context) replies = disc_container.getReplies() newreplycount = disc_container.replyCount(self.context) commentshiddencontainer = ksscore.getHtmlIdSelector('comcynapsehiddencomments') commentscontainer = ksscore.getHtmlIdSelector('comcynapsecyninitemcommentscontainer') addnewlasttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp') addnewlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid') addnewcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount') if passedcommentcount <> newreplycount: #if comment count mismatch then only modify the stuff alldiscussions = disc_container.objectValues() newlyaddedcomments = [k for k in alldiscussions if k.modified().greaterThan(datefromlasttimestamp) and k.id not in (lastcommentid)] newlyaddedcomments.sort(lambda x,y:cmp(x.modified(),y.modified())) for eachcomment in newlyaddedcomments: reply = disc_container.getReply(eachcomment.id) if reply <> None: parentsInThread = reply.parentsInThread() depthvalue = 0 if viewtype.lower() == 'threadedview': lenofparents = len(parentsInThread) depthvalue = lenofparents - 1 prev_reply_id = self.findpreviouscommentid(allreplies,reply) newlastdate = reply.modified().timeTime() commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__(self.context) replydict = [{'depth': depthvalue, 'object': reply,'prev_id':prev_reply_id,'view_type':viewtype},] output = commenttemplate.render(reply_dict=replydict) #delete the node if already exists old_comment = ksscore.getHtmlIdSelector('commenttable' + reply.id) ksscore.deleteNode(old_comment) #if there is no prev id found for new comment then insert it as last item to commentscontainer #else insert it after prev id comments table. if viewtype == 'flatview': ksscore.insertHTMLAsLastChild(commentscontainer,output) else: if prev_reply_id == '': ksscore.insertHTMLAsLastChild(commentscontainer,output) else: prevcommentcontainer = ksscore.getHtmlIdSelector('commenttable' + prev_reply_id) ksscore.insertHTMLAfter(prevcommentcontainer,output) newcomment = ksscore.getHtmlIdSelector('commenttable' + reply.id) if len(newlyaddedcomments) > 0: strlastcommentid = str(newlyaddedcomments[-1].id) ksscore.setKssAttribute(commentshiddencontainer,'lastcommentid',strlastcommentid) ksscore.setAttribute(addnewlastcommentid,'value',strlastcommentid) jq.serverCall(commentscontainer,'truncatetextonitemexpand') newlasttimestamp = str(newlastdate) strcommentcount = str(newreplycount) ksscore.setKssAttribute(commentshiddencontainer,'lasttimestamp',newlasttimestamp) ksscore.setKssAttribute(commentshiddencontainer,'commentcount',strcommentcount) ksscore.setAttribute(addnewlasttimestamp,'value',newlasttimestamp) ksscore.setAttribute(addnewcommentcount,'value',strcommentcount) itemcountcommentcount = ksscore.getHtmlIdSelector('itemcountcommentcount') discussionlabel = ksscore.getHtmlIdSelector('discussionlabel') ksscore.replaceInnerHTML(discussionlabel,strcommentcount) ksscore.replaceInnerHTML(itemcountcommentcount,strcommentcount)
def fetchnewcomments(self, lasttimestamp, commentcount, lastcommentid, viewtype): passedcommentcount = 0 passedcommentcount = int(commentcount) flasttimestamp = float(lasttimestamp) datefromlasttimestamp = DateTime(flasttimestamp) newlastdate = datefromlasttimestamp.timeTime() zopecommands = self.getCommandSet('zope') ksscore = self.getCommandSet('core') jq = self.getCommandSet('jquery') pdt = getToolByName(self.context, 'portal_discussion', None) if pdt <> None: allreplies = self.get_replies(pdt, self.context) disc_container = pdt.getDiscussionFor(self.context) replies = disc_container.getReplies() newreplycount = disc_container.replyCount(self.context) commentshiddencontainer = ksscore.getHtmlIdSelector( 'comcynapsehiddencomments') commentscontainer = ksscore.getHtmlIdSelector( 'comcynapsecyninitemcommentscontainer') addnewlasttimestamp = ksscore.getHtmlIdSelector( 'comcynapselasttimestamp') addnewlastcommentid = ksscore.getHtmlIdSelector( 'comcynapselastcommentid') addnewcommentcount = ksscore.getHtmlIdSelector( 'comcynapsecommentcount') if passedcommentcount <> newreplycount: #if comment count mismatch then only modify the stuff alldiscussions = disc_container.objectValues() newlyaddedcomments = [ k for k in alldiscussions if k.modified().greaterThan(datefromlasttimestamp) and k.id not in (lastcommentid) ] newlyaddedcomments.sort( lambda x, y: cmp(x.modified(), y.modified())) for eachcomment in newlyaddedcomments: reply = disc_container.getReply(eachcomment.id) if reply <> None: parentsInThread = reply.parentsInThread() depthvalue = 0 if viewtype.lower() == 'threadedview': lenofparents = len(parentsInThread) depthvalue = lenofparents - 1 prev_reply_id = self.findpreviouscommentid( allreplies, reply) newlastdate = reply.modified().timeTime() commenttemplate = ViewPageTemplateFile( 'ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__(self.context) replydict = [ { 'depth': depthvalue, 'object': reply, 'prev_id': prev_reply_id, 'view_type': viewtype }, ] output = commenttemplate.render(reply_dict=replydict) #delete the node if already exists old_comment = ksscore.getHtmlIdSelector( 'commenttable' + reply.id) ksscore.deleteNode(old_comment) #if there is no prev id found for new comment then insert it as last item to commentscontainer #else insert it after prev id comments table. if viewtype == 'flatview': ksscore.insertHTMLAsLastChild( commentscontainer, output) else: if prev_reply_id == '': ksscore.insertHTMLAsLastChild( commentscontainer, output) else: prevcommentcontainer = ksscore.getHtmlIdSelector( 'commenttable' + prev_reply_id) ksscore.insertHTMLAfter( prevcommentcontainer, output) newcomment = ksscore.getHtmlIdSelector('commenttable' + reply.id) if len(newlyaddedcomments) > 0: strlastcommentid = str(newlyaddedcomments[-1].id) ksscore.setKssAttribute(commentshiddencontainer, 'lastcommentid', strlastcommentid) ksscore.setAttribute(addnewlastcommentid, 'value', strlastcommentid) jq.serverCall(commentscontainer, 'truncatetextonitemexpand') newlasttimestamp = str(newlastdate) strcommentcount = str(newreplycount) ksscore.setKssAttribute(commentshiddencontainer, 'lasttimestamp', newlasttimestamp) ksscore.setKssAttribute(commentshiddencontainer, 'commentcount', strcommentcount) ksscore.setAttribute(addnewlasttimestamp, 'value', newlasttimestamp) ksscore.setAttribute(addnewcommentcount, 'value', strcommentcount) itemcountcommentcount = ksscore.getHtmlIdSelector( 'itemcountcommentcount') discussionlabel = ksscore.getHtmlIdSelector('discussionlabel') ksscore.replaceInnerHTML(discussionlabel, strcommentcount) ksscore.replaceInnerHTML(itemcountcommentcount, strcommentcount)
def replyToComment(self, viewtype, lasttimestamp, commentcount, lastcommentid): query = {'UID': self.request['cont_uid']} pdt = getToolByName(self.context, 'portal_discussion', None) cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) ksscore = self.getCommandSet('core') zopecore = self.getCommandSet('zope') jq = self.getCommandSet('jquery') if len(resbrains) == 1: contobj = resbrains[0].getObject() if contobj.isDiscussable() and self.canreply(contobj): mtool = getToolByName(self.context, 'portal_membership') username = mtool.getAuthenticatedMember().getId() dobj = pdt.getDiscussionFor(contobj) if len(self.request['commentbody'].strip( ' ')) == 0 or self.request['commentbody'].lower( ) == self.request['comcynapsenewcommenttitle'].lower(): comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector( 'comcynapsecommenterror' + self.request['inreplyto']) ksscore.setStyle(comcynapsecommenterrorlabel, 'display', 'block') else: id = dobj.createReply(title="", text=self.request['commentbody'], Creator=username) reply = dobj.getReply(id) reply.cooked_text = convertWebIntelligentPlainTextToHtml( reply.text) replyto = dobj.getReply(self.request['inreplyto']) reply.setReplyTo(replyto) if reply <> None: from ubify.cyninv2theme import triggerAddOnDiscussionItem triggerAddOnDiscussionItem(reply) #################Determine full reply to discussion to get placement peer of current comment view_type = self.request['cviewtype'] replies = [] def getRs(obj, replies, counter): rs = pdt.getDiscussionFor(obj).getReplies() if len(rs) > 0: rs.sort(lambda x, y: cmp( x.modified(), y.modified())) for r in rs: replies.append({ 'depth': counter, 'object': r }) getRs(r, replies, counter=counter + 1) getRs(replyto, replies, 0) if len( replies ) > 1: ##There are more than 1 comments already children of the comment we just replied to, so the current comment can't have been the first reply prevrep = replies[0]['object'] else: prevrep = replyto for rep in replies: if rep['object'].id == reply.id: belowreply = prevrep else: prevrep = rep['object'] mi = mtool.getMemberInfo() commenttemplate = ViewPageTemplateFile( 'ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__(self.context) depthvalue = 0 if view_type == 'threadedview': depthvalue = int(self.request['depth']) + 1 replydict = [ { 'depth': depthvalue, 'object': reply, 'view_type': view_type }, ] output = commenttemplate.render( indent=int(self.request['depth']) + 2, fullname=mi['fullname'], avatarurl=self.context.portal_membership. getPersonalPortrait(username).absolute_url(), creator=username, showreply=self.canreply(self.context), showdelete=getSecurityManager().checkPermission( 'Manage portal', aq_inner(self.context)), commenttime=self.context.toLocalizedTime( reply.created, True), replyid=reply.id, replytitle=reply.Title(), replybody=reply.CookedBody(), replyurl=reply.absolute_url(), reply_dict=replydict) if view_type == 'threadedview': commentscontainer = ksscore.getHtmlIdSelector( 'commenttable' + prevrep.id) ksscore.insertHTMLAfter(commentscontainer, output) else: commentsoutercontainer = ksscore.getHtmlIdSelector( 'comcynapsecyninitemcommentscontainer') ksscore.insertHTMLAsLastChild( commentsoutercontainer, output) taAddNewComment = ksscore.getCssSelector( 'textarea.commentbodyta') ksscore.setAttribute(taAddNewComment, "value", "") itemcountcommentcount = ksscore.getHtmlIdSelector( 'itemcountcommentcount') countofcomments = dobj.replyCount(self.context) discussionlabel = ksscore.getHtmlIdSelector( 'discussionlabel') ksscore.replaceInnerHTML(discussionlabel, str(countofcomments)) ksscore.replaceInnerHTML(itemcountcommentcount, str(countofcomments)) newcomment = ksscore.getHtmlIdSelector('commenttable' + reply.id) frmreply = ksscore.getHtmlIdSelector( 'replyform' + self.request['inreplyto']) ksscore.setStyle(frmreply, 'display', 'none') comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector( 'comcynapsecommenterror' + self.request['inreplyto']) ksscore.setStyle(comcynapsecommenterrorlabel, 'display', 'none') self.fetchnewcomments(lasttimestamp, commentcount, lastcommentid, viewtype)
def fetchcomments(self,uid,itemindex,lasttimestamp,commentcount,lastcommentid,viewtype): query = {'UID':uid} pdt = getToolByName(self.context, 'portal_discussion', None) cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) if len(resbrains) == 1: zopecommands = self.getCommandSet('zope') ksscore = self.getCommandSet('core') jq = self.getCommandSet('jquery') listcommentcontainer = ksscore.getHtmlIdSelector('comcynapselistcommentscontainer' + itemindex) listcountspan = ksscore.getHtmlIdSelector('commentcountspan' + itemindex) nocommentsyet = ksscore.getCssSelector('.nocommentsyet') listtimeoutuid = ksscore.getHtmlIdSelector('comcynapsecyninfetchUID') listtimeoutindex = ksscore.getHtmlIdSelector('comcynapsecyninfetchindex') listtimeouttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp') listtimeoutlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid') listtimeoutcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount') listcommentscount = ksscore.getHtmlIdSelector('listdiscussioncount' + itemindex) contobj = resbrains[0].getObject() isDiscussable = contobj.isDiscussable() canReply = self.canreply(contobj) if isDiscussable and canReply: passedcommentcount = 0 passedcommentcount = int(commentcount) flasttimestamp = float(lasttimestamp) datefromlasttimestamp = DateTime(flasttimestamp) newlastdate = datefromlasttimestamp.timeTime() disc_container = pdt.getDiscussionFor(contobj) newreplycount = disc_container.replyCount(contobj) allreplies = self.get_replies(pdt,contobj) if passedcommentcount <> newreplycount: alldiscussions = disc_container.objectValues() newlastcommentid = lastcommentid newlyaddedcomments = [k for k in alldiscussions if k.modified().greaterThan(datefromlasttimestamp) and k.id not in (lastcommentid)] newlyaddedcomments.sort(lambda x,y:cmp(x.modified(),y.modified())) lenofnewcomments = len(newlyaddedcomments) display_count = self.get_displaycountforlist() lastxdiscussions = [] if lenofnewcomments >= display_count: newlyaddedcomments.sort(lambda x,y:cmp(x.modified(),y.modified()),reverse=True) lastxdiscussions = newlyaddedcomments[:display_count] lastxdiscussions.sort(lambda x,y:cmp(x.modified(),y.modified())) ksscore.clearChildNodes(listcommentcontainer) else: lastxdiscussions = newlyaddedcomments if lenofnewcomments > 0 and len(alldiscussions) > display_count: alldiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()),reverse=True) marker_discussion = alldiscussions[display_count-1: display_count] if len(marker_discussion) > 0: #delete nodes before this item marker_node = ksscore.getHtmlIdSelector('commenttable' + marker_discussion[0].id) ksscore.deleteNodeBefore(marker_node) complete_output = '' list_reply_ids = [] for eachcomment in lastxdiscussions: reply = disc_container.getReply(eachcomment.id) if reply <> None: parentsInThread = reply.parentsInThread() depthvalue = 0 if viewtype.lower() == 'threadedview': lenofparents = len(parentsInThread) depthvalue = lenofparents - 1 prev_reply_id = self.findpreviouscommentid(allreplies,reply) newlastdate = reply.modified().timeTime() newlastcommentid = reply.id commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__(self.context) replydict = [{'depth': depthvalue, 'object': reply,'prev_id':prev_reply_id,'view_type':viewtype, 'showoutput':False},] output = commenttemplate.render(reply_dict=replydict,allowdiscussion = isDiscussable,usercanreply = canReply) list_reply_ids.append(reply.id) complete_output += output if complete_output <> '' and len(lastxdiscussions) > 0: ksscore.insertHTMLAsLastChild(listcommentcontainer,complete_output) for erid in list_reply_ids: newcomment = ksscore.getHtmlIdSelector('commenttable' + erid) jq.serverEffect(newcomment,"fadeIn", "slow") ksscore.setAttribute(listtimeoutuid,'value',uid) ksscore.setAttribute(listtimeoutindex,'value',itemindex) ksscore.setAttribute(listtimeouttimestamp,'value',str(newlastdate)) ksscore.setAttribute(listtimeoutlastcommentid,'value',newlastcommentid) ksscore.setAttribute(listtimeoutcommentcount,'value',str(newreplycount)) ksscore.setAttribute(listtimeoutuid,'value',uid) if newreplycount > display_count: xmorecomments = newreplycount - display_count ksscore.replaceInnerHTML(listcommentscount,str(xmorecomments)) jq.serverEffect(nocommentsyet,"fadeOut", "fast") jq.serverEffect(listcountspan,"fadeIn", "slow") elif newreplycount > 0 and newreplycount <= display_count: jq.serverEffect(nocommentsyet,"fadeOut", "fast") jq.serverCall(listcommentcontainer,'truncatetextonitemexpand')
def getDiscussionView(self,uid,itemindex,state,openeditemindex): ksscore = self.getCommandSet('core') zopecore = self.getCommandSet('zope') jq = self.getCommandSet('jquery') clickednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' + itemindex) listcommentcontainer = ksscore.getHtmlIdSelector('listitemdiscussrow' + itemindex) listtimeoutuid = ksscore.getHtmlIdSelector('comcynapsecyninfetchUID') listtimeoutindex = ksscore.getHtmlIdSelector('comcynapsecyninfetchindex') listtimeouttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp') listtimeoutlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid') listtimeoutcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount') listitemdetailright = ksscore.getHtmlIdSelector('listitemdetail' + itemindex) if openeditemindex != itemindex: openednode = ksscore.getHtmlIdSelector('listitemdiscusslinktop' + openeditemindex) listopenedcommentcontainer = ksscore.getHtmlIdSelector('listitemdiscussrow' + openeditemindex) ksscore.setKssAttribute(openednode,'state','closed') ksscore.replaceInnerHTML(listopenedcommentcontainer,'') if state.lower() != 'closed': ksscore.setKssAttribute(clickednode,'state','closed') ksscore.replaceInnerHTML(listcommentcontainer,'') return query = {'UID':uid} pdt = getToolByName(self.context,'portal_discussion') cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) if len(resbrains) == 1: contobj = resbrains[0].getObject() isDiscussable = contobj.isDiscussable() canReply = self.canreply(contobj) if isDiscussable and canReply: dobj = pdt.getDiscussionFor(contobj) alldiscussions = dobj.objectValues() alldiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()),reverse=True) maxdispcomments = self.get_displaycountforlist() lastxdiscussions = alldiscussions[:maxdispcomments] commentscount = dobj.replyCount(contobj) if commentscount > maxdispcomments: showxmorelink = True xmorecomments = commentscount - maxdispcomments elif commentscount > 0 and commentscount <= maxdispcomments: showxmorelink = False xmorecomments = 0 else: showxmorelink = True commentscount = 0 xmorecomments = 0 lasttimestamp = DateTime().timeTime() lastcommentid = '0' if len(alldiscussions) > 0: lasttimestamp = alldiscussions[0].modified().timeTime() lastcommentid = alldiscussions[0].id commenttemplate = ViewPageTemplateFile('ksstemplates/listcomment.pt') commenttemplate = commenttemplate.__of__(self.context) replydict = [] lastxdiscussions.sort(lambda x,y:cmp(x.modified(),y.modified())) for eachdisc in lastxdiscussions: reply = dobj.getReply(eachdisc.id) if reply <> None: replydict.append({'depth': 0,'object':reply,'view_type':'listview','showoutput':True}) output = commenttemplate.render(contobj=contobj, showxmorelink = showxmorelink, xmorecomments = xmorecomments, itemindex=itemindex,uid=uid,reply_dict=replydict,title=contobj.Title(),commentcount=commentscount,lasttimestamp = lasttimestamp,lastcommentid = lastcommentid,allowdiscussion = isDiscussable,usercanreply = canReply) detailtemplate = ViewPageTemplateFile('ksstemplates/listitemdetails.pt') detailtemplate = detailtemplate.__of__(self.context) item = resbrains[0] fullpath = item.getPath() splitpath = fullpath.split('/')[:-1] prettypath = '/' + '/'.join(splitpath) URLsuffix = getListingTemplateForContextParent(item) pathlink = self.context.portal_url() + prettypath + '/' + URLsuffix pathtitle = prettypath detail = detailtemplate.render(item_type=contobj.portal_type,portal_url=self.context.portal_url(),item_type_title=contobj.Type(),item=item,pathlink=pathlink,pathtitle=pathtitle,contobj=contobj) ksscore.replaceInnerHTML(listitemdetailright,force_unicode(detail,'utf')) ksscore.replaceInnerHTML(listcommentcontainer,output) ksscore.setKssAttribute(clickednode,'state','opened') ksscore.setAttribute(listtimeoutuid,'value',uid) ksscore.setAttribute(listtimeoutindex,'value',itemindex) ksscore.setAttribute(listtimeouttimestamp,'value',str(lasttimestamp)) ksscore.setAttribute(listtimeoutlastcommentid,'value',lastcommentid) ksscore.setAttribute(listtimeoutcommentcount,'value',str(commentscount)) jq.serverCall(clickednode,'truncatetextonitemexpand') jq.serverCall(clickednode,'marklistedtags') jq.serverCall(listcommentcontainer,'activateinputlabel')
def toggleCommentsView(self,viewtype): zopecommands = self.getCommandSet('zope') ksscore = self.getCommandSet('core') jq = self.getCommandSet('jquery') commentshiddencontainer = ksscore.getHtmlIdSelector('comcynapsehiddencomments') commentscontainer = ksscore.getHtmlIdSelector('comcynapsecyninitemcommentscontainer') addnewlasttimestamp = ksscore.getHtmlIdSelector('comcynapselasttimestamp') addnewlastcommentid = ksscore.getHtmlIdSelector('comcynapselastcommentid') addnewcommentcount = ksscore.getHtmlIdSelector('comcynapsecommentcount') objcommentslist = [] pdt = getToolByName(self.context, 'portal_discussion', None) if pdt <> None: disc_container = pdt.getDiscussionFor(self.context) alldiscussions = disc_container.objectValues() allreplies = self.get_replies(pdt,self.context) newreplycount = disc_container.replyCount(self.context) newlastdate = DateTime().timeTime() if viewtype == 'flatview': alldiscussions.sort(lambda x,y:cmp(x.modified(),y.modified())) objcommentslist.extend(alldiscussions) else: objcommentslist.extend(allreplies) ksscore.replaceInnerHTML(commentscontainer,'') complete_output = '' for eachcomment in objcommentslist: if hasattr(eachcomment,'id'): id = eachcomment.id elif eachcomment.has_key('id'): id = eachcomment['id'] reply = disc_container.getReply(id) if reply <> None: parentsInThread = reply.parentsInThread() depthvalue = 0 if viewtype.lower() == 'threadedview': lenofparents = len(parentsInThread) depthvalue = lenofparents - 1 prev_reply_id = self.findpreviouscommentid(allreplies,reply) newlastdate = reply.modified().timeTime() commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__(self.context) replydict = [{'depth': depthvalue, 'object': reply,'prev_id':prev_reply_id,'view_type':viewtype,'showoutput':True},] output = commenttemplate.render(reply_dict=replydict) #if there is no prev id found for new comment then insert it as last item to commentscontainer #else insert it after prev id comments table. if viewtype == 'flatview': complete_output += output else: complete_output += output if complete_output <> '' and len(objcommentslist) > 0: ksscore.replaceInnerHTML(commentscontainer,complete_output) jq.serverCall(commentscontainer,'truncatetextonitemexpand') if len(alldiscussions) > 0: strlastcommentid = str(alldiscussions[-1].id) ksscore.setKssAttribute(commentshiddencontainer,'lastcommentid',strlastcommentid) ksscore.setAttribute(addnewlastcommentid,'value',strlastcommentid) newlasttimestamp = str(newlastdate) strcommentcount = str(newreplycount) ksscore.setKssAttribute(commentshiddencontainer,'lasttimestamp',newlasttimestamp) ksscore.setKssAttribute(commentshiddencontainer,'commentcount',strcommentcount) ksscore.setAttribute(addnewlasttimestamp,'value',newlasttimestamp) ksscore.setAttribute(addnewcommentcount,'value',strcommentcount) itemcountcommentcount = ksscore.getHtmlIdSelector('itemcountcommentcount') discussionlabel = ksscore.getHtmlIdSelector('discussionlabel') ksscore.replaceInnerHTML(discussionlabel,strcommentcount) ksscore.replaceInnerHTML(itemcountcommentcount,strcommentcount) ksscore.setKssAttribute(commentshiddencontainer,'viewtype',viewtype) addnewcommentviewtype = ksscore.getHtmlIdSelector('comcynapseviewtype') ksscore.setAttribute(addnewcommentviewtype,'value',viewtype) ksscore.setStyle(commentscontainer,'display','block')
def inspectElement(self, insideInspectableArea=False, talcontent=None, talattributes=None, talcondition=None, metaldefmacro=None, metalusemacro=None, fieldname=None, portlethash=None, viewlethash=None, sourceAnnotation=None): """ Get details about a particular html element. """ # Make sure we're not clicking inside the inspector div since KSS doesn't seem to provide a # way to block processing of other rules. if insideInspectableArea: logger.debug("in inspectElement") parsedTalAttributes = [] if talattributes: # logger.debug("talattributes: %s" % talattributes) # If there's only one item in the list being returned by the KSS method, # it's passing it as a string instead of a list/array. Not sure why. # Sniff the type and make it a list if needed. if isinstance(talattributes, str): talattributes = [talattributes] for attr in talattributes: # logger.debug("attr: %s" % attr) attribute = {} attribute['name'], attribute['expression'], attribute['result'] = attr.split(',') parsedTalAttributes.append(attribute) unhashedPortletInfo = {} if portlethash: unhashedPortletInfo = unhashPortletInfo(portlethash) unhashedViewletInfo = {} if viewlethash: unhashedViewletInfo = unhashViewletInfo(viewlethash) if sourceAnnotation: sourceAnnotation = sourceAnnotation.strip(' =\n') template = ViewPageTemplateFile('panel_inspect_element.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = template.__of__(self) out = template(metalUseMacro = metalusemacro, metalDefMacro = metaldefmacro, fieldName = fieldname, talContent = talcontent, talAttributes = parsedTalAttributes, talCondition = talcondition, portletInfo = unhashedPortletInfo, viewletInfo = unhashedViewletInfo, sourceAnnotation = sourceAnnotation ) # Dump the output to the inspector panel self.updatePanelBodyContent(out) # Highlight this element ksscore = self.getCommandSet('core') self.highlightElement(ksscore.getSameNodeSelector()) # And in the nav tree (Should this be here or in the nav tree viewlet code?) if viewlethash: self.highlightInNavTree(ksscore.getCssSelector('#glowormPanelNavTree .kssattr-forviewlet-%s' % viewlethash)) return self.render()
def toggleCommentsView(self, viewtype): zopecommands = self.getCommandSet('zope') ksscore = self.getCommandSet('core') jq = self.getCommandSet('jquery') commentshiddencontainer = ksscore.getHtmlIdSelector( 'comcynapsehiddencomments') commentscontainer = ksscore.getHtmlIdSelector( 'comcynapsecyninitemcommentscontainer') addnewlasttimestamp = ksscore.getHtmlIdSelector( 'comcynapselasttimestamp') addnewlastcommentid = ksscore.getHtmlIdSelector( 'comcynapselastcommentid') addnewcommentcount = ksscore.getHtmlIdSelector( 'comcynapsecommentcount') objcommentslist = [] pdt = getToolByName(self.context, 'portal_discussion', None) if pdt <> None: disc_container = pdt.getDiscussionFor(self.context) alldiscussions = disc_container.objectValues() allreplies = self.get_replies(pdt, self.context) newreplycount = disc_container.replyCount(self.context) newlastdate = DateTime().timeTime() if viewtype == 'flatview': alldiscussions.sort( lambda x, y: cmp(x.modified(), y.modified())) objcommentslist.extend(alldiscussions) else: objcommentslist.extend(allreplies) ksscore.replaceInnerHTML(commentscontainer, '') complete_output = '' for eachcomment in objcommentslist: if hasattr(eachcomment, 'id'): id = eachcomment.id elif eachcomment.has_key('id'): id = eachcomment['id'] reply = disc_container.getReply(id) if reply <> None: parentsInThread = reply.parentsInThread() depthvalue = 0 if viewtype.lower() == 'threadedview': lenofparents = len(parentsInThread) depthvalue = lenofparents - 1 prev_reply_id = self.findpreviouscommentid( allreplies, reply) newlastdate = reply.modified().timeTime() commenttemplate = ViewPageTemplateFile( 'ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__(self.context) replydict = [ { 'depth': depthvalue, 'object': reply, 'prev_id': prev_reply_id, 'view_type': viewtype, 'showoutput': True }, ] output = commenttemplate.render(reply_dict=replydict) #if there is no prev id found for new comment then insert it as last item to commentscontainer #else insert it after prev id comments table. if viewtype == 'flatview': complete_output += output else: complete_output += output if complete_output <> '' and len(objcommentslist) > 0: ksscore.replaceInnerHTML(commentscontainer, complete_output) jq.serverCall(commentscontainer, 'truncatetextonitemexpand') if len(alldiscussions) > 0: strlastcommentid = str(alldiscussions[-1].id) ksscore.setKssAttribute(commentshiddencontainer, 'lastcommentid', strlastcommentid) ksscore.setAttribute(addnewlastcommentid, 'value', strlastcommentid) newlasttimestamp = str(newlastdate) strcommentcount = str(newreplycount) ksscore.setKssAttribute(commentshiddencontainer, 'lasttimestamp', newlasttimestamp) ksscore.setKssAttribute(commentshiddencontainer, 'commentcount', strcommentcount) ksscore.setAttribute(addnewlasttimestamp, 'value', newlasttimestamp) ksscore.setAttribute(addnewcommentcount, 'value', strcommentcount) itemcountcommentcount = ksscore.getHtmlIdSelector( 'itemcountcommentcount') discussionlabel = ksscore.getHtmlIdSelector('discussionlabel') ksscore.replaceInnerHTML(discussionlabel, strcommentcount) ksscore.replaceInnerHTML(itemcountcommentcount, strcommentcount) ksscore.setKssAttribute(commentshiddencontainer, 'viewtype', viewtype) addnewcommentviewtype = ksscore.getHtmlIdSelector('comcynapseviewtype') ksscore.setAttribute(addnewcommentviewtype, 'value', viewtype) ksscore.setStyle(commentscontainer, 'display', 'block')
def inspectViewletManager(self, managerName): """ Display information about a particular viewlet manager """ logger.debug("in inspectViewletManager") # Get the viewletmanager object managerName = managerName.replace('-', '.') viewletManager = queryMultiAdapter((self.context, self.request, self), IViewletManager, managerName) # Gather information for the viewlet hashes managerInterface = list(providedBy(viewletManager).flattened())[0] # Look up the viewlets attached to this viewlet manager. # We do it this way because calling viewletManager.viewlets won't see the hidden viewlets... viewlets = getAdapters((self.context, self.request, viewletManager.__parent__, viewletManager),IViewlet) # Get the names of the hidden viewlets storage = getUtility(IViewletSettingsStorage) hidden = frozenset(storage.getHidden(managerName, self.context.getCurrentSkinName())) # Generate the output sortedViewlets = viewletManager.sort(viewlets) containedViewlets = [] for viewletTuple in sortedViewlets: containedViewlet = {} viewletname = viewletTuple[0] # generate viewlet hashes... # TODO factor this up. # Get the "provided" interfaces for this viewlet manager. # TODO: Do this lookup properly. regs = [regs for regs in getGlobalSiteManager().registeredAdapters() if regs.name == viewletname and regs.required[-1].isOrExtends(managerInterface)] if regs: reg = regs[0] provided = ','.join([a.__identifier__ for a in reg.required]) # logger.debug("%s - provided: %s" % (viewletName, provided)) hashedInfo = binascii.b2a_hex("%s\n%s\n%s" % (viewletname, managerName, provided)) else: hashedInfo = "" logger.debug("Unable to create hash for %s" % viewletname) # Give the viewlet a class name depending on the visibility classname = viewletname in hidden and 'hiddenViewlet' or 'visibleViewlet' logger.debug(classname) containedViewlet['className'] = classname containedViewlet['hashedInfo'] = hashedInfo containedViewlet['name'] = viewletname containedViewlets.append(containedViewlet) # Determine whether the contained viewlets can be sorted. skinname = self.context.getCurrentSkinName() canOrder = bool(storage.getOrder(managerName, skinname)) template = ViewPageTemplateFile('panel_inspect_viewlet_manager.pt') # Wrap it so that Zope knows in what context it's being called # Otherwise, we get an "AttributeError: 'str' object has no attribute 'other'" error template = template.__of__(self) out = template(managerName = managerName, containedViewlets = containedViewlets, canOrder = canOrder ) # Dump the output to the output panel self.updatePanelBodyContent(out) # Highlight the element ksscore = self.getCommandSet('core') self.highlightElement(ksscore.getCssSelector('.kssattr-viewletmanagername-%s' % managerName.replace('.', '-'))) # And in the nav tree (Should this be here or in the nav tree viewlet code?) self.highlightInNavTree(ksscore.getCssSelector('#glowormPanelNavTree .kssattr-forviewletmanager-%s' % managerName.replace('.', '-'))) return self.render()
def replyToComment(self,viewtype,lasttimestamp,commentcount,lastcommentid): query = {'UID':self.request['cont_uid']} pdt = getToolByName(self.context, 'portal_discussion', None) cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) ksscore = self.getCommandSet('core') zopecore = self.getCommandSet('zope') jq = self.getCommandSet('jquery') if len(resbrains) == 1: contobj = resbrains[0].getObject() if contobj.isDiscussable() and self.canreply(contobj): mtool = getToolByName(self.context, 'portal_membership') username = mtool.getAuthenticatedMember().getId() dobj = pdt.getDiscussionFor(contobj) if len(self.request['commentbody'].strip(' ')) == 0 or self.request['commentbody'].lower() == self.request['comcynapsenewcommenttitle'].lower(): comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector('comcynapsecommenterror'+ self.request['inreplyto']) ksscore.setStyle(comcynapsecommenterrorlabel,'display','block') else: id = dobj.createReply(title="", text=self.request['commentbody'], Creator=username) reply = dobj.getReply(id) reply.cooked_text = convertWebIntelligentPlainTextToHtml(reply.text) replyto = dobj.getReply(self.request['inreplyto']) reply.setReplyTo(replyto) if reply <> None: from ubify.cyninv2theme import triggerAddOnDiscussionItem triggerAddOnDiscussionItem(reply) #################Determine full reply to discussion to get placement peer of current comment view_type = self.request['cviewtype'] replies = [] def getRs(obj, replies, counter): rs = pdt.getDiscussionFor(obj).getReplies() if len(rs) > 0: rs.sort(lambda x, y: cmp(x.modified(), y.modified())) for r in rs: replies.append({'depth':counter, 'object':r}) getRs(r, replies, counter=counter + 1) getRs(replyto, replies, 0) if len(replies) > 1: ##There are more than 1 comments already children of the comment we just replied to, so the current comment can't have been the first reply prevrep = replies[0]['object'] else: prevrep = replyto for rep in replies: if rep['object'].id == reply.id: belowreply = prevrep else: prevrep = rep['object'] mi = mtool.getMemberInfo(); commenttemplate = ViewPageTemplateFile('ksstemplates/commentrow.pt') commenttemplate = commenttemplate.__of__(self.context) depthvalue = 0 if view_type == 'threadedview': depthvalue = int(self.request['depth']) + 1 replydict = [{'depth': depthvalue, 'object': reply,'view_type':view_type},] output = commenttemplate.render(indent=int(self.request['depth'])+2,fullname = mi['fullname'], avatarurl=self.context.portal_membership.getPersonalPortrait(username).absolute_url(),creator=username,showreply=self.canreply(self.context),showdelete=getSecurityManager().checkPermission('Manage portal',aq_inner(self.context)),commenttime=self.context.toLocalizedTime(reply.created,True),replyid=reply.id,replytitle=reply.Title(),replybody=reply.CookedBody(),replyurl=reply.absolute_url(),reply_dict=replydict) if view_type == 'threadedview': commentscontainer = ksscore.getHtmlIdSelector('commenttable' + prevrep.id) ksscore.insertHTMLAfter(commentscontainer,output) else: commentsoutercontainer = ksscore.getHtmlIdSelector('comcynapsecyninitemcommentscontainer') ksscore.insertHTMLAsLastChild(commentsoutercontainer,output) taAddNewComment = ksscore.getCssSelector('textarea.commentbodyta') ksscore.setAttribute(taAddNewComment,"value","") itemcountcommentcount = ksscore.getHtmlIdSelector('itemcountcommentcount') countofcomments = dobj.replyCount(self.context) discussionlabel = ksscore.getHtmlIdSelector('discussionlabel') ksscore.replaceInnerHTML(discussionlabel,str(countofcomments)) ksscore.replaceInnerHTML(itemcountcommentcount,str(countofcomments)) newcomment = ksscore.getHtmlIdSelector('commenttable' + reply.id) frmreply = ksscore.getHtmlIdSelector('replyform' + self.request['inreplyto']) ksscore.setStyle(frmreply,'display','none') comcynapsecommenterrorlabel = ksscore.getHtmlIdSelector('comcynapsecommenterror'+ self.request['inreplyto']) ksscore.setStyle(comcynapsecommenterrorlabel,'display','none') self.fetchnewcomments(lasttimestamp,commentcount,lastcommentid,viewtype)