コード例 #1
0
def statcomentall(environ, start_response):
    """
    Процедура вывода всех регионов с комментриями
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    workDb = Workdb('test.db')
    name = workDb.StatRegionAll()
    return json.JSONEncoder().encode({'name': name})
コード例 #2
0
def getregion(environ, start_response):
    """
    Процедура получения списка регионов
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    workDb = Workdb('test.db')
    name = workDb.SelectRegion()
    return json.JSONEncoder().encode({'name': name})
コード例 #3
0
def statcomentfive(environ, start_response):
    """
    Процедура вывода регионов содержащих более 5 комментариев
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    workDb = Workdb('test.db')
    name = workDb.StatRegionCountFive()
    return json.JSONEncoder().encode({'name': name})
コード例 #4
0
def save(environ, start_response):
    """
    Процедура сохранения комментариев в базу
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0
    request_body = environ['wsgi.input'].read(request_body_size)
    data = parse_qs(request_body)
    try:
        surname = data['surname'][0].decode('utf8')
    except:
        surname = 'not'
    try:
        firstName = data['firstName'][0].decode('utf8')
    except:
        firstName = 'not'
    try:
        patronymic = data['patronymic'][0].decode('utf8')
    except:
        patronymic = 'не указано'.decode('utf8')
    try:
        email = data['email'][0].decode('utf8')
    except:
        email = 'не указано'.decode('utf8')
    try:
        phone = data['phone'][0].decode('utf8')
    except:
        phone = 'не указано'.decode('utf8')
    if (data['code_city'][0] == 'not'):
        code_city = 0
    else:
        code_city = data['code_city'][0]
    try:
        comment = data['comment'][0].decode('utf8')
    except:
        comment = 'not'
    if (surname == "not") or (firstName == "not") or (comment == "not"):
        return ["Не заполнены поля"]
    workDb = Workdb('test.db')
    workDb.InsertComent(surname, firstName, patronymic, email, phone,
                        code_city, comment)
    return ["Успешно"]
コード例 #5
0
def getcity(environ, start_response):
    """
    Процедура получения списка городов по выбранному региону
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0
    request_body = environ['wsgi.input'].read(request_body_size)
    data = parse_qs(request_body)
    workDb = Workdb('test.db')
    codeRegion = data['city'][0]
    name = workDb.SelectCity(str(codeRegion))
    return json.JSONEncoder().encode({'name': name})
コード例 #6
0
def delcoment(environ, start_response):
    """
    Процедура удаления комментариев
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0
    request_body = environ['wsgi.input'].read(request_body_size)
    data = parse_qs(request_body)
    id = data['id']
    workDb = Workdb('test.db')
    workDb.DeleteComent(id)
    return ["Успешно"]
コード例 #7
0
def getstatcomentcity(environ, start_response):
    """
    Процедура вывода городов региона с комментриями
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    try:
        request_body_size = int(environ.get('CONTENT_LENGTH', 0))
    except (ValueError):
        request_body_size = 0
    request_body = environ['wsgi.input'].read(request_body_size)
    data = parse_qs(request_body)
    region_id = data['region_id'][0].decode('utf8')
    workDb = Workdb('test.db')
    name = workDb.StatCityRegion(region_id)
    return json.JSONEncoder().encode({'name': name})
コード例 #8
0
def getviewcoment(environ, start_response):
    """
    Процедура получения комментариев
    :param environ:
    :param start_response:
    :return:
    """
    start_response('200 OK', [('Content-Type', 'text/plan')])
    workDb = Workdb('test.db')
    comments = workDb.SelectComent()
    print(comments)
    tableRows = u'<table id="myTable" cellspacing="0">\
    <tr align="center">\
        <th>Фамилия</th>\
        <th>Имя</th>\
        <th>Отчество</th>\
        <th>Email</th>\
        <th>Телефон</th>\
        <th>Город</th>\
        <th>Коментарий</th>\
        <th>Действие</th>\
    </tr>'

    for line in comments:
        tableRows += u"<tr>"
        ind = -1
        for elem in line:
            if type(elem) != int:
                tableRows += u'<td>' + elem + u'</td>'
            else:
                ind = elem
        tableRows += u"<td><button id=" + unicode(
            str(ind), 'ascii'
        ) + u" onclick = deleteComment(this.id)>Удалить</button></td></tr>"
    tableRows += u'</table>'
    return json.JSONEncoder().encode({'name': tableRows})