当前位置: 首页>>代码示例>>Python>>正文


Python Article.all方法代码示例

本文整理汇总了Python中models.Article.all方法的典型用法代码示例。如果您正苦于以下问题:Python Article.all方法的具体用法?Python Article.all怎么用?Python Article.all使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在models.Article的用法示例。


在下文中一共展示了Article.all方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: index

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def index():
    articles = Article.all()
    if 'email' in session:
        person = Person.query.filter_by(email=session['email']).first()
        name = person.firstname
        return render_template('index.html', articles=articles, name=name)
    return render_template('index.html', articles=articles)
开发者ID:mitchheard,项目名称:mitchheardcom,代码行数:9,代码来源:views.py

示例2: check

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def check():
    q = Article.all()
    q.order("datetime")

    # check_cursor = memcache.get("check_cursor")
    # if check_cursor:
    #     q.with_cursor(start_cursor = check_cursor)

    chunk_size = 30
    articles = q.fetch(chunk_size)

    art_ctr = 0
    l = []
    for article in articles: 
        # if not article.sentiment:
        #     article.analyzed = False
        #     article.put()
        art_ctr += 1
        l.append(".")

    count = len(articles)

    # if len(articles) < chunk_size:
    #     memcache.delete("check_cursor")

    # if check_cursor:
    #     memcache.set("check_cursor",check_cursor, 11000)
    # else:
    #     memcache.add("check_cursor",check_cursor, 11000)

    return [count,art_ctr,unicode(l)]
开发者ID:memius,项目名称:market-analyzer,代码行数:33,代码来源:utils.py

示例3: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
    def get(self):
        query = Article.all().order('-pub_date')
        posts = query.fetch(10)

        rss_items = []
        for post in posts:
            this_link = self.request.host_url + "/posts/" + post.slug
            item = PyRSS2Gen.RSSItem(
                title=post.title,
                link=this_link,
                description=post.body_html,
                guid="",
                pubDate=post.pub_date
            )
            rss_items.append(item)

        rss = PyRSS2Gen.RSS2(
            title=settings['blog_title'],
            link=self.request.host_url,
            description="a blog by " + settings['author'],
            lastBuildDate=datetime.datetime.now(),
            items=rss_items
        )
        rss_xml = rss.to_xml()
        self.response.headers['Content-Type'] = 'application/rss+xml'
        self.response.out.write(rss_xml)
开发者ID:eblahm,项目名称:eblahg,代码行数:28,代码来源:rss.py

示例4: all_sentiment_old_articles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def all_sentiment_old_articles(): 
    q = Article.all()
    q.order("datetime")

#    memcache.delete("ana_old_cursor") #debug only

    ana_old_cursor = memcache.get("ana_old_cursor")
    if ana_old_cursor:
        q.with_cursor(start_cursor = ana_old_cursor)

    chunk_size = 8
    articles = q.fetch(chunk_size)

    for article in articles: 
        if not article.analyzed:
#        if article.clean and not article.sentiment:
            sentiment(article) 
#            article.sentiment = "sugar"


    if len(articles) < chunk_size:
        memcache.delete("ana_old_cursor")

    if ana_old_cursor:
        memcache.set("ana_old_cursor",ana_old_cursor, 11000)
    else:
        memcache.add("ana_old_cursor",ana_old_cursor, 11000)
开发者ID:memius,项目名称:market-analyzer,代码行数:29,代码来源:janitor.py

示例5: index

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def index(page = 1):
    articles = Article.all().paginate(page,app.config['POST_PER_PAGE'],False)
    if 'email' in session:
        person = Person.query.filter_by(email=session['email']).first()
        name = person.firstname
        return render_template('index.html', articles= articles, name=name)
    return render_template('index.html', articles= articles)
开发者ID:mauri84,项目名称:blogtest,代码行数:9,代码来源:views.py

示例6: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
    def get(self):
        was_here = self.get_cookie('was_here', False)
        tweets = self.cache.get("tweets")

        if not was_here:
            self.set_cookie('was_here', '1')
        articles = Article.all({'slug': 'article-pertama'})
        self.render("home", articles=articles, was_here=was_here, tweets=tweets)
