Exemple #1
0
def get_vcf_comments(vcf_id):
    """Return all user comments in the following format:

    {
      "comments": {
        "<row_key STRING>": [<comment_fields>, ...],
        "<row_key STRING>": [...], ...
      }
    }
    """
    def _row_key(comment, table):
        cols = ['contig', 'position', 'reference', 'alternates', 'sample_name']
        return ':'.join([str(comment[col]) for col in cols])

    with tables(db.engine, 'user_comments') as (conn, user_comments):
        cols = user_comments.c
        stmt = select(cols.values()).where(cols.vcf_id == vcf_id)
        results = conn.execute(stmt)
        results_map = defaultdict(list)
        for comment in (dict(c) for c in results):
            row_key = _row_key(comment, user_comments)
            comment['last_modified'] = to_epoch(comment['last_modified'])
            comment['created'] = to_epoch(comment['created'])
            comment = camelcase_dict(comment)
            results_map[row_key].append(comment)
    return {'comments': results_map}
Exemple #2
0
 def wrapper(*args, **kwargs):
     resp = f(*args, **kwargs)
     if not isinstance(resp, tuple):
         content = resp
         resp = (content, 200, {})
     content = marshal(resp[0], schema, envelope=envelope)
     content = camelcase_dict(content)
     return (content,) + resp[1:]
Exemple #3
0
def get_last_comments(n=5):
    """Return list of the last `n` comments."""
    with tables(db.engine, 'user_comments') as (con, user_comments):
        cols = user_comments.c
        q = select(cols.values()).order_by(
            desc(cols.created)).limit(n)
        comments = [camelcase_dict(dict(c)) for c in con.execute(q).fetchall()]
    return epochify_comments(comments)
Exemple #4
0
def comments():
    with tables(db.engine, 'user_comments') as (con, comments):
        comments = comments.select().order_by(desc(comments.c.id))
        comments = [camelcase_dict(dict(c))
                    for c in comments.execute().fetchall()]
        comments = cycledash.api.comments.epochify_comments(comments)
        comments = cycledash.api.comments.add_user_to_comments(comments)
    return render_template('comments.html', comments=comments)