Esempio n. 1
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)
Esempio n. 2
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)
Esempio n. 3
0
def index(request):
    header = 'Header!'
    user_id = request.session.get('user_id', None)
    if user_id is None:
        user_name = None
    else:
        user_name = get_name_user(user_id)
    data = get_news()
    return render_to_response('index.html', {'header': header, 'news': data, 'user_name': user_name})
Esempio n. 4
0
def sandbox(request):
    data = {}
    user_id = request.session.get('user_id', None)
    if user_id is None:
        user_name = None
    else:
        user_name = get_name_user(user_id)
    data['news'] = get_childs_articles()
    data['user_name'] = user_name
    return render_to_response('sandbox.html', data)
Esempio n. 5
0
def index(request):
    c = {}
    user_id = request.session.get('user_id', None)
    print 'us_id index = ', user_id
    if user_id is None:
        c['user_name'] = None
    else:
        c['user_name'] = get_name_user(user_id)
    c['news'] = get_news()
    return render_to_response('index.html', c)
Esempio n. 6
0
def my_page(request, user_name):
    c = {}
    errors = []
    c.update(csrf(request))
    user_id = request.session.get('user_id', None)
    print 'usr id my_page =', user_id
    cur_user = get_name_user(user_id)
    if request.method == 'POST':
        data = request.POST
        if not data.get('news', ''):
            errors.append('Write news!')
        if not data.get('header', ''):
            errors.append('Write title!')
        if is_journalist(user_id):
            is_sand = 0
        else:
            is_sand = 1
        print 'usr id', user_id
        print 'sand =', is_sand
        add_news(user_id, data['news'], data['header'], is_sand)
    c['user_name'] = user_name
    c['news'] = get_news_by_name(user_name)
    c['cur_user'] = cur_user
    return render_to_response('my_page.html', c)
Esempio n. 7
0
def get_name_by_id(value):
    return get_name_user(value)