Exemplo n.º 1
0
def contacts(request):
    if request['METHOD'] == 'GET':
        page = render_from_file('contacts.html', request)
        return '200 OK', page

    if request['METHOD'] == 'POST':
        body = parse_body_json(request)
        print(body)
        if body['topic'] and body['msg'] and body['email']:
            print(
                f'User with email {body["email"]} had sent a message. Topic {body["topic"]}: \n {body["msg"]}'
            )

        page = render_from_file('contacts.html', request)
        return '200 OK', page
Exemplo n.º 2
0
def category_list(request):
    if request['METHOD'] == 'GET':
        page = render_from_file('category_list.html',
                                object_list=courses_app.categories)
        return '200 OK', page
    if request['METHOD'] == 'POST':
        pass
Exemplo n.º 3
0
def course_list(request):
    if request['METHOD'] == 'GET':
        print('courses: ')
        print(courses_app.courses)
        page = render_from_file('course_list.html',
                                object_list=courses_app.courses)
        return '200 OK', page
    if request['METHOD'] == 'POST':
        pass
Exemplo n.º 4
0
def create_course(request):
    if request['METHOD'] == 'GET':
        page = render_from_file('create_course.html',
                                categories=courses_app.categories)
        return '200 OK', page
    if request['METHOD'] == 'POST':
        data = request['DATA']

        print(data)

        name = data['name']
        category_id = data.get('category_id')
        print(category_id)
        category = None
        if category_id:
            category = courses_app.get_category_by_id(int(category_id))

        courses_app.create_course('online', name, category)
        print(courses_app.courses)

        # редирект?
        # return '302 Moved Temporarily', render('create_course.html')
        # Для начала можно без него
        return '200 OK', render_from_file('create_course.html')
Exemplo n.º 5
0
def index(request):
    page = render_from_file('index.html', request)
    return '200 OK', page
Exemplo n.º 6
0
 def render_template_with_context(self):
     template_name = self.get_template()
     context = self.get_context_data()
     return '200 OK', render_from_file(template_name, **context)
Exemplo n.º 7
0
def not_found(request):
    page = render_from_file('404.html', request)
    return '404 NOT FOUND', page