Esempio n. 1
0
    def handle(self, *args, **options):

        print '================================'
        print 'reload_presentidlist'
        print '================================'

        uid_max = Player.max_value('id')
        redisdb = RedisModel.getDB()
        pipe = redisdb.pipeline()
        model_mgr = ModelRequestMgr()

        for uid in xrange(1, uid_max + 1):
            BackendApi._save_presentidlist(uid,
                                           model_mgr,
                                           using=settings.DB_READONLY,
                                           pipe=pipe)
            print '%s..end' % uid

        pipe.execute()
        print '================================'
        print 'all done'
Esempio n. 2
0
    def putPresentList(self, url_reload, topic, page=0, sort="desc", using=settings.DB_READONLY):
        """プレゼントリストをHTMLに埋め込む.
        """
        model_mgr = self.getModelMgr()
        
        # 絞り込みの引数.
        v_player = self.getViewerPlayer()
        
        overlimit = v_player.cardlimit <= BackendApi.get_cardnum(v_player.id, model_mgr, using=settings.DB_READONLY)
        
        # プレゼントを取得.
        offset = page * Defines.PRESENT_PAGE_CONTENT_NUM
        limit = Defines.PRESENT_PAGE_CONTENT_NUM + 1
        presentidlist = BackendApi.get_present_idlist(v_player.id, topic, offset, limit, model_mgr, using=using, desc=sort=="desc")
        has_next_page = len(presentidlist) == limit
        presentidlist = presentidlist[:Defines.PRESENT_PAGE_CONTENT_NUM]
        presentlist = BackendApi.get_presents(presentidlist, model_mgr, using=using)
        if presentlist is None:
            # うまく取れなかった.リダイレクトさせておくか.
            BackendApi._save_presentidlist(v_player.id, model_mgr, topic, using=using)
            url = url_reload
            url = OSAUtil.addQuery(url, Defines.URLQUERY_CTYPE, topic)
            url = OSAUtil.addQuery(url, Defines.URLQUERY_PAGE, page)
            self.appRedirect(self.makeAppLinkUrlRedirect(url))
            return
        
        self.html_param['presentlist'] = [Objects.present(self, presentset, overlimit, cur_topic=topic) for presentset in presentlist]
        
        # 絞り込み用のURL.
        url_base = OSAUtil.addQuery(UrlMaker.present(), Defines.URLQUERY_SORTBY, sort)
        self.html_param['url_all'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_CTYPE, Defines.PresentTopic.ALL))
        self.html_param['url_card'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_CTYPE, Defines.PresentTopic.CARD))
        self.html_param['url_item'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_CTYPE, Defines.PresentTopic.ITEM))
        self.html_param['url_etc'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_CTYPE, Defines.PresentTopic.ETC))
        
        # ソート切り替え.
        url_base = OSAUtil.addQuery(UrlMaker.present(), Defines.URLQUERY_CTYPE, topic)
        self.html_param['url_desc'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_SORTBY, "desc"))
        self.html_param['url_asc'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_SORTBY, "asc"))
        self.html_param['cur_sort'] = "desc" if sort == "desc" else "asc"
        
        # ページ切り替えURL.
        url_base = OSAUtil.addQuery(url_base, Defines.URLQUERY_SORTBY, sort)
        if 0 < page:
            self.html_param['url_prev'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_PAGE, page - 1))
        if has_next_page:
            self.html_param['url_next'] = self.makeAppLinkUrl(OSAUtil.addQuery(url_base, Defines.URLQUERY_PAGE, page + 1))
        
        # まとめて受け取るUrl.
        url = UrlMaker.presentdo()
        url = OSAUtil.addQuery(url, Defines.URLQUERY_CTYPE, topic)
        url = OSAUtil.addQuery(url, Defines.URLQUERY_SORTBY, sort)
        self.html_param['url_receive_all'] = self.makeAppLinkUrl(self.addIDQuesyParam(url, presentidlist))
        
        # チェックボックスのキー.
        self.html_param['key_except_card'] = Defines.URLQUERY_CHECK_CARD
        self.html_param['key_except_gold'] = Defines.URLQUERY_CHECK_GOLD
        
        self.html_param['cur_topic'] = topic
        
        client = OSAUtil.get_cache_client()
#        client.set(v_player.id, topic, namespace='presentbox:topic')
        client.set(v_player.id, sort, namespace='present:sort')