示例#1
0
def image_list_json(request):
    #TODO duplication,I have to DRY below code
    blob_info_query = blobstore.BlobInfo.all().order('-creation')
    blob_info_results = blob_info_query.fetch(10)
    for r in blob_info_results:
        bsi_entity = BlobStoreImage.get_by_key_name(r.md5_hash)
        if bsi_entity is None:
            bsi_entity = BlobStoreImage(key_name=r.md5_hash,file_name=r.filename,blob_key=r.key())
            bsi_entity.put()
    query = BlobStoreImage.all().order('-update')
    paginator = Paginator(query,10)
    try:
        page = int(request.args.get('page','1'))
    except ValueError:
        page = 1
    try:
        results = paginator.page(page)
    except (EmptyPage,InvalidPage):
        results = paginator.page(paginator.num_pages)
    return_list = []
    for r in results.object_list:
        if r.image_path is None or r.image_path == '':
            r.image_path = get_serving_url(r.blob_key.key())
            r.put()
        return_list.append({'key':str(r.key()),
            'id':r.key().name(),
            'title':r.title,
            'file_name':r.file_name,
            'note':r.note,
            'image_path':RE_REMOVE_HTTP.sub('',r.image_path),
            'update':str(r.update)[:16]})
    return Response(json.dumps({'images':return_list,
        'current_page':results.number,
        'total_pages':results.paginator.num_pages}, ensure_ascii=False))
示例#2
0
def get_article_list(browser_lang,page,article_per_page,tag_name=False):
    if tag_name:
        tag_name_encoded = unicode(tag_name)
    else:
        tag_name_encoded = str(tag_name)
    memcache_key = u'article-'+str(page)+u'-'+str(article_per_page)+u'-'+urllib.quote(tag_name_encoded.encode('utf-8'))+u'-'+browser_lang
    logging.info(memcache_key)
    results_dic = memcache.get(memcache_key)
    #if memcache data exist return
    if results_dic:
        return results_dic
    #else memcach data is none,query from datastore
    now = datetime.datetime.now()
    logging.info(now)
    query = Article.all().filter(u'lang =',DEFAULT_LANG).filter(u'display_page_flg =',True)
    if tag_name:
        query.filter(u'tags =',tag_name)
    query.filter(u'display_time <',now).order('-display_time')
    paginator = Paginator(query,article_per_page)
    try:
        results = paginator.page(page)
    except (EmptyPage,InvalidPage):
        results = paginator.page(paginator.num_pages)
    return_list = []
    for r in results.object_list:
        browser_lang_trans = None
        if browser_lang != DEFAULT_LANG:
            translations = Article.all().ancestor(r.key()).fetch(1000)
            #browser_lang_trans = None
            for trans in translations:
                if trans.lang == browser_lang:
                    browser_lang_trans = trans
                    break
            if browser_lang_trans:
                r.content = browser_lang_trans.content
                r.title = browser_lang_trans.title
        url = r.external_url if r.external_url else url_for('mainapp/show_each_article',key_name=r.key().name())
        if browser_lang_trans and browser_lang != DEFAULT_LANG:
            url += '?hl='+browser_lang
        snippet = html.strip_tags(markdown(r.content)).split('\n')[0]
        try:
            first_image = json.loads(r.images)['images'][0]['image_path']
        except:
            first_image = None
        return_list.append({'key':str(r.key()),
            'id':r.key().name(),
            'title':r.title,
            'snippet':snippet,
            'url':url,
            'first_image':first_image,
            'display_time':str(r.display_time)[:10]})
    results_dic = {'articles':return_list,
    'current_page':results.number,
    'previous_page':results.previous_page_number,
    'next_page':results.next_page_number,
    'has_next':results.has_next,
    'total_pages':results.paginator.num_pages,
    'tag_name':tag_name}
    memcache.set(memcache_key,results_dic)
    return results_dic 
示例#3
0
文件: views.py 项目: gmist/f-toy
def search(request):
    if request.method == 'POST':
        text = request.form.get('q', '')
        if not text:
            return redirect('/')
        gifts_list = Gift.all().filter('leftovers >', 0).search(text,
            properties=['name'])
        gifts_list = filter_leftovers(gifts_list)
        if not gifts_list:
            return redirect('/')

        paginator = Paginator(gifts_list, 24)
        try:
            page = int(request.args.get('page', 1))
        except ValueError:
            page = 1
        try:
            gifts = paginator.page(page)
        except (EmptyPage, InvalidPage):
            gifts = paginator.page(paginator.num_pages())
        categories = get_cat_subcat()
        return render_to_response('index_page/main_page.html',
                {'gifts': gifts,
                 'categories': categories[0],
                 'subcategories': categories[1],
                 'subcategories_keys': categories[2],
                 'price_modif': GlobalPriceModif.get_price_modif()})
    else:
        return redirect('/')
