Exemplo n.º 1
0
def index():
    # Try login, try cookies, else return template
    resp = login_or_register() or login_cookies()
    if resp:
        resp, user = resp
        # If there is a comment, create a new one
        comment_content = request.values.get("comment")
        if comment_content:
            Comment.new_comment(int(request.values.get("post-id")), user.name,
                                comment_content)

        return resp

    return render_template("index.html", config=Config.config)
Exemplo n.º 2
0
def reports_by_group_id(group_id):
    edges = []
    nodes = []
    index = {}
    _in = defaultdict(int)
    _out = defaultdict(int)
    ids =  user_id_by_group_id(group_id)
    for n,i in enumerate(ids):
        index[i] = n
    for user_id in ids:
        user = get_user(user_id)
        if Blog.get(user_id=user_id):
            #blog_id = Blog.get(user_id=user_id).id
            author_id = get_author_id_by_user_id(user_id)
            comments = Comment.where(author_id=author_id)
            counts = count_in(comments, user_id, ids, _in, _out)
            for i, j in counts.iteritems():
                target = get_user(i)
                edge = {'source': index[user_id],
                        'target': index[i],
                        'value': j,
                        }
                edges.append(edge)

    nodes = [
            {   'name': get_user(i).name,
                'in': _in[i],
                'out': _out[i],
                'weight': _in[i]+_out[i],
                'index': n,
                'id':i,
                 }
            for n,i in enumerate(ids)
            ] 
    return {'nodes': nodes, 'links': edges}
Exemplo n.º 3
0
def count_in(comments, user_id, ids, _in, _out):
    res = {}
    for comment in comments:
        _a = get_user_id_by_blog_id(comment.blog_id)
        _t = None
        if comment.reply_to:
            _comment = Comment.get(comment.reply_to)
            _t = get_user_id_by_author_id(_comment.author_id)
        _t = _t or _a
        if _t and _t <> user_id and _t in ids:
            _out[user_id] += 1
            _in[_t] += 1
            if _t in res:
                res[_t] += 1
            else:
                res[_t] = 1
    return res
Exemplo n.º 4
0
from blog import Blogpost, Comment
from time import sleep

print(
    '\n============================================================================'
)
blogpost = Blogpost('Bill Gates', 'Unix sux!',
                    'bla bla bla! \nWindows rulez_!')
print(blogpost)
print(blogpost.strComments())
sleep(1)

print(
    '\n============================================================================'
)
blogpost.addComment(Comment('Linus Torvalds', 'You is stupid! Agrh!!'))
print(blogpost)
print(blogpost.strComments())
sleep(1)

print(
    '\n============================================================================'
)
blogpost.addComment(Comment('Денис Попов', 'Зато в линуксе не скучные обои!'))
print(blogpost)
print(blogpost.strComments())