From: Yoan Le Clanche Date: Tue, 5 Dec 2023 11:00:41 +0000 (+0100) Subject: Add missing code for webclass X-Git-Url: https://git.parisson.com/?a=commitdiff_plain;h=7b0ad5fe10fb6332056187a940018bbba11e783e;p=teleforma.git Add missing code for webclass --- diff --git a/teleforma/admin.py b/teleforma/admin.py index 42e76875..cd858824 100644 --- a/teleforma/admin.py +++ b/teleforma/admin.py @@ -8,10 +8,12 @@ from django.contrib.admin import SimpleListFilter from django.contrib.auth.admin import UserAdmin from django.contrib.auth.models import User from django.core import serializers +from django.urls import reverse from django.http import HttpResponse from django.utils.translation import ugettext_lazy as _ from django import forms from django.contrib.admin.helpers import ActionForm +from django.utils.html import format_html from teleforma.models.chat import ChatMessage from teleforma.models.notification import Notification @@ -267,6 +269,18 @@ class ProfileInline(admin.StackedInline): class UserProfileAdmin(UserAdmin): inlines = [ProfileInline, StudentInline, ProfessorProfileInline] search_fields = ['username', 'email'] + list_display = UserAdmin.list_display + ( + 'user_actions', + ) + + def user_actions(self, obj): + return format_html( + 'Se connecter en tant que', + reverse('teleforma-user-login', args=[obj.pk]), + reverse('teleforma-user-login', args=[obj.pk]), + ) + user_actions.short_description = 'Actions' + user_actions.allow_tags = True class TrainingAdmin(admin.ModelAdmin): diff --git a/teleforma/context_processors.py b/teleforma/context_processors.py index 9d805982..7681fc33 100644 --- a/teleforma/context_processors.py +++ b/teleforma/context_processors.py @@ -44,5 +44,5 @@ def periods(request): if not user.is_authenticated: return {'periods': None} else: - return {'periods': get_periods(user)} + return {'periods': get_periods(request)} diff --git a/teleforma/views/appointment.py b/teleforma/views/appointment.py index d88d669a..ee7a36cf 100644 --- a/teleforma/views/appointment.py +++ b/teleforma/views/appointment.py @@ -26,7 +26,7 @@ class Appointments(View): if not student: return HttpResponse('Unauthorized', status=401) period_id = int(period_id) - periods = [ p for p in get_periods(user) if int(p.id) == period_id ] + periods = [ p for p in get_periods(self.request) if int(p.id) == period_id ] if not periods: return HttpResponse('Unauthorized', status=401) return diff --git a/teleforma/views/core.py b/teleforma/views/core.py index ccb69937..a7a95fe1 100644 --- a/teleforma/views/core.py +++ b/teleforma/views/core.py @@ -176,27 +176,40 @@ def get_host(request): return host -def get_periods(user): +def get_periods(request): + user = request.user periods = [] - student = user.student.all() - if student: - student = user.student.get() - periods = student.period.all() + professor = user.professor.all() + quotas = user.quotas.all() + students = user.student.all() if user.is_superuser or user.is_staff: periods = Period.objects.filter(is_open=True) - professor = user.professor.all() - if professor: + elif professor: periods = Period.objects.filter(is_open=True) - quotas = user.quotas.all() - if quotas and not (user.is_superuser or user.is_staff) and not professor: + elif quotas and not (user.is_superuser or user.is_staff) and not professor: periods = [] for quota in quotas: if not quota.period in periods: periods.append(quota.period) + elif students: + period_ids = request.session.get('period_ids') + if period_ids: + periods = [Period.objects.get(id=period_id) + for period_id in period_ids] + else: + student = user.student.get() + periods = [training.period for training in student.trainings.all()] + for period in periods: + for child in period.children.all(): + periods.append(child) + request.session['period_ids'] = [period.id for period in periods] + else: + return [] + return periods @@ -286,7 +299,7 @@ class HomeRedirectView(View): def get(self, request): if request.user.is_authenticated: - periods = get_periods(request.user) + periods = get_periods(request) if periods: period = get_default_period(periods) if period in periods: @@ -308,14 +321,14 @@ class PeriodAccessMixin(View): if period: self.period = period[0] else: - periods = get_periods(self.request.user) + periods = get_periods(self.request) self.period = get_default_period(periods) context['period'] = self.period return context def render_to_response(self, context): period = context['period'] - if not period in get_periods(self.request.user): + if not period in get_periods(self.request): messages.warning(self.request, _( "You do NOT have access to this resource and then have been redirected to your desk.")) return redirect('teleforma-home') @@ -396,7 +409,8 @@ class CourseListView(CourseAccessMixin, ListView): to_subscribe = [] student_courses = [course['course'] for course in get_courses(user)] - for webclass in Webclass.published.filter(period=self.period, iej=student.iej, course__in=student_courses): + import pdb;pdb.set_trace() + for webclass in Webclass.published.filter(period=self.period, course__in=student_courses): # if webclass.course not in student_courses: # continue slot = webclass.get_slot(user) @@ -480,7 +494,7 @@ class CourseView(CourseAccessMixin, DetailView): if student: try: webclass = Webclass.published.filter( - period=self.period, course=course, iej=student.iej)[0] + period=self.period, course=course)[0] except IndexError: pass if webclass: @@ -674,7 +688,7 @@ class DocumentView(CourseAccessMixin, DetailView): if not access: context['access_error'] = access_error context['message'] = contact_message - context['periods'] = get_periods(self.request.user) + context['periods'] = get_periods(self.request) return context @method_decorator(access_required) diff --git a/teleforma/views/crfpa.py b/teleforma/views/crfpa.py index d410763f..19fd6dc1 100644 --- a/teleforma/views/crfpa.py +++ b/teleforma/views/crfpa.py @@ -534,7 +534,7 @@ class AnnalsView(ListView): if self.student: context['student'] = self.student context['all_courses'] = self.all_courses - periods = get_periods(user) + periods = get_periods(self.request) context['period'] = periods[0] return context diff --git a/teleforma/webclass/views.py b/teleforma/webclass/views.py index 3cf8c1cc..3460e781 100644 --- a/teleforma/webclass/views.py +++ b/teleforma/webclass/views.py @@ -60,8 +60,6 @@ class WebclassAppointment(View): if not courses: return HttpResponse('Unauthorized', status=401) # Student is in the right IEJ ? - if not student.iej in webclass.iej.all(): - return HttpResponse('Unauthorized', status=401) if student.platform_only and not webclass.allow_elearning: return HttpResponse('Unauthorized', status=401) if not student.platform_only and not webclass.allow_presentiel: