Пример #1
0
def professions(request):
    content = app_data.get_context_data('professions', 'users')
    content['user'] = app_data.get_active_user()

    content_text = render('professions.html', loader_params=jinja_loader_params, static_url=static_url, **content)
    status_code = '200 OK'
    return content_text, status_code
Пример #2
0
 def __call__(self, request):
     print(request)
     if request['method'] == 'POST':
         data = request['data']
         name = data['name']
         name = site.decode_value(name)
         category_id = data.get('category_id')
         category = None
         if category_id:
             category = site.find_category_by_id(int(category_id))
         new_category = site.create_category(name, category)
         site.categories.append(new_category)
         return '200 OK', render('index.html', objects_list=site.categories)
     else:
         categories = site.categories
         return '200 OK', render('create_category.html',
                                 categories=categories)
Пример #3
0
def participate(request):
    content = app_data.get_context_data('courses', 'professions', 'users')
    content['user'] = app_data.get_active_user()
    content_text = render('participate.html', loader_params=jinja_loader_params, static_url=static_url, **content)
    status_code = '200 OK'
    if request['method'] == 'POST':
        print("QUERY STRING: ", request['body'])
    return content_text, status_code
Пример #4
0
 def __call__(self, request):
     logger.log('Список курсов')
     try:
         category = site.find_category_by_id(
             int(request['request_params']['id']))
         return '200 OK', render('course_list.html',
                                 objects_list=category.courses,
                                 name=category.name,
                                 id=category.id)
     except KeyError:
         return '200 OK', 'No course have been added yet'
Пример #5
0
 def __call__(self, request):
     if request['method'] == 'POST':
         data = request['data']
         name = data['name']
         name = site.decode_value(name)
         category = None
         if self.category_id != -1:
             category = site.find_category_by_id(int(self.category_id))
             course = site.create_course('video', name, category)
             site.courses.append(course)
         return '200 OK', render('course_list.html',
                                 objects_list=category.courses,
                                 name=category.name,
                                 id=category.id)
     else:
         try:
             self.category_id = int(request['request_params']['id'])
             category = site.find_category_by_id(self.category_id)
             return '200 OK', render('create_course.html',
                                     name=category.name,
                                     id=category.id)
         except KeyError:
             return '200 OK', 'No categories have been added yet'
Пример #6
0
    def __call__(self, request):
        request_params = request['request_params']
        try:
            name = request_params['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)
        except KeyError:
            return '200 OK', 'No courses have been added yet'
Пример #7
0
def courses(request):
    # TODO make buying courses awailible in all functions
    print(request)
    if request['method'] == 'GET':
        try:
            course_title = request['query_string']['course']
            course = app_data.get_course(course_title)
            user = app_data.get_active_user()
            if isinstance(user, Student):
                user.buy_course(course)
            if isinstance(user, Chef):
                user.authorize_for_course(course)
        except TypeError:
            pass
    if request['method'] == 'POST':
        course_data = request['body']
        app_data.add_course(**course_data)
    content = app_data.get_context_data('courses', 'users')
    content['user'] = app_data.get_active_user()
    content_text = render('courses.html', loader_params=jinja_loader_params, static_url=static_url, **content)
    status_code = '200 OK'
    return content_text, status_code
Пример #8
0
 def render_template_with_context(self):
     template_name = self.get_template()
     context = self.get_context_data()
     return '200 OK', render(template_name, **context)
Пример #9
0
 def __call__(self, request):
     logger.log('Список категорий')
     return '200 OK', render('category_list.html',
                             objects_list=site.categories)
Пример #10
0
 def __call__(self, request):
     return '200 OK', render('study_programs.html', data=date.today())
Пример #11
0
 def __call__(self, request):
     return '200 OK', render('about.html')
Пример #12
0
 def __call__(self, request):
     return '200 OK', render('index.html', objects_list=site.categories)