Example #1
0
    def _render_list(self, req, db, flatmode, month):
        target_category = req.args.get('category', '')

        data = {}

        from model import MailFinder
        data['mls'], data['name'], data['year'], data['month'], target_category \
             = MailFinder.get_categories(req, db, target_category)
        
        results = MailFinder.find_by_category(self.env, target_category.encode('utf-8'))
        
        #pagelize
        pagelized = self._pagelize_list(req, results, data)

        #Thanks http://d.hatena.ne.jp/ohgui/20090806/1249579406
        data['reversemode'] = reversemode = (req.args.get('reversemode', 'off') == 'on')
        data['flatmode'] = flatmode

        mails_per_page, cached_mails = self._get_mails_per_page(pagelized, reversemode, flatmode)

        idstext = self._collect_ids(pagelized.items, flatmode)
        
        self.log.debug("Idtext: %s" % idstext)
        
        req.session['mailarc_mails'] = idstext
        req.session['mailarc_category_href'] = get_category_href(req, target_category)

        data['mails'] = mails_per_page
        data['cached_mails'] = cached_mails

        return 'mailarchive.html', data, None
Example #2
0
 def _get_mails_per_page(self, pagelized, reversemode, flatmode):
     mails_per_page = []
     
     if flatmode:
         mails_per_page = [mail for mail in pagelized.items]
         if reversemode:
             mails_per_page.reverse()
         return mails_per_page, []
         
     else:
         #ツリー表示のため、rootだけを集める
         root_mails = []
         for mail in pagelized.items:
             root_mail = mail.get_thread_root()
             
             if root_mail in mails_per_page:
                 #ルートの場合最後に登録し直すため一度削除する
                 mails_per_page.remove(root_mail)
             mails_per_page.append(root_mail)
             
             if root_mail not in root_mails:
                 root_mails.append(root_mail)
                 
         #ルートから関連メールを全てキャッシュする
         root_messageids = [x.messageid for x in root_mails]
         from model import MailFinder
         cached_mails = MailFinder.find_thread_mails(self.env, root_messageids)
 
         if reversemode:
             mails_per_page.reverse()
         return mails_per_page, cached_mails
 def do_updatedb(self, line):
     db = self.db_open()
     self.env = self.env_open()
     
     from model import MailFinder
     
     mails = MailFinder.find_not_root(self.env)
     
     cursor = db.cursor()
     for mail in mails:
         root_id = mail.get_thread_root().messageid
         sql = "UPDATE mailarc SET threadroot = %s WHERE messageid = %s" 
         printout(_('root_id=%s, messageid=%s' % (root_id, mail.messageid)))
         if root_id == mail.messageid:
             #自分が親(親メッセージIDのメールがDBに存在しない)場合、更新しない
             continue
         cursor.execute(sql, (root_id, mail.messageid))
         self.print_info('%s' % sql)
         
     db.commit()