开发者ID:apit,项目名称:rinjani,代码行数:10,代码来源:home.py

示例7: all_articles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def all_articles():
#    q = Article.all(keys_only=True) #fetching only the key, not the whole object.
# fetch only the titles, and use them for comparison
    q = Article.all() 
#    q = Article.all(projection=["title"]) funker ikke. feil med syntaks i doku.
    article_keys = q.fetch(10000) # this is just wrong! you are not fetching the keys here.
    duplicates = []
    for article_key in article_keys: # this is also just wrong - never dupe check on keys - they are all different!
        if article_key.title in duplicates:
            db.delete(article_key)
        else:
            duplicates.append(article_key.title)
开发者ID:memius,项目名称:market-analyzer,代码行数:14,代码来源:duplicates.py

示例8: articles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def articles():
    article_keys = memcache.get("article_keys")
    # logging.debug("dupe() article keys: %s", article_keys[:3])
    duplicate_check = memcache.get("duplicate_check") 

# dupe check skal inneholde:
#   i verste fall:
#     alle fra db - hente derfra hvis ingen dupe check
#   i beste fall:
#     de som ble skrapet forrige gang = article keys nå + dupe checks skal lagres som neste dupe check

    delete_ctr = 0
    if article_keys: # lagret av forrige scrape
        # logging.debug("article keys exist in dupes")
        if duplicate_check: # lagret av forrige duplicates
            for article_key in article_keys:
                article = Article.get_by_id(article_key.id())
                if article:
                    if article.title in duplicate_check:
                        db.delete(article)
                        article_keys.remove(article_key)
                        delete_ctr += 1
                    else:
                        duplicate_check.append(article.title)
            memcache.set("duplicate_check", duplicate_check)
            memcache.set("article_keys", article_keys, 7200)
        else:
            q = Article.all(keys_only=True)
            # q.order("datetime") no datetime on keys
            keys = q.fetch(500)
            duplicate_check = []
            for key in keys:
                article = Article.get_by_id(key.id())
                duplicate_check.append(article.title)

            for article_key in article_keys:

                article = Article.get_by_id(key.id())
                if article:
                    if article.title in duplicate_check: 
                        db.delete(article)
                        article_keys.remove(article_key)
                        delete_ctr += 1
                    else:
                        duplicate_check.append(article.title)
            memcache.set("duplicate_check", article_keys, 7200)
            memcache.set("article_keys", article_keys, 7200)
    elif duplicate_check:
        # logging.debug("article keys do NOT exist in dupes")
        memcache.set("duplicate_check", duplicate_check, 7200)

    logging.debug("deleted %s duplicate articles", delete_ctr)
开发者ID:memius,项目名称:market-analyzer,代码行数:54,代码来源:duplicates.py

示例9: settings

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def settings():
    articles = Article.all()
    if 'email' in session:
        person = Person.query.filter_by(email=session['email']).first()
        form = PersonUpdateForm(request.form, person)
        name = person.firstname
        if form.validate_on_submit():
            form.populate_obj(person)
            db.session.merge(person)
            db.session.commit()
            return render_template('index.html', articles=articles)
        return render_template('settings.html', form=form, name=name)
    return render_template('index.html', articles=articles)
开发者ID:mitchheard,项目名称:mitchheardcom,代码行数:15,代码来源:views.py

示例10: create_article

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def create_article(request):

    articles = Article.all()

    if request.method == "POST":
        form = ArticleForm(request.POST)

        if form.is_valid():
            article = Article(title=form.cleaned_data['title'],
                              body=form.cleaned_data['body'])
            article.put()
            messages.success(request, 'Article created successful')
            return redirect('create_article')

    return render_to_response('create_article.html', dict(articles=articles))
开发者ID:paktek123,项目名称:article-blog,代码行数:17,代码来源:views.py