示例#4
0
文件: views.py 项目: dbordak/pyblog
def report_admin(request):
  from kay.utils import render_to_response
  from kay.utils.paginator import Paginator

  version_filter = request.args.get('versions', 'all')
  report_date = request.args.get('date', None)
  if report_date:
    yesterday = datetime.date(*[int(x) for x in report_date.split('-')])
  else:
    yesterday = None

  app_id = os.environ['APPLICATION_ID']
  version = os.environ['CURRENT_VERSION_ID']
  major_version, minor_version = version.rsplit('.', 1)
  minor_version = int(minor_version)

  query_args = {
    'major_version': major_version,
  }
  if yesterday:
    query_args['query_date'] = yesterday

  try:
    exceptions = GetQuery(order='-date', **query_args)
    paginator = Paginator(exceptions, 10)
    page = paginator.page(request.args.get('page', 1))
  except db.NeedIndexError, e:
    logging.warn(e)
    exceptions = GetQuery(**query_args)
    paginator = Paginator(exceptions, 10)
    page = paginator.page(request.args.get('page', 1))
示例#5
0
def index(request):
    user=User.all()
    paginator=Paginator(user,25)
    try:
        page = int(request.args.get('page', '1'))
    except ValueError:
        page = 1
    try:
        contacts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        contacts = paginator.page(paginator.num_pages)
    return render_to_response('tsuhanbe_auth/index.html', {"contacts": contacts})
示例#6
0
def show_all(request):
    dragons = DragonMember.all()
    paginator = Paginator(dragons, 30)
    try:
        page = int(request.args.get("page", 1))
    except ValueError:
        page = 1
    try:
        dragons = paginator.page(page)
    except (EmptyPage, InvalidPage):
        dragons = paginator.page(paginator.num_pages())

    return render_to_response("dragons/admin/show_all.html", {"dragons": dragons})
示例#7
0
文件: admin.py 项目: gmist/f-toy
def news_all(request):
    news = News.all().order('-add_time')
    paginator = Paginator(news, 25)
    try:
        page = int(request.args.get('page',1))
    except ValueError:
        page = 1

    try:
        news = paginator.page(page)
    except (EmptyPage, InvalidPage):
        news = paginator.page(paginator.num_pages())
    return render_to_response('news/admin/news_all.html', {'news':news})
示例#8
0
def create_paginator_page(request, query, length=10):
    #show http://kay-docs-jp.shehas.net/pagination.html
    paginator = Paginator(query, length)
    
    try:
        page = int(request.args.get('page', '1'))
    except ValueError:
        page = 1
    
    try:
        return paginator.page(page)
    except (EmptyPage, InvalidPage):
        return paginator.page(paginator.num_page)
示例#9
0
def show_all(request):
    actions = Action.all().order('-add_time')
    paginator = Paginator(actions, 25)
    try:
        page = int(request.args.get('page',1))
    except ValueError:
        page = 1

    try:
        actions = paginator.page(page)
    except (EmptyPage, InvalidPage):
        actions = paginator.page(paginator.num_pages())
    return render_to_response('news/admin/actions_all.html', {'actions':actions})
示例#10
0
文件: admin.py 项目: gmist/f-toy
def all(request):
    gifts_list = Gift.all()
    paginator = Paginator(gifts_list, 26)
    try:
        page = int(request.args.get('page',1))
    except ValueError:
        page = 1

    try:
        gifts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        gifts = paginator.page(paginator.num_pages())

    return render_to_response('gift/admin/all.html', {'gifts':gifts})
示例#11
0
def index(request):
    showcases = Showcase.all().filter('is_display =', True).order("-add_time")
    paginator = Paginator(showcases, 5)
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1
    try:
        showcases = paginator.page(page)
    except (EmptyPage, InvalidPage):
        showcases = paginator.page(paginator.num_pages())

    return render_to_response('showcase/index.html', {
        'showcases': showcases
    })
