def get_summary(self, item, model, categories=None, locations=None): if model is self.db.Feedback: comment = item['comment'] if len(comment) > 40: comment = comment[:40].strip() + '...' return ("<strong>'%s' feedback!</strong> %s" % (item['what'], comment)) if model is self.db.User: if locations is None: locations = {} if item['current_location'] not in locations: locations[item['current_location']] = \ (self.db.Location .find_one({'_id': item['current_location']})) current_location = locations[item['current_location']] return ('<strong>User!</strong> %s (currently in %s)' % (item['username'], current_location)) if model is self.db.Question: if categories is None: categories = {} if item['category'] not in categories: categories[item['category']] = (self.db.Category .find_one({'_id': item['category']})) category = categories[item['category']] text = truncate_text(item['text'], 80) text = ("<strong>'%s' question!</strong> %s" % (category['name'], text)) if (self.db.QuestionPicture .find({'question': item['_id']}) .count()): text += ' (with picture)' return text.strip() if model is self.db.HTMLDocument: text = "<strong>'%s' document!</strong> " % item['type'] if item['user']: user = self.db.User.find_one({'_id': item['user']}) text += 'about user %s ' % user if item['location']: location = self.db.Location.find_one({'_id': item['location']}) text += 'about %s ' % location if item['category']: category = self.db.Category.find_one({'_id': item['category']}) text += 'for %s ' % category return text.strip() if model is self.db.Award: user = self.db.User.find_one({'_id': item['user']}) return ( "%s earned the <strong>%s award</strong> " "with %s coins reward! " % (user['username'], item['type'], item['reward']) ) raise NotImplementedError(model._obj_class)
def get_summary(self, item, model, categories=None, locations=None): if model is self.db.Feedback: comment = item['comment'] if len(comment) > 40: comment = comment[:40].strip() + '...' return ("<strong>'%s' feedback!</strong> %s" % (item['what'], comment)) if model is self.db.User: if locations is None: locations = {} if item['current_location'] not in locations: locations[item['current_location']] = \ (self.db.Location .find_one({'_id': item['current_location']})) current_location = locations[item['current_location']] return ('<strong>User!</strong> %s (currently in %s)' % (item['username'], current_location)) if model is self.db.Question: if categories is None: categories = {} if item['category'] not in categories: categories[item['category']] = (self.db.Category.find_one( {'_id': item['category']})) category = categories[item['category']] text = truncate_text(item['text'], 80) text = ("<strong>'%s' question!</strong> %s" % (category['name'], text)) if (self.db.QuestionPicture.find({ 'question': item['_id'] }).count()): text += ' (with picture)' return text.strip() if model is self.db.HTMLDocument: text = "<strong>'%s' document!</strong> " % item['type'] if item['user']: user = self.db.User.find_one({'_id': item['user']}) text += 'about user %s ' % user if item['location']: location = self.db.Location.find_one({'_id': item['location']}) text += 'about %s ' % location if item['category']: category = self.db.Category.find_one({'_id': item['category']}) text += 'for %s ' % category return text.strip() if model is self.db.Award: user = self.db.User.find_one({'_id': item['user']}) return ("%s earned the <strong>%s award</strong> " "with %s coins reward! " % (user['username'], item['type'], item['reward'])) raise NotImplementedError(model._obj_class)
def render(self, text, characters): return tornado.escape.xhtml_escape(truncate_text(text, characters))