Esempio n. 1
0
def main():
    import getPop, jsonify

    fn = './data/N40W074.hgt'
    siz = os.path.getsize(fn)
    dim = int(math.sqrt(siz / 2))
    assert dim * dim * 2 == siz, 'Invalid file size'
    data = numpy.fromfile(fn, numpy.dtype('>i2'), dim * dim).reshape(
        (dim, dim))
    floodMap = hgtMap(data.tolist())

    floodStartLocation = floodMap.latLongToPointApprox(40.366, -73.88)
    userSelectedIntensity = 5  # provided by user (frontend)
    floodLitres = (10**6) * (userSelectedIntensity**2)
    floodMap.minFloodHeight = 100
    floodMap.setWater(floodStartLocation[0], floodStartLocation[1],
                      floodLitres)
    mins = 5
    tickInterations = mins
    for _ in range(tickInterations):
        floodMap = tick(floodMap)

    pmap = getPop.getPopulation(floodMap)
    totalPop = getPop.totalPop(pmap)
    jsonify.jsonify(floodMap, pmap, totalPop)
Esempio n. 2
0
def test_basic():
    for v in [
        1, 1.0, 'foo', u'bar',
        [1, 2], 
        {'a': 1, 'b': 2}]:
        assert jsonify(v) == v
    assert jsonify((1, 'a', {'b': 2})) == [
        1, 'a', {'b': 2}]
Esempio n. 3
0
    def get(self):
        user = users.get_current_user()
        logging.info("Debug User: '******'")
        if user:
            user_data = models.UserData.get_for_user_id(user.user_id())
            # TODO(chris): remove this hack! We added email to
            # UserData, and it's required, so this ensures that on the
            # next page load, UserData will be updated properly.
            if user_data.email is None:
                logging.info("Added %s for UserData %s"
                             % (user.email(), user_data.key.urlsafe()))
                user_data.email = user.email()
                user_data.put()
        else:
            user_data = None

        if user_data:
            user_cards, global_cards = yield ((
                models.Card
                    .query(models.Card.user_key ==
                        ndb.Key(urlsafe=user_data.key.urlsafe()))
                    .order(models.Card.next_review)
                    .fetch_async(500)),
                models.Card
                    .query()
                    .order(-models.Card.added)
                    .fetch_async(500),
                )
            following_keys = [k.urlsafe() for k in user_data.following]
            user_key = user_data.key.urlsafe()
            username = str(user)
            user_nickname = user_data.nickname
            user_email = user_data.email
        else:
            user_cards = []
            global_cards = (models.Card
                .query().order(-models.Card.added).fetch(1000))
            following_keys = []
            user_key = None
            username = None
            user_nickname = None
            user_email = None

        template = JINJA_ENVIRONMENT.get_template('index.html')
        env = {
            'user': user_data,
            'user_key': user_key,
            'user_nickname': user_nickname,
            'user_email': user_email,
            'username': json.dumps(username),
            'following_keys': jsonify.jsonify(following_keys),
            'users': users,
            'user_cards': jsonify.jsonify(user_cards),
            'global_cards': jsonify.jsonify(global_cards),
        }
        self.response.write(template.render(env))
Esempio n. 4
0
    def get(self):
        user = users.get_current_user()
        logging.info("Debug User: '******'")
        if user:
            user_data = models.UserData.get_for_user_id(user.user_id())
            # TODO(chris): remove this hack! We added email to
            # UserData, and it's required, so this ensures that on the
            # next page load, UserData will be updated properly.
            if user_data.email is None:
                logging.info("Added %s for UserData %s" %
                             (user.email(), user_data.key.urlsafe()))
                user_data.email = user.email()
                user_data.put()
        else:
            user_data = None

        if user_data:
            user_cards, global_cards = yield (
                (models.Card.query(models.Card.user_key == ndb.Key(
                    urlsafe=user_data.key.urlsafe())).order(
                        models.Card.next_review).fetch_async(500)),
                models.Card.query().order(-models.Card.added).fetch_async(500),
            )
            following_keys = [k.urlsafe() for k in user_data.following]
            user_key = user_data.key.urlsafe()
            username = str(user)
            user_nickname = user_data.nickname
            user_email = user_data.email
        else:
            user_cards = []
            global_cards = (
                models.Card.query().order(-models.Card.added).fetch(1000))
            following_keys = []
            user_key = None
            username = None
            user_nickname = None
            user_email = None

        template = JINJA_ENVIRONMENT.get_template('index.html')
        env = {
            'user': user_data,
            'user_key': user_key,
            'user_nickname': user_nickname,
            'user_email': user_email,
            'username': json.dumps(username),
            'following_keys': jsonify.jsonify(following_keys),
            'users': users,
            'user_cards': jsonify.jsonify(user_cards),
            'global_cards': jsonify.jsonify(global_cards),
        }
        self.response.write(template.render(env))
