def __init__(self, context, querier, p2pquerier): athena.LivePage.__init__(self) # NOTE: At the time this comment is written, athena/LivePages are handled # differently in nevow SVN. It's now possible to insantiate directly # LivePage instances (which is great !), so we'll have to change # the implementation for next nevow release. self.querier = querier self.p2pquerier = p2pquerier self.query = Query.fromContext(context) self.offset = self.query.offset self.onlyLocal = False self.onlyDistant = False # push local results once for all if len(inevow.IRemainingSegments(context)) < 2: # only store abstracts in the results table results = [] for localDoc in querier.findDocuments(self.query): localDoc.text = makeAbstract(localDoc.text, self.query.words) results.append(localDoc) webappConfig = INodeConfiguration(context) p2pQuery = P2pQuery(sender=webappConfig.get_node_id(), query=self.query) self.qid = p2pQuery.qid self.p2pQuery = p2pQuery # purge old results self.querier.purgeOldResults() provider = (NODE_LOGIN, NODE_CONFIG.get_node_id(), 'localhost', 0) self.querier.pushDocuments(self.qid, results, provider) self.results = self.querier.getQueryResults(self.query)
def getPageContextForRequestContext(self, ctx): """Retrieve a resource from this site for a particular request. The resource will be wrapped in a PageContext which keeps track of how the resource was located. """ path = inevow.IRemainingSegments(ctx) res = inevow.IResource(self.resource) pageContext = context.PageContext(tag=res, parent=ctx) return self.handleSegment(res.locateChild(pageContext, path), ctx.tag, path, pageContext)
def child_(self, ctx): """When addSlash is True, a page rendered at a url with no trailing slash and a page rendered at a url with a trailing slash will be identical. addSlash is useful for the root resource of a site or directory-like resources. """ # Only allow an empty child, by default, if it's on the end # and we're a directoryish resource (addSlash = True) if self.addSlash and len(inevow.IRemainingSegments(ctx)) == 1: return self return None
def child_(self, ctx): """When addSlash is True, a page rendered at a url with no trailing slash and a page rendered at a url with a trailing slash will be identical. addSlash is useful for the root resource of a site or directory-like resources. """ # Only allow an empty child, by default, if it's on the end # and we're a directoryish resource (addSlash = True) if self.addSlash and len(inevow.IRemainingSegments(ctx)) == 1: return self # After deprecation is removed, this should return None warnings.warn( "Allowing an empty child ('/') of resources automatically is " "deprecated. If the class '%s' is a directory-index-like resource, " "please add addSlash=True to the class definition." % (self.__class__), DeprecationWarning, 2) return self
def render_linkedDN(self, ctx, data): dn = data cfg = ctx.locate(interfaces.ILDAPConfig) baseDN = iwebui.ICurrentDN(ctx) ctx.tag.clear() while (dn!=baseDN and dn!=distinguishedname.DistinguishedName(stringValue='')): firstPart=dn.split()[0] u = url.here.parentdir().parentdir().child(dn) segments = inevow.ICurrentSegments(ctx) if segments[-1] == '': u = u.child(segments[-2]).child(segments[-1]) else: u = u.child(segments[-1]) for segment in inevow.IRemainingSegments(ctx): u = u.child(segment) ctx.tag[tags.a(href=u)[str(firstPart)], ','] dn=dn.up() ctx.tag['%s\n' % str(dn)] return ctx.tag