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 __call__(self): uid = None itemindex = 0 if self.request.form.has_key('uid'): uid = self.request.form['uid'] if self.request.form.has_key('itemindex'): itemindex = self.request.form['itemindex'] if uid is not None: query = {'UID':uid} pdt = getToolByName(self.context,'portal_discussion') cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) if len(resbrains) == 1: item = resbrains[0] contobj = item.getObject() fullpath = item.getPath() splitpath = fullpath.split('/')[:-1] prettypath = '/' + '/'.join(splitpath) URLsuffix = getListingTemplateForContextParent(item) pathlink = self.context.portal_url() + prettypath + '/' + URLsuffix pathtitle = prettypath lasttimestamp = DateTime().timeTime() lastcommentid = '0' showxmorelink = True commentscount = 0 xmorecomments = 0 replydict = [] isDiscussable = contobj.isDiscussable() canReply = canreply(contobj) jsondata = getjsondata(self.context,replydict,self.context.portal_url(),contobj.absolute_url()) if isDiscussable: dobj = pdt.getDiscussionFor(contobj) alldiscussions = dobj.objectValues() alldiscussions.sort(lambda x,y:cmp(x.modified(),y.modified()),reverse=True) maxdispcomments = 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 if len(alldiscussions) > 0: lasttimestamp = alldiscussions[0].modified().timeTime() lastcommentid = alldiscussions[0].id 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,'showoutput':True}) other_data = {'view_type':'listview','canreply': str(canReply)} jsondata = getjsondata(self.context,replydict,self.context.portal_url(),contobj.absolute_url(),other_data) return self.template(item_type=contobj.portal_type,item_type_title=contobj.Type(),item=item,pathlink=pathlink,pathtitle=pathtitle,contobj=contobj,showxmorelink = showxmorelink, xmorecomments = xmorecomments,allowdiscussion = isDiscussable,usercanreply = canReply,uid=uid,reply_dict=jsondata,title=contobj.Title(),commentcount=commentscount,lasttimestamp = lasttimestamp,lastcommentid = lastcommentid,itemindex=itemindex,view_type='listview') else: raise NotFound('Object not found for request','Not found',self.request) else: raise NotFound('uid is not passed','Not found',self.request)
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 __call__(self): uid = None itemindex = 0 if self.request.form.has_key('uid'): uid = self.request.form['uid'] if self.request.form.has_key('itemindex'): itemindex = self.request.form['itemindex'] if uid is not None: query = {'UID': uid} pdt = getToolByName(self.context, 'portal_discussion') cat = getToolByName(self.context, 'uid_catalog') resbrains = cat.searchResults(query) if len(resbrains) == 1: item = resbrains[0] contobj = item.getObject() fullpath = item.getPath() splitpath = fullpath.split('/')[:-1] prettypath = '/' + '/'.join(splitpath) URLsuffix = getListingTemplateForContextParent(item) pathlink = self.context.portal_url( ) + prettypath + '/' + URLsuffix pathtitle = prettypath lasttimestamp = DateTime().timeTime() lastcommentid = '0' showxmorelink = True commentscount = 0 xmorecomments = 0 replydict = [] isDiscussable = contobj.isDiscussable() canReply = canreply(contobj) jsondata = getjsondata(self.context, replydict, self.context.portal_url(), contobj.absolute_url()) if isDiscussable: dobj = pdt.getDiscussionFor(contobj) alldiscussions = dobj.objectValues() alldiscussions.sort( lambda x, y: cmp(x.modified(), y.modified()), reverse=True) maxdispcomments = 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 if len(alldiscussions) > 0: lasttimestamp = alldiscussions[0].modified().timeTime() lastcommentid = alldiscussions[0].id 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, 'showoutput': True }) other_data = { 'view_type': 'listview', 'canreply': str(canReply) } jsondata = getjsondata(self.context, replydict, self.context.portal_url(), contobj.absolute_url(), other_data) return self.template(item_type=contobj.portal_type, item_type_title=contobj.Type(), item=item, pathlink=pathlink, pathtitle=pathtitle, contobj=contobj, showxmorelink=showxmorelink, xmorecomments=xmorecomments, allowdiscussion=isDiscussable, usercanreply=canReply, uid=uid, reply_dict=jsondata, title=contobj.Title(), commentcount=commentscount, lasttimestamp=lasttimestamp, lastcommentid=lastcommentid, itemindex=itemindex, view_type='listview') else: raise NotFound('Object not found for request', 'Not found', self.request) else: raise NotFound('uid is not passed', 'Not found', self.request)