Exemple #1
0
def format_status(status):
    """Format a status update inside an Atom feed with HTML filters."""
    return markdown(urlize(format_update(status.content_html, status.project)))
Exemple #2
0
def format_status(status):
    """Format a status update inside an Atom feed with HTML filters."""
    return markdown(urlize(format_update(status.content_html, status.project)))
Exemple #3
0
def get_statuses():
    """Get all status updates.

    Returns id, user (the name), project name and timestamp of statuses.

    The amount of items to return is determined by the limit argument (defaults
    to 20):
    /api/v1/feed/?limit=20

    An example of the JSON:

        {
            "1": {
                "user": "******",
                "content": "working on bug 123456",
                "project": "sumodev",
                "timestamp": "2013-01-11T21:13:30.806236"
            }
        }
    """

    limit = request.args.get('limit', 20)
    type = request.args.get('type', 'json')

    statuses = Status.query.filter(Status.reply_to == None). \
             order_by(db.desc(Status.created)).limit(limit)

    if type == 'json':
        data={}
        index = 0
        for row in statuses:
            created = row.created.isoformat()
            try:
                project_name = row.project.name
            except:
                project_name = None
            data[index] = (dict(author=row.user.name, content=markdown(urlize(row.content)),
                             timestamp=created, project=project_name))
            index = index + 1

        #js = jsonify(data)
        json_str = json.dumps(data)
        content = '%s(%s)' % ("func", json_str)
        response = make_response(content)
        response.status_code = 200
        response.content_type = "application/json;charset=utf-8"

        return response

    else:
        feed = AtomFeed('hsgr activity', feed_url=request.url, url=request.url_root)
        for status in statuses:
            title = 'From %s at %s' % (status.user.username,
                                       status.created.strftime('%d/%m/%y %H:%M %Z'))
            content = unicode(markdown(urlize(status.content)))
            summary = unicode(markdown(status.content))
            summary = ''.join(BeautifulSoup(summary).findAll(text=True))
            summary = summary[:128]

            if status.project:
                content = '[%s] %s' % (status.project.name, content)

            feed.add(title=title, content=content, content_type="html", summary=summary,
                     summary_type="text", author=status.user.name,
                     url=absolute_url('/status/%s' % status.id),
                     updated=status.created, published=status.created)

        return feed.get_response()