0

こんにちは私は動作していたWebページングを有効にしたいのですが、環境や実装の更新中に壊れてしまいました。 GAEによって注文されたリストをページ付けしたい オブジェクトは "自然順序付け"すなわち時間、数値、単語などを持つ傾向があるので、このコードはすでにどこかで使用可能な状態になっていますか?おそらくので、それが動作するために使用データセットをページングする方法

next = None 
    bookmark = self.request.get("bookmark") 
    category = self.request.get('cg')#category parameter 
    if bookmark: 
    bookmark = datetime.strftime(bookmark[:-7], "%Y-%m-%d %H:%M:%S") 
    else:  
    bookmark = datetime.strftime(datetime.now(), "%Y-%m-%d %H:%M:%S") 

    if cg: 
    articles = Articles.all().filter("category =", cg).filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1)  

、今ページングが壊れている:URLクエリからブックマークと呼ばれるパラメータを取りますhttp://code.google.com/appengine/articles/paging.html 私の努力:私は、Googleがここに記載されていることをジョーイGからの例のようなものをやってみました私は、変更されたオブジェクトとdatetimeオブジェクトをどのように扱うかを完全には理解していません。途中で私を助けてくれますか?私のユースケースへのURLはwww.koolbusiness.com/liです ありがとう

EDIT/UPDATE:リストページを表示する現在のコードは次のとおりです。それはINをいくつかの場所で使用しているので、INなしで動作するように書き換えられる可能性があります。難しいのは、nocategoryで検索したり、検索したり、私が何か不可能にしようとしていると思ってはいけません。それはもっとPythonを学ぶ必要があるだけです(ラムダプログラミングが関わっており、完全には把握できません)、すべての組み合わせが処理されるときにはより明確な構造になります。

class I18NListPage(FBBaseHandler,I18NHandler): 

    def get(self, cursor=None, limit=60, PAGESIZE = 10, twittername = None): 
    client = OAuthClient('twitter', self) 
    if client.get_cookie(): 
     info = client.get('/account/verify_credentials') 
     twittername = info['screen_name'] 
    if (users.is_current_user_admin()): 
     timeline = datetime.now() - timedelta (days = limit) 
    else: 
     timeline = datetime.now() - timedelta (days = limit) 
    logo = ''    
    if util.get_host().endswith('.br'): 
     cookie_django_language = 'pt-br' 
     logo = 'montao' 
     translation.activate(cookie_django_language) 
     self.request.COOKIES['django_language'] = cookie_django_language 
     dispatch= 'template/montaoli.html' 
    else: 
     cookie_django_language = self.request.get('cookie_django_language', '') if self.request.get('cookie_django_language', '') else self.request.get('hl', '') 
     dispatch= 'template/li.html' 
    if cookie_django_language: 
     if cookie_django_language == 'unset': 
     del self.request.COOKIES['django_language'] 
     else: 
     self.request.COOKIES['django_language'] = cookie_django_language 
     self.reset_language()  
    next = None 
    bookmark = self.request.get("bookmark") 
    if not bookmark: 
     bookmark = = str(time.time()) 

    category = self.request.get('cg') 
    q = self.request.get('q').encode("utf-8") 
    w = self.request.get('q') 
    cg = self.request.get('cg') 
    t = self.request.get('t') 
    f = self.request.get('f') 

    if cg and not t and not q and not f:#category without search 
     ads = Ad.all().filter("category =", cg).filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1)  
    elif q and not t and not cg and not f:#search without category 
     ads = Ad.all().search(self.request.get('q')).filter("published =", True)  
     ads = filter(lambda x: x.modified > timeline, ads) 
     ads = filter(lambda x: x.modified <= bookmark, ads) 
     ads = ads[:PAGESIZE+1] 
     ads = sorted(ads, key=lambda x: x.modified, reverse=True) 
     #iterate list keeping elements that are on timeline newer than bookmark 
    elif q and not t and cg and not f: 
     ads = Ad.all().search(q).filter("type =", 's').filter("category =", cg).filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1)  
    elif t and not f: 
     ads = Ad.all().filter("type =", 'w').filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1)  
    elif f == 'c': 
     ads = Ad.all().filter("company_ad =", True).filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1) 
    elif f == 'p': 
     ads = Ad.all().filter("company_ad =", False).filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1) 
    else: 
     if util.get_host().find('onta') > 1: 
      ads = Ad.all().filter("modified >", timeline).filter("published =", True).filter("url IN", ['www.montao.com.br','montao']).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1)    
     else: 
      ads = Ad.all().filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1) 
    if util.get_host().find('onta') > 1 and f == 'c': 
     ads = Ad.all().filter("company_ad =", True).filter("modified >", timeline).filter("published =", True).filter("url IN", ['www.montao.com.br','montao']).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1) 
    elif util.get_host().find('onta') > 1 and f == 'p': 
     ads = Ad.all().filter("company_ad =", False).filter("modified >", timeline).filter("published =", True).filter("url IN", ['www.montao.com.br','montao']).filter("modified <=", bookmark).order("-modified").fetch(PAGESIZE+1) 


    if self.request.get('lat'): 
     m=int(self.request.get('r')) if self.request.get('r') else 804670 
     logging.info(m) 
     lat = self.request.get('lat') 
     lon = self.request.get('lon') if self.request.get('lon') else self.request.get('lng') 
     ads = Ad.proximity_fetch(Ad.all().filter("modified >", timeline).filter("published =", True).filter("modified <=", bookmark).order("-modified") ,db.GeoPt(lat, lon),max_results=PAGESIZE+1, max_distance=m) 
     ads = sorted(ads, key=lambda x: x.modified, reverse=True) 
    if ads and len(ads) == PAGESIZE+1: 
     next = ads[-1].modified 
     ads = ads[:PAGESIZE]  

    template_values = {'twittername':twittername,'request':self.request,'lat':self.request.get('lat'),'lon':self.request.get('lon'),'q':q,'w':w,'cg':cg,'t':t,'logo':logo,'ads':ads, 'next':next, 'user':users.get_current_user(), 'bookmark':bookmark,'q':q, 'user_url': users.create_logout_url(self.request.uri) if users.get_current_user() else 'login', 
      'cg':category,'admin':users.is_current_user_admin(),} 
    template_values.update(dict(current_user=self.current_user, facebook_app_id=FACEBOOK_APP_ID)) 
    path = os.path.join(os.path.dirname(__file__), dispatch) 
    self.response.out.write(template.render(path, template_values)) 