def handle_coc_exception(error):
    # Log our own exceptions at error level (no need for stack trace, these are "expected"
    if isinstance(error, COCException):
        app.logger.error("COCException guid={0} msg={1} user_msg={2}".format(
            error.guid, error.message, error.user_message))
        response = jsonify(error.to_dict())
    else:
        app.logger.exception(error)
        response = jsonify({
            "success": False,
            "message": "There was an error on the server."
        })

    return response
Esempio n. 6
0
def create_quote_resp_json(quote, body_valid, tags_valid): 
    error = { 'error': 'validation', 'error_msg': '' }
    if not body_valid:
        error['error_msg'] += 'Body too large'
    if not tags_valid:
        error['error_msg'] += 'Tags too large'
    if not body_valid or not tags_valid:
        rs = jsonify(error, 'application/vnd.pyqdb-error+json')
        rs.status_code = 413
        return rs
     
    rs = jsonify(quote, Quote.json_mimetype)
    add_loc_hdr(rs, '/quotes/%s' % (quote.id))
    rs.status_code = 201
    return rs 
Esempio n. 7
0
def create_quote_resp_json(quote, body_valid, tags_valid):
    error = {'error': 'validation', 'error_msg': ''}
    if not body_valid:
        error['error_msg'] += 'Body too large'
    if not tags_valid:
        error['error_msg'] += 'Tags too large'
    if not body_valid or not tags_valid:
        rs = jsonify(error, 'application/vnd.pyqdb-error+json')
        rs.status_code = 413
        return rs

    rs = jsonify(quote, Quote.json_mimetype)
    add_loc_hdr(rs, '/quotes/%s' % (quote.id))
    rs.status_code = 201
    return rs
Esempio n. 8
0
def latest():
    incr, start, next, prev = parse_qs(request.args)
    quotes = db.latest(incr, start)
    admin = authDB.isAuthenticated(request)
    if request.wants_json():
        next_link = '/quotes?start=%s' % (next)
        prev_link = '/quotes?start=%s' % (prev)
        json = {
            'quotes':
            quotes,
            'links': [
                build_link(next_link, 'pyqdb/quotes/next',
                           Quote.list_json_mimetype),
                build_link(prev_link, 'pyqdb/quotes/prev',
                           Quote.list_json_mimetype)
            ]
        }
        rs = jsonify(json, Quote.list_json_mimetype)
        add_link_hdr(rs, next_link, 'pyqdb/quotes/next')
        if start > 0:
            add_link_hdr(rs, prev_link, 'pyqdb/quotes/prev')
        return rs
    return render_template('quotes.html',
                           nav=navs,
                           quotes=quotes,
                           page='quotes',
                           next=next,
                           prev=prev,
                           isAdmin=admin)
Esempio n. 9
0
 def to_json(self):
     archive = {
         "format": "JSONCardArchive",
         "version": self.VERSION,
         "cards": map(self._card_to_archive_card, self.cards),
     }
     return jsonify.jsonify(archive)
Esempio n. 10
0
def user_follows(handler):
    """Get the users followed by and following a certain users.

    Called via a route like:
    /api/user/<user_key>/follows
    """
    path = handler.request.path

    user_key = path[len('/api/user/'):-len('/follows')]
    user_data = ndb.Key(urlsafe=user_key).get()
    if not user_data:
        return "User not found"

    # TODO make async
    following_data = ndb.get_multi(user_data.following)
    followers_data = ndb.get_multi(user_data.followers)

    # Finally ready to do the update
    data = {
        'user_data': user_data,
        'following': following_data,
        'followers': followers_data
    }

    return jsonify.jsonify(data)