示例#12
0
文件: views.py 项目: gmist/f-toy
def index(request):
    gifts_list = Gift.all().order('-rating')
    gifts_list = filter_leftovers(gifts_list)
    paginator = Paginator(gifts_list, 24)
    banners = MainPageBanner.all()
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1
    try:
        gifts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        gifts = paginator.page(paginator.num_pages())
    categories = get_cat_subcat()
    return render_to_response('index_page/main_page.html',
            {'gifts': gifts,
             'banners': banners,
             'categories': categories[0],
             'subcategories': categories[1],
             'subcategories_keys': categories[2],
             'price_modif': GlobalPriceModif.get_price_modif()})
示例#13
0
def report_admin(request):
    from kay.utils import render_to_response
    from kay.utils.paginator import Paginator

    version_filter = request.args.get('versions', 'all')
    report_date = request.args.get('date', None)
    if report_date:
        yesterday = datetime.date(*[int(x) for x in report_date.split('-')])
    else:
        yesterday = None

    app_id = os.environ['APPLICATION_ID']
    version = os.environ['CURRENT_VERSION_ID']
    major_version, minor_version = version.rsplit('.', 1)
    minor_version = int(minor_version)

    query_args = {
        'major_version': major_version,
    }
    if yesterday:
        query_args['query_date'] = yesterday

    try:
        exceptions = GetQuery(order='-date', **query_args)
        paginator = Paginator(exceptions, 10)
        page = paginator.page(request.args.get('page', 1))
    except db.NeedIndexError, e:
        logging.warn(e)
        exceptions = GetQuery(**query_args)
        paginator = Paginator(exceptions, 10)
        page = paginator.page(request.args.get('page', 1))
示例#14
0
def report_admin(request):
    from kay.utils import render_to_response
    from kay.utils.paginator import Paginator

    version_filter = request.args.get("versions", "all")
    report_date = request.args.get("date", None)
    if report_date:
        yesterday = datetime.date(*[int(x) for x in report_date.split("-")])
    else:
        yesterday = None

    app_id = os.environ["APPLICATION_ID"]
    version = os.environ["CURRENT_VERSION_ID"]
    major_version, minor_version = version.rsplit(".", 1)
    minor_version = int(minor_version)

    query_args = {"major_version": major_version}
    if yesterday:
        query_args["query_date"] = yesterday

    try:
        exceptions = GetQuery(order="-date", **query_args)
        paginator = Paginator(exceptions, 10)
        page = paginator.page(request.args.get("page", 1))
    except db.NeedIndexError:
        exceptions = GetQuery(**query_args)
        paginator = Paginator(exceptions, 10)
        page = paginator.page(request.args.get("page", 1))

    return render_to_response(
        "ereporter/admin.html",
        {
            "version_filter": version_filter,
            "app_id": app_id,
            "major_version": major_version,
            "exceptions": page.object_list,
            "paginator": paginator,
            "page": page,
        },
    )
示例#15
0
文件: views.py 项目: gmist/f-toy
def cat(request, idx):
    acat = Category.get_by_id(idx)
    if not acat:
        return redirect('/')
    gifts_list = acat.gift_category.order('-rating')
    gifts_list = filter_leftovers(gifts_list)
    paginator = Paginator(gifts_list, 24)
    try:
        page = int(request.args.get('page', 1))
    except ValueError:
        page = 1
    try:
        gifts = paginator.page(page)
    except (EmptyPage, InvalidPage):
        gifts = paginator.page(paginator.num_pages())
    categories = get_cat_subcat()
    return render_to_response('index_page/index.html',
            {'gifts': gifts,
             'categories': categories[0],
             'subcategories': categories[1],
             'subcategories_keys': categories[2],
             'price_modif': GlobalPriceModif.get_price_modif()})
示例#16
0
 def list(self, request, cursor=None):
   self._import_model_if_not()
   self.check_authority(request, OP_LIST)
   q = self.get_query(request)
   try:
       page = int(request.args.get('page','1'))
   except ValueError:
       page = 1
   paginator = Paginator(q,self.entities_per_page)
   try:
       entities = paginator.page(page)
   except (EmptyPage,InvalidPage):
       entities = paginator.page(paginator.num_pages)
   return render_to_response(self.get_template(request, OP_LIST),
                             {'model': self.model_name,
                              'entities': entities.object_list,
                              'message': get_flash(),
                              'current_page':entities.number,
                              'previous_page':entities.previous_page_number,
                              'next_page':entities.next_page_number,
                              'has_next':entities.has_next,
                              'total_pages':entities.paginator.num_pages,
                             },
                             processors=(self.url_processor,))