UPDATE 2:私は、次のコードを実際にページデータセットのこのこのケースをDjangoのページネータクラスfrom paginator import Paginator, InvalidPage, EmptyPageを使用してみました:それはとても簡単で、読み取り可能なので

 articles = Articles.all() 
     paginator = Paginator(articles,PAGESIZE) 
     articles = paginator.page(page) 

ので、私はこのソリューションは魅力的見つけますあなたが今後コメントできることを願っています。

答えて

1

クライアントに渡す前に、ブックマークをbase64でエンコードする必要がある場合があります。 [あなたのサイト] [1]を試しましたが、サーバー側のエラーメッセージを表示せずに質問に明確に答えられません。

さらに、ページング記事に記載されているように、ブックマークとしてdatetimeを直接使用すると、同じ期間に複数の記事が投稿されている間に問題が発生します。(期間は1分です)代わりにこの形式を使用することを検討してください。

2008-10-26 04:38:00|aee15ab24b7b3718596e3acce04fba85 

または秒を使用して時刻を表します。

1310427763.47|aee15ab24b7b3718596e3acce04fba85 

は、私はそれはそれは表示されます最初のページの場合)(DateTime.Nowがするように設定する必要がありますか?

最初のページの結果は、変更されたフィルタを無視するだけで取得できます。例えば :

if bookmark: 
    suggestions = Suggestion.all().order("-when") 
     .filter('when <=', bookmark).fetch(PAGESIZE+1) 
else: 
    suggestions = Suggestion.all().order("-when").fetch(PAGESIZE+1) 

又はブックマークとして現在の時刻を使用して。

import time 
bookmark = str(time.time()) 
+1

lucemiaありがとうございます。私は適切なフォーマットをフィンにしようとするべきです。それが今表示される方法は正しいとは思わない。私は時間を表現する秒を使用する方法を試みますが、私はどのようにブックマーク変数を使用するか分からない。私はそれをdatetime.now()に設定する必要がありますそれが表示される最初のページですか? –

+1

最初のページの結果は2通りあります。どちらの方法もうまくいくはずです! – lucemia

+1

私は時間の形式に一致することができますそれが動作します。私はdjangoのdatetimeオブジェクトを使って、別の方法で作業することができます。この質問でAbdulが説明しています。http://stackoverflow.com/questions/6014657/query-with-paging-by-cursor-causes-error-because-of-フィルタリングの制限 - i / –

3

Query cursorsは、このために作られています。独自のソリューションを構築する代わりに、それらを使用する必要があります。

+0

ありがとうございました。後で私のコードで、クエリカーソルを使用できないように見えるIN演算子を使用します。 –

+1

@Niklasそれを使用するクエリでは使用できません。しかし、あなたが投稿したクエリはINを使用しません。 –

+1

OKか、INを使用しないクエリを再作成するか、またはINまたはカーソルを取り除くか、INで動作するように更新するまでdatetimeをブックマークとして使用します –

関連する問題