Esempio n. 11
0
def user_follows(handler):
    """Get the users followed by and following a certain users.

    Called via a route like:
    /api/user/<user_key>/follows
    """
    path = handler.request.path

    user_key = path[len('/api/user/'):-len('/follows')]
    user_data = ndb.Key(urlsafe=user_key).get()
    if not user_data:
        return "User not found"

    # TODO make async
    following_data = ndb.get_multi(user_data.following)
    followers_data = ndb.get_multi(user_data.followers)

    # Finally ready to do the update
    data = {
        'user_data': user_data,
        'following': following_data,
        'followers': followers_data
    }

    return jsonify.jsonify(data)
Esempio n. 12
0
def log_client_message():
    log_message = request.get_json()
    message = log_message['message']
    level = log_message['level']
    client_logging_service.log(message, level)

    return jsonify({"success": True})
Esempio n. 13
0
def welcome():
    if request.wants_json():
        links = navs
        links.append(build_link('/', 'self', 'application/json'))
        root = {'version': '0.1', 'title': 'VT Bash', 'links': links}
        return jsonify(root, 'application/json')
    news = News()
    return render_template('index.html', nav=navs, news=news.news)
Esempio n. 14
0
def welcome():
    if request.wants_json():
        links = navs
        links.append(build_link('/', 'self', 'application/json'))
        root = { 'version': '0.1',
                 'title': 'VT Bash',
                 'links': links }
        return jsonify(root, 'application/json')
    news = News()
    return render_template('index.html', nav=navs, news=news.news)
Esempio n. 15
0
    def get(self):
        user = users.get_current_user()
        logging.info("Debug User: '******'")
        if user:
            user_data = models.UserData.get_for_user_id(user.user_id())
        else:
            user_data = None

        if user_data:
            user_cards, global_cards = yield ((
                models.Card
                    .query(models.Card.user_key ==
                        ndb.Key(urlsafe=user_data.key.urlsafe()))
                    .order(models.Card.next_review)
                    .fetch_async(500)),
                models.Card
                    .query()
                    .order(-models.Card.added)
                    .fetch_async(500),
                )
            following_keys = [k.urlsafe() for k in user_data.following]
        else:
            user_cards = []
            global_cards = (models.Card
                .query().order(-models.Card.added).fetch(1000))
            following_keys = []

        if user_data:
            username = str(user)
        else:
            username = None

        template = JINJA_ENVIRONMENT.get_template('index.html')
        env = {
            'user': user_data,
            'username': json.dumps(username),
            'following_keys': jsonify.jsonify(following_keys),
            'users': users,
            'user_cards': jsonify.jsonify(user_cards),
            'global_cards': jsonify.jsonify(global_cards),
        }
        self.response.write(template.render(env))
Esempio n. 16
0
File: api.py Progetto: MattFaus/ssrs
def card_search(handler):
    """Search cards with query parameter "q".

    Returns a (possibly empty) list of JSONified models.Card
    entities. See search.py for query processing details.
    """
    query = handler.request.get('q', '')
    search_results = search.query_cards(query, limit=20, ids_only=True)
    results = ndb.get_multi([ndb.Key(urlsafe=result.doc_id)
                             for result in search_results])
    return jsonify.jsonify(results)
Esempio n. 17
0
def fetch_votes(quote_id):
    quote = db.get(quote_id)
    if quote is None:
        abort(404)
    json = { 'links': [ 
                        build_link('/quotes/%s' %(quote_id), 'pyqdb/quote', Quote.json_mimetype),
                        build_link('/quotes/%s/votes' %(quote_id), 'pyqdb/quote/cast-vote', Vote.json_mimetype, method='put') ],
              'type': '', # up or down
              'id': quote_id
    }
    return jsonify(json, Vote.json_mimetype)
Esempio n. 18
0
def get_content_list():
    app.logger.info("get_content_list()")

    content_service = ContentService()
    content_list = content_service.get_content_list()

    ret = {
        "success": True,
        "content": content_list
    }

    return jsonify(ret)
Esempio n. 19
0
def get_content(content_id):
    app.logger.info("get_content() - content_id={0}".format(content_id))

    content_service = ContentService()
    content = content_service.get_content(content_id)

    ret = {
        "success": True,
        "html": content['html']
    }

    return jsonify(ret)
Esempio n. 20
0
def get_posts():
    app.logger.info("get_posts()")

    blog_posts_service = BlogPostsService()
    posts = blog_posts_service.get_posts()

    ret = {
        "success": True,
        "posts": posts
    }

    return jsonify(ret)
