def getMessageBodies(self): """Creates a structure for a thread tree""" if self.flat: message = messageStructure(self.context, sub_mgr=self.getSubManager(), full_message=True) message['children'] = [] results = self.search.getMessageReferrers(self.context.message_id, reversed=self.newest_first) for msg in results: child = messageStructure(msg, sub_mgr=self.getSubManager(), full_message=True) child['children']=[] message['children'].append(child) return message # If the method was already called it should be cached, use it. If # not call it and cache it. reply_struct = self._reply_cache if reply_struct is None: try: reply_struct = createReplyStructureFromReferrers( self.context, self.search, full_message=True, sub_mgr=self.getSubManager(), newest_first=self.newest_first) except KeyError: # This happens when we have parentless messages in the # thread. Fall back to the equivalent, but slower, # way of creating the structure. reply_struct = createReplyStructure( self.context, self.search, full_message=True, sub_mgr=self.getSubManager()) # Cache this in case we need it for the thread display self._reply_cache = reply_struct return reply_struct
def getMessageBodies(self): """Creates a structure for a thread tree""" if self.flat: message = messageStructure(self.context, sub_mgr=self.getSubManager(), full_message=True) message['children'] = [] results = self.search.getMessageReferrers( self.context.message_id, reversed=self.newest_first) for msg in results: child = messageStructure(msg, sub_mgr=self.getSubManager(), full_message=True) child['children'] = [] message['children'].append(child) return message # If the method was already called it should be cached, use it. If # not call it and cache it. reply_struct = self._reply_cache if reply_struct is None: try: reply_struct = createReplyStructureFromReferrers( self.context, self.search, full_message=True, sub_mgr=self.getSubManager(), newest_first=self.newest_first) except KeyError: # This happens when we have parentless messages in the # thread. Fall back to the equivalent, but slower, # way of creating the structure. reply_struct = createReplyStructure( self.context, self.search, full_message=True, sub_mgr=self.getSubManager()) # Cache this in case we need it for the thread display self._reply_cache = reply_struct return reply_struct
def items(self, n_items=5): if hasattr(self,'_items'): # If the property already contains something, there's no need to # regenerate it. return self._items # set self._items to empty list in case we have # no results at all self._items = [] all_msgs = [] for ml_id in self.mlists: mlist = self.context._getOb(ml_id) if not mlist.can_view_archives(mlist.REQUEST): continue cat = get_utility_for_context(ISearchableArchive, mlist) # aq wrap since brains work better this way cat = cat.__of__(mlist) msgs = cat(sort_limit=n_items, sort_order='descending', sort_on='modification_date') all_msgs.extend(msgs) all_msgs.sort(key=lambda x:x.modification_date, reverse=True) all_msgs = all_msgs[:n_items] for msg in all_msgs: mstruct = messageStructure(msg, sub_mgr=mlist) self.add_item(title=obfct(msg.subject), description=obfct(msg.subject), link='%s/forum_view' % mstruct['url'], author=mstruct['mail_from'], pubDate=msg.modification_date, # context=mlist, # byline='by', # responses=response ) return self._items
def getTopics(self): """Returns a list of dicts containing information about the initial messages in threads. """ batch = self.request.get('batch', True) batch_size = int(self.request.get('b_size', 25)) batch_start = int(self.request.get('b_start', 0)) context = self.context topic_list = [] search = self.search getToplevelMessages = search.getToplevelMessages getMessageReferrers = search.getMessageReferrers messages = getToplevelMessages(recent_first=True) mem_list = IMembershipList(self.getMailingList()) if batch: messages = Batch(messages, batch_size, batch_start) for message in messages: msg_dict = messageStructure(message, sub_mgr=mem_list) msg_dict['responses'] = message.responses or 0 msg_dict['last_post'] = format_date(message.modification_date, context) msg_dict['url'] = msg_dict['url'] + '/forum_view' topic_list.append(msg_dict) messages.topic_list = topic_list return messages
def getTopics(self): """Returns a list of dicts containing information about the initial messages in threads. """ batch = self.request.get('batch', True) batch_size = int(self.request.get('b_size', 25)) batch_start = int(self.request.get('b_start', 0)) context = self.context topic_list = [] search = self.search getToplevelMessages = search.getToplevelMessages getMessageReferrers = search.getMessageReferrers messages = getToplevelMessages(recent_first=True) mem_list = IMembershipList(self.getMailingList()) if batch: messages = Batch(messages, batch_size, batch_start) for message in messages: msg_dict = messageStructure(message, sub_mgr=mem_list) msg_dict['responses'] = message.responses or 0 msg_dict['last_post'] = format_date(message.modification_date, context) msg_dict['url'] = msg_dict['url'] +'/forum_view' topic_list.append(msg_dict) messages.topic_list = topic_list return messages
def getPreviousByDate(self): """See ISearchableArchive documentation""" msg = self.search.getPreviousByDate(self.message_id) return msg and messageStructure(msg, sub_mgr=self.getSubManager())
def getNextInThread(self): """See ISearchableArchive documentation""" msg = self.search.getNextInThread(self.message_id) return msg and messageStructure(msg, sub_mgr=self.getSubManager())
def getPreviousByDate(self): """See ISearchableArchive documentation""" msg = self.search.getPreviousByDate(self.message_id) return msg and messageStructure(msg, sub_mgr=self.getSubManager())
def getNextInThread(self): """See ISearchableArchive documentation""" msg = self.search.getNextInThread(self.message_id) return msg and messageStructure(msg, sub_mgr=self.getSubManager())
def items(self, n_items=5): """feed for latest messages in a mailing list""" if hasattr(self,'_items'): # If the property already contains something, there's no need to # regenerate it. return self._items archive = getUtility(ISearchableArchive, context=self.context) messages = archive.getToplevelMessages() messages = [ dict(message=message, reply=latest_reply(archive, message), mlist=self.context) for message in messages ] date = lambda x: x['reply'].modification_date messages.sort(key=date, reverse=True) messages = messages[:n_items] self._items = [] for message in messages: reply = message['reply'] mlist = message['mlist'] message = message['message'] structure = messageStructure(message, sub_mgr=mlist) reply_structure = messageStructure(reply, sub_mgr=mlist) link = '%s/forum_view' % structure['url'].rstrip('/') reply_url = '%s#%s' % ( link, reply_structure['id'] ) pubDate = reply.modification_date author = reply_structure['from_id'] if not author: author = reply_structure['mail_from'] match = re.match(email_re, author) if match: author = match.groups()[0] title = structure['subject'] description = structure['subject'] # deal with responses responses = message.responses if responses: byline = 'latest by' response = FeedItemResponses(responses, reply_url) else: response = None byline = 'by' self.add_item(title=title, description=description, link=link, author=author, pubDate=pubDate, byline=byline, responses=response) return self._items