コード例 #1
0
ファイル: talk.py プロジェクト: masyl/wrook
	def get(self, key):
		onRequest(self)
		if key:
			cacheKey = key
			logging.debug("getting topic from cache: %s" % key)
			topic = cachetree.get(cacheKey)
			if not topic:
				logging.debug("no topic found in cache")
				topic = Topic.get(key)
				if topic: cachetree.set(key, topic)
			if topic:
				cacheKey = "%s-page-TopicView"\
					% topic.key()
				cachedPage = cachetree.get_fresh_cache(
					cacheKey,
					["%s" % topic.parent().key(),
						"%s-replies" % topic.key()])
				if not cachedPage:
					self.Model.update({
						"topic" : topic,
						"renderedReplies" : topic.render_replies_list(),
						"renderedReplyForm" : topic.render_reply_form()
					})
					self.TemplateBaseFolder = os.path.dirname(__file__)
					cachedPage = self.getRender('views/talk-TopicView.html')
					cachetree.set(cacheKey, cachedPage)
				self.response.out.write(cachedPage)
			else: self.error(404)
		else: self.error(500)
コード例 #2
0
ファイル: talk.py プロジェクト: masyl/wrook
	def topics(self, maxResults=999, offset=0):
		key = "topicable-%s::topics-%s-%s" % (self.key(), maxResults, offset)
		topics = cachetree.get(key)
		if not topics:
			topics = Topic.all().ancestor(self).order("-Sent")\
				.fetch(limit=maxResults, offset=offset)
			cachetree.set(key, topics)
		return topics
コード例 #3
0
ファイル: talk.py プロジェクト: masyl/wrook
	def render(self):
		cacheKey = "topic-%s" % self.key()
		renderedTopic = cachetree.get(cacheKey)
		if not renderedTopic:
			templateSource = "%s/views/talk-part-topic.html" % os.path.dirname(__file__)
			data = {"topic": self}
			renderedTopic = template.render(templateSource, data)
			cachetree.set(cacheKey, renderedTopic)
		return renderedTopic
コード例 #4
0
ファイル: talk.py プロジェクト: masyl/wrook
	def render_topics_list(self, maxResults=maxTopicsPerPage, offset=0):
		cacheKey = "%s-renderedTopicList-%s-%s" % (self.key(), maxResults, offset)
		renderedTopicList = cachetree.get_fresh_cache(cacheKey,
			["%s-topicsWithReplies" % self.key()])
		if not renderedTopicList:
			templateSource = "%s/views/talk-part-topics.html" % os.path.dirname(__file__)
			model = {"topics": self.topics(maxResults)}
			renderedTopicList = template.render(templateSource, model)
			cachetree.set(cacheKey, renderedTopicList)
		return renderedTopicList.decode('utf-8')
コード例 #5
0
ファイル: talk.py プロジェクト: masyl/wrook
	def render_replies_list(self, maxResults=999, offset=0):
		logging.debug("in: render_replies_list(%s)" % self.key())
		cacheKey = "%s-render-replies-list-%s-%s" % (self.key(), maxResults, offset)
		renderedReplies = cachetree.get_fresh_cache(cacheKey,[
			"%s-replies" % self.key()])
		if not renderedReplies:
			templateSource = "%s/views/talk-part-replies.html" % os.path.dirname(__file__)
			model = {"replies": self.replies(maxResults, offset)}
			renderedReplies = template.render(templateSource, model)
			cachetree.set(cacheKey, renderedReplies)
		logging.debug("out: render_replies_list(%s)" % self.key())
		return renderedReplies.decode('utf-8')
コード例 #6
0
ファイル: talk.py プロジェクト: masyl/wrook
	def replies(self, maxResults=999, offset=0):
		logging.debug("in: replies(%s)" % self.key())
		cacheKey = "%s-replies-list-%s-%s" % (self.key(), maxResults, offset)
		replies = cachetree.get_fresh_cache(cacheKey,[
			"%s-replies" % self.key()])
		logging.debug("replies: %s " % replies)
		if not replies:
			replies = Reply.all().ancestor(self).order("Sent")\
				.fetch(limit=maxResults, offset=offset)
			cachetree.set(cacheKey, replies)
		logging.debug("out: replies(%s)" % self.key())
		return replies