Esempio n. 21
0
def entity_view(handler, route_root):
    """Query for a single entity by Key."""
    path = handler.request.path
    response = '{}'

    if not path.startswith(route_root) and len(path) > len(route_root):
        return response

    entity_key = path[len(route_root):]
    entity = ndb.Key(urlsafe=entity_key).get()
    if entity:
        response = jsonify.jsonify(entity, pretty_print=True)

    return response
Esempio n. 22
0
File: api.py Progetto: MattFaus/ssrs
def entity_view(handler, route_root):
    """Query for a single entity by Key."""
    path = handler.request.path
    response = '{}'

    if not path.startswith(route_root) and len(path) > len(route_root):
        return response

    entity_key = path[len(route_root):]
    entity = ndb.Key(urlsafe=entity_key).get()
    if entity:
        response = jsonify.jsonify(entity, pretty_print=True)

    return response
Esempio n. 23
0
def update_content():
    content_data = request.get_json()
    app.logger.info("update_content() - data={0}".format(content_data))

    content_id = content_data['content_id']
    html = content_data['html']

    content_service = ContentService()
    success = content_service.update_content(content_id, html)

    ret = {
        "success": success
    }

    return jsonify(ret)
Esempio n. 24
0
def new_quote():
    if request.wants_json():
        rs = jsonify(
            {
                'body':
                "Quote here",
                'tags': [],
                'link':
                build_link('/quotes',
                           'pyqdb/quote/new',
                           Quote.json_mimetype,
                           method='post',
                           title='Create a new quote')
            }, Quote.json_mimetype)
        add_link_hdr(rs, '/quotes', 'pyqdb/quote/new')
        return rs
    return render_template('submit.html', nav=navs)
Esempio n. 25
0
def cast_vote(quote_id):
    ip = request.remote_addr
    quote = db.get(quote_id)
    if quote is None:
        abort(404)
    if request.provided_json():
        return json_nyi()
    else:
        type = request.form['type']

    if type == "up":
        quote = db.up_vote(quote_id, ip)
    elif type == "down":
        quote = db.down_vote(quote_id, ip)
    else:
        abort(400)
    return jsonify(quote, Quote.json_mimetype)
Esempio n. 26
0
def latest():
    incr,start,next,prev = parse_qs(request.args)
    quotes = db.latest(incr, start)
    admin = authDB.isAuthenticated(request)
    if request.wants_json():
        next_link = '/quotes?start=%s' % (next)
        prev_link = '/quotes?start=%s' % (prev)
        json = {'quotes': quotes, 'links': [ 
            build_link(next_link, 'pyqdb/quotes/next', Quote.list_json_mimetype),
            build_link(prev_link, 'pyqdb/quotes/prev', Quote.list_json_mimetype) ]
        }
        rs = jsonify(json, Quote.list_json_mimetype)
        add_link_hdr(rs, next_link, 'pyqdb/quotes/next')
        if start > 0:
            add_link_hdr(rs, prev_link, 'pyqdb/quotes/prev')
        return rs
    return render_template('quotes.html', nav=navs, quotes=quotes, page='quotes', next=next, prev=prev, isAdmin=admin)
Esempio n. 27
0
def cast_vote(quote_id):
    ip = request.remote_addr
    quote = db.get(quote_id)
    if quote is None:
        abort(404)
    if request.provided_json():
        return json_nyi()
    else:
        type = request.form['type']

    if type == "up":
        quote = db.up_vote(quote_id, ip)
    elif type == "down":
        quote = db.down_vote(quote_id, ip)
    else:
        abort(400)
    return jsonify(quote, Quote.json_mimetype)
Esempio n. 28
0
def authenticate():
    post_data = request.get_json()
    app.logger.info("authenticate() - {0}".format(post_data))

    username = post_data['username']
    password = post_data['password']
    session = authentication_service.authenticate(username, password)

    if session is None:
        raise COCException("Failed to authenticate.")
    else:
        ret = {
            "success": True,
            "token": session['token'],
            "expires": session['expires']
        }

    return jsonify(ret)
Esempio n. 29
0
def card_search(handler):
    """Search cards with query parameter "q".

    Returns a (possibly empty) list of JSONified models.Card
    entities. See search.py for query processing details.
    """
    user = users.get_current_user()
    if user:
        user_data = models.UserData.get_for_user_id(user.user_id())
        user_key = user_data.key.urlsafe()
    else:
        user_key = None

    query = handler.request.get('q', '')
    search_results = search.query_cards(query, limit=20, ids_only=True,
            user_key=user_key)
    results = ndb.get_multi([ndb.Key(urlsafe=result.doc_id)
                             for result in search_results])
    return jsonify.jsonify(results)
