Beispiel #1
0
 def create_obj(self, data):
     course_name = data['course_name']
     course_name = Application.decode_value(course_name)
     course = site.get_course(course_name)
     student_name = data['student_name']
     student_name = Application.decode_value(student_name)
     student = site.get_student(student_name)
     course.add_student(student)
Beispiel #2
0
def contact_view(request):
    # Проверка метода запроса
    if request['method'] == 'POST':
        data = request['data']
        title = Application.decode_value(data['title'])
        text = Application.decode_value(data['text'])
        email = Application.decode_value(data['email'])
        print(f'Нам пришло сообщение от {email} с темой {title} и текстом {text}')
        return '200 OK', render('contact.html')
    else:
        return '200 OK', render('contact.html')
Beispiel #3
0
 def create_obj(self, data):
     name = data['name']
     name = Application.decode_value(name)
     new_obj = site.create_user('student', name)
     site.students.append(new_obj)
     new_obj.mark_new()
     UnitOfWork.get_current().commit()
Beispiel #4
0
def course_list(request):
    request_params = request['request_params']

    name = request_params['name']
    name = Application.decode_value(name)

    old_course = site.get_course(name)
    if old_course:
        new_name = f'copy_{name}'
        new_course = old_course.clone()
        new_course.name = new_name
        site.courses.append(new_course)

    return '200 OK', render('course_list.html', objects_list=site.courses)
Beispiel #5
0
def create_course(request):
    if request['method'] == 'POST':
        # метод пост
        data = request['data']
        name = data['name']
        name = Application.decode_value(name)

        category_id = data.get('category_id')

        if category_id:
            category = site.find_category_by_id(int(category_id))

            course = site.create_course('record', name, category)
            site.courses.append(course)
        # редирект?
        # return '302 Moved Temporarily', render('create_course.html')
        # Для начала можно без него
        return '200 OK', render('create_course.html')
    else:
        categories = site.categories
        return '200 OK', render('create_course.html', categories=categories)
Beispiel #6
0
    def create_obj(self, data):
        name = data['name']
        name = Application.decode_value(name)

        new_category = site.create_category(name)
        site.categories.append(new_category)
Beispiel #7
0
    '/student-list/': StudentListView(),
    '/create-student/': StudentCreateView(),
    '/add-student/': AddStudentCreateView(),
}


def secret_controller(request):
    # пример Front Controller
    request['secret_key'] = 'SECRET'


front_controllers = [
    secret_controller
]

application = Application(urls, front_controllers)


# application = DebugApplication(urls, front_controllers)
# application = FakeApplication(urls, front_controllers)

@application.add_route('/create-course/')
def create_course(request):
    if request['method'] == 'POST':
        # метод пост
        data = request['data']
        name = data['name']
        name = Application.decode_value(name)

        category_id = data.get('category_id')