示例11: update_article

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def update_article(request, article_id):

    article = Article.get_by_id(int(article_id))
    articles = Article.all()

    if request.method == "POST":
        form = ArticleForm(request.POST)

        if form.is_valid():
            article.title = form.cleaned_data['title']
            article.body = form.cleaned_data['body']
            article.put()
            messages.success(request, 'Article updated successfully')
            return redirect('create_article')

    return render_to_response('create_article.html', dict(articles=articles, article=article, form_action="edit"))
开发者ID:paktek123,项目名称:article-blog,代码行数:18,代码来源:views.py

示例12: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
  def get(self):
    path = self.request.path.replace('citeulike/', '')
    url = 'http://www.citeulike.org' + path
    socket = urllib.urlopen(url)

    # Build template
    template = Template(open('views/page.html').read())
    attrs = citeulike.page_metadata(socket.read(), url)
    attrs['views'] = Article.all().filter("id =", self.request.path).count()
    s = template.render_unicode(attributes=attrs)

    # Render the page
    self.response.out.write(template.render_unicode(attributes=attrs))

    # Record that this article has been viewed
    article = Article(id=self.request.path, last_viewed=datetime.now())
    article.put()
开发者ID:mreid,项目名称:annotatr,代码行数:19,代码来源:main.py

示例13: get

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
    def get(self):
        """
        Simple offset-based endless json/jsonp feed
        """

        articles = Article.all().filter('publish_state = ', True)\

        if self.request.get('start') and self.request.get('end'):
            articles = articles.filter('publish_date >=',
                                       datetime.strptime(self.request.get('start'), '%d/%m/%Y')
                              ).filter('publish_date <=',
                                       datetime.strptime(self.request.get('end'), '%d/%m/%Y'))

        articles = articles.order('-publish_date').fetch(10, offset=int(self.request.get('offset', 0)))
        articles = [to_dict(item) for item in articles]

        callback = self.request.get('callback')
        if callback:
            self.jsonp_response(articles, callback)
        else:
            self.json_response(articles)
开发者ID:stachern,项目名称:bseu_news,代码行数:23,代码来源:feed.py

示例14: add_article

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def add_article():
    """Add a article."""
    form = ArticleForm()
    if request.method == 'POST':
        if form.validate_on_submit():
            # Get the right number - the article ID
            number = 1
            articles = Article.all().order('-number')
            if articles.count() > 0:
                number = articles[0].number + 1

            article = Article(
                number=number,
                title=form.title.data,
                content=form.content.data,
                tags=form.tags.data,
                is_public=form.is_public.data,
            )
            article.save()
            return redirect(article.get_absolute_url())
    action_url = url_for('add_article')
    return render_template('add_article.html', form=form, action_url=action_url)
开发者ID:mitnk,项目名称:justablog,代码行数:24,代码来源:views.py

示例15: check_all_articles

# 需要导入模块: from models import Article [as 别名]
# 或者: from models.Article import all [as 别名]
def check_all_articles():
    q = Article.all(keys_only=True)
    # q.order("datetime") no datetime in keys
    article_keys = q.fetch(10000)

    # maintenance = memcache.get("maintenance")
    # if maintenance:
    #     article = maintenance.pop() # last element is removed in place
    #     check(article)
    #     memcache.set("maintenance", maintenance)
    # else:
    #     q = Article.all().filter("clean =", None) # now, it doesn't check those with clean == True!
    #     articles = q.fetch(8)
    #     memcache.add("articles", articles)

    duplicates = []
    changed_ctr = 0
    dupe_ctr = 0
    for key in article_keys:
        article = Article().get_by_id(key.id())
        if article == None:
            if article.title in duplicates:
                db.delete(article)
                dupe_ctr += 1
            else:
                duplicates.append(article.title)
                changed = check(article)
                if changed:
                    changed_ctr += 1

        

    logging.debug("janitored %s articles", changed_ctr)
    logging.debug("janitor dupe removed %s articles", dupe_ctr)
    article_keys = memcache.get("article_keys")
    if article_keys and len(article_keys) > 1000:
        memcache.set("article_keys", article_keys[:500])
开发者ID:memius,项目名称:market-analyzer,代码行数:39,代码来源:janitor.py


注:本文中的models.Article.all方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。