Esempio n. 30
0
def fetch_votes(quote_id):
    quote = db.get(quote_id)
    if quote is None:
        abort(404)
    json = {
        'links': [
            build_link('/quotes/%s' % (quote_id), 'pyqdb/quote',
                       Quote.json_mimetype),
            build_link('/quotes/%s/votes' % (quote_id),
                       'pyqdb/quote/cast-vote',
                       Vote.json_mimetype,
                       method='put')
        ],
        'type':
        '',  # up or down
        'id':
        quote_id
    }
    return jsonify(json, Vote.json_mimetype)
Esempio n. 31
0
def add_post():
    post_data = request.get_json()
    app.logger.info("add_post() - {0}".format(post_data))

    title = post_data['title']
    summary = post_data['summary']
    html = post_data['html']
    tags = post_data['tags']
    iso_date_string = post_data['date']
    date_object = dateutil.parser.parse(iso_date_string)

    blog_posts_service = BlogPostsService()
    post_id = blog_posts_service.add_post(title, summary, html, tags, date_object)

    ret = {
        "success": True,
        "post_id": post_id
    }

    return jsonify(ret)
Esempio n. 32
0
def card_search(handler):
    """Search cards with query parameter "q".

    Returns a (possibly empty) list of JSONified models.Card
    entities. See search.py for query processing details.
    """
    user = users.get_current_user()
    if user:
        user_data = models.UserData.get_for_user_id(user.user_id())
        user_key = user_data.key.urlsafe()
    else:
        user_key = None

    query = handler.request.get('q', '')
    search_results = search.query_cards(query,
                                        limit=20,
                                        ids_only=True,
                                        user_key=user_key)
    results = ndb.get_multi(
        [ndb.Key(urlsafe=result.doc_id) for result in search_results])
    return jsonify.jsonify(results)
Esempio n. 33
0
def test_explicit():
    e = Expl('foo', 'a')
    result = {'name': 'foo', 'objs': ['a']}
    assert jsonify(e) == result
    assert jsonify([e]) == [result]
Esempio n. 34
0
def encode(object):
    return SafeString(base64.standard_b64encode(jsonify(object)))
Esempio n. 35
0
def card_query(handler):
    """Query for multiple cards.

    See main.py for usage examples.

    TODO(jace): return a query cursor, too?
    """

    tag = handler.request.get("tag", None)
    tag_list = tag.split(',') if tag else None
    review = handler.request.get('review', None)
    reviewAll = handler.request.get('reviewAll', False)
    include_followers = handler.request.get('include_followers', None)
    user_key = handler.request.get('user', None)

    if review and user_key:
        handler.error(400)
        return "'review' and 'user_key' cannot be used together."

    if review and include_followers:
        handler.error(400)
        return "'review' and 'include_followers' cannot be used together."

    if include_followers and not user_key:
        handler.error(400)
        return "'review' and 'include_followers' cannot be used together."

    if review:
        # if asked for review cards, get them for the current user only
        current_user = get_current_user(handler)
        if not current_user:
            handler.error(400)
            return "must be logged in to quer for review cards."
        user_key = current_user.key.urlsafe()

    query = models.Card.query()

    if include_followers:
        user_data = ndb.Key(urlsafe=user_key).get()
        if not user_data:
            handler.error(500)
            return "UserData not found."
        user_list = user_data.following + [ndb.Key(urlsafe=user_key)]
        query = query.filter(models.Card.user_key.IN(user_list))
    elif user_key:
        query = query.filter(models.Card.user_key == ndb.Key(urlsafe=user_key))

    if tag_list:
        query = query.filter(models.Card.tags.IN(tag_list))

    if review:
        # For review mode, we sort by next scheduled review
        query = query.order(models.Card.next_review)
    else:
        query = query.order(-models.Card.added)

    results = query.fetch(100)

    response = '[]'
    if results:
        if review and not reviewAll:
            # TODO(jace) if the current user is asking for review cards but
            # hasn't explicitly asked to review ALL cards, then we truncate
            # the results to include just cards scheduled on or before
            # today... the future can wait.
            now = datetime.datetime.now()
            results = [card for card in results if card.next_review <= now]

        response = jsonify.jsonify(results, pretty_print=True)

    return response
