Exemplo n.º 1
0
def article(request, article_id):
    errors = []
    c = {}
    user_id = request.session.get('user_id', None)
    print 'us_id article = ', user_id
    # request.session['name']

    if user_id is None:
        user_name = None
    else:
        user_name = get_name_user(user_id)
    if request.method == 'POST':
        data = request.POST
        if not data.get('comment', ''):
            errors.append('Write comment!')
        # user_id = list(request.COOKIES['user_id'][2])
        user_id = request.session['user_id']
        add_comment(article_id, user_id, data['comment'])

    # TODO rewrite request in sql_request/select.py
    c['comments'] = get_comments(article_id)
    c['article'] = get_article(article_id)
    c['user_name'] = user_name
    c.update(csrf(request))

    return render_to_response('article.html', c)
Exemplo n.º 2
0
def article(request, article_id):
    errors = []
    c = {}
    user_id = request.session.get('user_id', None)
    if user_id is None:
        user_name = None
    else:
        user_name = get_name_user(user_id)
    if request.method == 'POST':
        data = request.POST
        if not data.get('comment', ''):
            errors.append('Write comment!')
        # user_id = list(request.COOKIES['user_id'][2])
        user_id = request.session['user_id']
        add_comment(article_id, user_id, data['comment'])

    # TODO rewrite request in sql_request/select.py
    cursor = connection.cursor()
    c['comments'] = get_comments(article_id)
    cursor.execute('SELECT * FROM News WHERE News_id = {};'.format(article_id))
    c['article'] = list(cursor.fetchall()[0])
    c['user_name'] = user_name
    c.update(csrf(request))

    return render_to_response('article.html', c)