コード例 #1
0
def view_create_category(request):
    logger.log('view_create_category')
    request['title'] = 'Категории'
    request['categories'] = web.categories
    if request['method'] == 'POST':
        data = request['data']
        try:
            name = data['name']
        except:
            return '400 BAD_REQUEST', render('templates/categories.html',
                                             object_list=request)
        new_category = web.create_category(name)
        web.categories.append(new_category)
        request['categories'] = web.categories
        return '201 CREATED', render('templates/categories.html',
                                     object_list=request)
    return '200 OK', render('templates/categories.html', object_list=request)
コード例 #2
0
def view_student_add(request):
    request['title'] = 'Создать студента'
    if request['method'] == 'POST':
        data = request['data']
        name = data['name']
        new_obj = web.create_user('student', name)
        web.students.append(new_obj)
    return '200 OK', render('templates/create_student.html',
                            object_list=request)
コード例 #3
0
def view_create_course(request):
    logger.log('view_create_course')
    request['title'] = 'Создать курс'
    request['categories'] = web.categories
    if request['method'] == 'POST':
        data = request['data']
        try:
            name = data['name']
        except:
            return '400 BAD_REQUEST', render('templates/categories.html',
                                             object_list=request)
        category_id = data.get('category_id')
        if category_id:
            category = web.find_category_by_id(int(category_id[0]))
            course = web.create_course('record', name, category)
            web.courses.append(course)
        request['categories'] = web.categories
    return '200 OK', render('templates/create_course.html',
                            object_list=request)
コード例 #4
0
def view_contacts(request):
    logger.log('view_contacts')
    request['title'] = 'Контакты'
    if request['method'] == 'POST':
        data = request['data']
        title = ''.join(data['title'])
        text = ''.join(data['text'])
        email = ''.join(data['email'])
        print(f'{title}, {text}, {email}')
        if title or text or email:
            save_to_file(f'{title}, {text}, {email}')
    return '200 OK', render('templates/contacts.html', object_list=request)
コード例 #5
0
def view_student_add(request):
    request['title'] = 'Запись на курс'
    request['courses'] = web.courses
    request['students'] = web.students
    if request['method'] == 'POST':
        data = request['data']
        print(request)
        course_name = data['course_name']
        print(course_name)
        course = web.get_course(course_name)
        print(course)
        student_name = data['student_name']
        student = web.get_student(student_name)
        course.add_student(student)
    return '200 OK', render('templates/add_student.html', object_list=request)
コード例 #6
0
def view_404(request):
    request['title'] = '404_page'
    page = render('templates/404.html', object_list=request)
    return '404 WHAT', page
コード例 #7
0
def view_about(request):
    logger.log('view_about')
    request['title'] = 'О нас'
    return '200 OK', render('templates/about.html', object_list=request)
コード例 #8
0
def view_index(request):
    logger.log('view_index')
    request['title'] = 'Главная'
    return '200 OK', render('templates/index.html', object_list=request)
コード例 #9
0
def view_student_add(request):
    request['title'] = 'Список студентов'
    request['students'] = web.students
    return '200 OK', render('templates/list_student.html', object_list=request)
コード例 #10
0
def view_list_courses(request):
    logger.log('view_list_courses')
    request['title'] = 'Курсы'
    request['courses'] = web.courses
    return '200 OK', render('templates/list_course.html', object_list=request)