You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
 
 
 
 
 
 

49 lines
1.5 KiB

from django.contrib.auth import get_user_model
from django.contrib.auth.decorators import login_required, user_passes_test
from django.shortcuts import get_object_or_404
from django.utils.decorators import method_decorator
from django.views.generic import ListView, UpdateView, TemplateView, DetailView
from .models import LiveLesson
User = get_user_model()
def is_admin_or_teacher(function=None, login_url=None):
actual_decorator = user_passes_test(
lambda u: u.role in [User.ADMIN_ROLE, User.TEACHER_ROLE],
login_url=login_url,
)
if function:
return actual_decorator(function)
return actual_decorator
@method_decorator([login_required, is_admin_or_teacher], name='dispatch')
class LiveLessonsView(ListView):
model = LiveLesson
template_name = 'school/livelessons_list.html'
@method_decorator([login_required, is_admin_or_teacher], name='dispatch')
class LiveLessonsDetailView(DetailView):
model = LiveLesson
template_name = 'school/livelesson_detail.html'
@method_decorator([login_required, is_admin_or_teacher], name='dispatch')
class LiveLessonEditView(TemplateView):
template_name = 'course/course_edit.html'
def get(self, request, pk=None):
if pk:
self.object = get_object_or_404(LiveLesson, pk=pk)
else:
self.object = LiveLesson.objects.create()
return super().get(request)
def get_context_data(self):
context = super().get_context_data()
context['object'] = self.object
context['live'] = 'true'
return context