Esempio n. 36
0
def user_view_current(handler):
    """Return information about the currently logged in user."""
    return jsonify.jsonify(users.get_current_user())
Esempio n. 37
0
def tags():
    format = request.args.get('format', 'html')
    if request.wants_json():
        return jsonify(db.tags(), Tag.list_json_mimetype)
    return render_template('tags.html', nav=navs)
Esempio n. 38
0
def json_nyi():
    json_error = {'error': 'nyi', 'error_msg': 'search not yet implemented'}
    rs = jsonify(json_error, 'application/vnd.pyqdb-error+json')
    rs.status_code = 501
    return rs
Esempio n. 39
0
File: api.py Progetto: MattFaus/ssrs
def card_query(handler):
    """Query for multiple cards.

    See main.py for usage examples.

    TODO(jace): return a query cursor, too?
    """

    tag = handler.request.get("tag", None)
    tag_list = tag.split(',') if tag else None
    review = handler.request.get('review', None)
    reviewAll = handler.request.get('reviewAll', False)
    include_followers = handler.request.get('include_followers', None)
    user_key = handler.request.get('user', None)

    if review and user_key:
        handler.error(400)
        return "'review' and 'user_key' cannot be used together."

    if review and include_followers:
        handler.error(400)
        return "'review' and 'include_followers' cannot be used together."

    if include_followers and not user_key:
        handler.error(400)
        return "'review' and 'include_followers' cannot be used together."


    if review:
        # if asked for review cards, get them for the current user only
        current_user = get_current_user(handler)
        if not current_user:
            handler.error(400)
            return "must be logged in to quer for review cards."
        user_key = current_user.key.urlsafe()


    query = models.Card.query()

    if include_followers:
        user_data = ndb.Key(urlsafe=user_key).get()
        if not user_data:
            handler.error(500)
            return "UserData not found."
        user_list = user_data.following + [ndb.Key(urlsafe=user_key)]
        query = query.filter(models.Card.user_key.IN(user_list))
    elif user_key:
        query = query.filter(models.Card.user_key == ndb.Key(urlsafe=user_key))

    if tag_list:
        query = query.filter(models.Card.tags.IN(tag_list))

    if review:
        # For review mode, we sort by next scheduled review
        query = query.order(models.Card.next_review)
    else:
        query = query.order(-models.Card.added)

    results = query.fetch(100)

    response = '[]'
    if results:
        if review and not reviewAll:
            # TODO(jace) if the current user is asking for review cards but
            # hasn't explicitly asked to review ALL cards, then we truncate
            # the results to include just cards scheduled on or before
            # today... the future can wait.
            logging.error("Attempting to truncate review list")
            now = datetime.datetime.now()
            results = [card for card in results if card.next_review <= now]

        response = jsonify.jsonify(results, pretty_print=True)

    return response
Esempio n. 40
0
 def return_json(self, data):
     data_json = jsonify.jsonify(data, camel_cased=True)
     self.response.headers['Content-Type'] = 'application/json'
     self.response.out.write(data_json)
Esempio n. 41
0
def new_quote():
    if request.wants_json():
        rs = jsonify({'body': "Quote here", 'tags': [], 'link': build_link('/quotes', 'pyqdb/quote/new', Quote.json_mimetype, method='post', title='Create a new quote')}, Quote.json_mimetype)
        add_link_hdr(rs, '/quotes', 'pyqdb/quote/new')
        return rs
    return render_template('submit.html', nav=navs)
Esempio n. 42
0
def images():
    return jsonify(list(get_pictures(page=int(request.args.get('page', 1)))))
Esempio n. 43
0
def test_explicit():
    assert jsonify(State(name='Illinois', abbr='IL')) == 'Illinois'
Esempio n. 44
0
def tags():
    format = request.args.get('format', 'html')
    if request.wants_json():
        return jsonify( db.tags(), Tag.list_json_mimetype )
    return render_template('tags.html', nav=navs)
Esempio n. 45
0
 def __json__(self):
     return {
         'name': self.name,
         'objs': [jsonify(o) for o in self.objs]}
Esempio n. 46
0
def test_sqlobject():
    f = Foo(name='foo')
    b = Bar(name='bar', value=1, foo=f)
    assert jsonify(f) == {'name': 'foo', 'id': f.id}
    assert jsonify(b) == {'name': 'bar', 'value': 1,
                          'fooID': f.id, 'id': b.id}