Пример #1
0
def getfrontpage(page=0):
    """ Get the list of results for the frontpage as a json string"""

    pagesize = 100
    try:

        page = int(page)

    except Exception as e:
        return (jsonify({
            'status': 'error',
            "message": "Error converting page to integer value"
        }))
    stories = []
    #blogs = mongo.db.blog.find({'status':'active','homepage':'yes'}).sort("created",-1)

    collections = mongo.db.collections.find({
        'status': 'active'
    }).sort("created", -1)

    for c in collections:
        photos = mongo.db.photos.find({
            'status': 'active',
            'collection': c['collection'],
            'homepage': 'yes'
        }).sort('displayorder').limit(1)

        for b in photos:

            b['ctitle'] = c['title']
            b['cslug'] = c['slug']
            b['created'] = datetime.strftime(c['created'],
                                             '%Y-%m-%dT%H:%M:%S.%fZ')
            b['summary'] = util.summary_text(c['body'])
            b['type'] = 'photo'
            b.pop('_id')
            stories.append(b)
            break

    articles = mongo.db.articles.find({'status': 'active'}).sort("created", -1)

    for a in articles:
        r = {}
        r['created'] = datetime.strftime(a['created'], '%Y-%m-%dT%H:%M:%S.%fZ')
        r['summary'] = util.summary_text(a['body'])
        r['cslug'] = a['slug']
        r['type'] = 'article'
        r['title'] = a['title']
        r['teaserurl'] = a['teaserurl']
        stories.append(r)

    sorted_stories = sorted(stories, key=lambda x: x['created'], reverse=True)

    lower_bound = page * pagesize
    upper_bound = page * pagesize + (pagesize - 1)

    # Return the slice we are interested in
    return jsonify(sorted_stories[lower_bound:upper_bound])
Пример #2
0
def get_stories(id=None):
    """ Collection Detail Display """
    collection = None

    if id is not None:
        collection = mongo.db.collections.find_one({'slug': id},
                                                   {'_id': False})

        collection['summary'] = util.summary_text(collection['body'])
    if collection is None:
        return redirect(url_for('notfound'))

    photos = mongo.db.photos.find(
        {
            'collection': collection['collection'],
            'status': 'active'
        }, {
            '_id': False
        }).sort('displayorder', 1)

    #collection['summary'] = util.summary_text(collection['body'])
    firstphoto = None
    if photos.count() > 0:
        firstphoto = photos[0]

    return jsonify({
        'collection': collection,
        'photos': list(photos),
        'firstphoto': firstphoto
    })
Пример #3
0
def get_frontpage():
    """ Get the list of results for the frontpage"""

    stories = []
    #blogs = mongo.db.blog.find({'status':'active','homepage':'yes'}).sort("created",-1)

    collections = mongo.db.collections.find({
        'status': 'active'
    }).sort("created", -1)

    for c in collections:
        photos = mongo.db.photos.find({
            'status': 'active',
            'collection': c['collection'],
            'homepage': 'yes'
        }).sort('displayorder').limit(1)

        for b in photos:

            b['ctitle'] = c['title']
            b['cslug'] = c['slug']
            b['created'] = datetime.strftime(c['created'],
                                             '%Y-%m-%dT%H:%M:%S.%fZ')
            b['summary'] = util.summary_text(c['body'])
            b['type'] = 'Story'
            b.pop('_id')
            stories.append(b)
            break

    articles = mongo.db.articles.find({'status': 'active'}).sort("created", -1)

    for a in articles:
        r = {}
        r['created'] = datetime.strftime(a['created'], '%Y-%m-%dT%H:%M:%S.%fZ')
        r['summary'] = util.summary_text(a['body'])
        r['cslug'] = a['slug']
        r['type'] = 'Article'
        r['title'] = a['title']
        r['teaserurl'] = a['teaserurl']
        stories.append(r)

    sorted_stories = sorted(stories, key=lambda x: x['created'], reverse=True)

    return jsonify(sorted_stories)
Пример #4
0
def get_listarticles():
    """ Get the list of articles from the database"""

    articles = mongo.db.articles.find({'status': 'active'}).sort("created", -1)

    new_articles = []
    for article in articles:
        article['summary'] = util.summary_text(article['body'])
        article.pop('_id')
        article['created'] = datetime.strftime(article['created'],
                                               '%Y-%m-%dT%H:%M:%S.%fZ')
        new_articles.append(article)
    return jsonify(new_articles)
Пример #5
0
def get_photo(id=None):
    """
    Photo Detail
    """
    photo = None
    if id is not None:
        photo = mongo.db.photos.find_one({'slug': id}, {'_id': False})
        photo['summary'] = util.summary_text(photo['body'])
        return jsonify(photo)
    #if photo is None:
    #    return jsonify({'error':'No photo found'})

    #image_url = siteconfig.AMAZON_BASE_URL + photo['files']['large']['path']
    #lowrez_url = siteconfig.AMAZON_BASE_URL + photo["files"]['lrlarge']['path']

    photo.pop('_id')
    return jsonify({"error": "No result found"})