Esempio n. 1
0
 def _filter_scholar_year(self, queryset):
     start_year = get_scholar_year()
     end_year = start_year + 1
     start = timezone.datetime(year=start_year, month=8, day=20)
     end = timezone.datetime(year=end_year, month=8, day=19)
     return queryset.filter(datetime_creation__gt=start,
                            datetime_creation__lt=end)
Esempio n. 2
0
    def get_context_data(self, **kwargs):
        # Get settings.
        settings_dossier_eleve = get_settings()

        # Add to the current context.
        context = super().get_context_data(**kwargs)
        context['settings'] = JSONRenderer().render(DossierEleveSettingsSerializer(settings_dossier_eleve).data).decode()
        context['menu'] = json.dumps(get_menu(self.request.user, "dossier_eleve"))
        context['filters'] = json.dumps(self.filters)
        scholar_year = get_scholar_year()
        context['current_year'] = json.dumps('%i-%i' % (scholar_year, scholar_year + 1))
        context['can_set_sanction'] = json.dumps(self.request.user.has_perm('dossier_eleve.set_sanction'))
        context['can_ask_sanction'] = json.dumps(self.request.user.has_perm('dossier_eleve.ask_sanction'))
        groups = get_generic_groups()
        groups["sysadmin"] = {"id": groups["sysadmin"].id, "text": "Admin"}
        groups["direction"] = {"id": groups["direction"].id, "text": "Direction"}
        groups["coordonator"] = {"id": groups["coordonator"].id, "text": "Coordonateur"}
        groups["educator"] = {"id": groups["educator"].id, "text": "Educateur"}
        groups["teacher"] = {
            "id": groups["teacher"].id,
            "text": "Titulaire(s)" if settings_dossier_eleve.filter_teacher_entries_by_tenure else "Professeurs"
        }
        groups["pms"] = {"id": groups["pms"].id, "text": "PMS"}
        context['groups'] = groups
        return context
Esempio n. 3
0
    def gen_stats(self, user_from, matricule, only_sanctions=False, all_years=False):
        all_access = get_settings().all_access.all()
        queryset = CasEleve.objects.all()
        if not user_from.groups.intersection(all_access).exists():
            teachings = ResponsibleModel.objects.get(user=user_from).teaching.all()
            classes = get_classes(list(map(lambda t: t.name, teachings)), True, user_from)
            queryset = queryset.filter(matricule__classe__in=classes)

        cas_discip = queryset.filter(info=None, matricule=matricule)\
                             .filter(Q(sanction_faite=True) | Q(sanction_faite__isnull=True))
        cas_info = queryset.filter(sanction_decision=None, matricule=matricule)

        if not all_years:
            current_scolar_year = get_scholar_year()
            limit_date = timezone.make_aware(timezone.datetime(current_scolar_year, 8, 15))
            cas_discip = cas_discip.filter(datetime_encodage__gte=limit_date)
            cas_info = cas_info.filter(datetime_encodage__gte=limit_date)

        sanctions = SanctionStatisticsModel.objects.all()

        stats = []
        for s in sanctions:
            stat = {
                'display': s.display,
                'value': len(cas_discip.filter(sanction_decision__in=s.sanctions_decisions.all()))
            }
            stats.append(stat)

        if not only_sanctions:
            stats.append({'display': 'Non disciplinaire', 'value': len(cas_info)})
            stats.append({'display': 'Total disciplinaire', 'value': len(cas_discip)})

        return stats
Esempio n. 4
0
    def get(self, format=None):
        query = self.request.GET.get('scholar_year', '')
        if not query:
            return Response([])

        current_year = get_scholar_year()
        options = []
        for y in reversed(range(current_year - 10, current_year + 1)):
            options.append("%i-%i" % (y, y + 1))
        return Response(options)
Esempio n. 5
0
def notify_sanction(self, instance_id):
    instance = CasEleve.objects.get(id=instance_id)
    student = instance.matricule
    context = {'student': student, 'sanction': instance}

    for notify in instance.sanction_decision.notify.all():
        recipient = []
        # Check if we match the frequency.
        scholar_year_start = date(year=get_scholar_year(), month=9, day=1)
        scholar_year_end = date(year=get_scholar_year() + 1, month=9, day=1)
        sanction_count = CasEleve.objects.filter(
            datetime_encodage__gte=scholar_year_start,
            datetime_encodage__lt=scholar_year_end,
            matricule=student,
            sanction_decision=instance.sanction_decision
        ).count()
        if sanction_count % notify.frequency != 0:
            continue

        if notify.recipient == "PA":
            if student.additionalstudentinfo.father_email:
                recipient.append(student.additionalstudentinfo.father_email)
            if student.additionalstudentinfo.mother_email:
                recipient.append(student.additionalstudentinfo.mother_email)
        elif notify.recipient == "LR":
            if student.additionalstudentinfo.resp_email:
                recipient.append(student.additionalstudentinfo.resp_email)
        elif notify.recipient == "SR":
            emails = EmailModel.objects.filter(
                teaching=student.teaching,
                years=student.classe.year
            )
            recipient += [e.email for e in emails]

        send_email(
            to=recipient,
            subject="Sanction concernant %s" % student.fullname,
            email_template="dossier_eleve/email_sanction.html",
            context=context
        )
Esempio n. 6
0
    def sync(self) -> None:
        from libreschoolfdb.reader import get_teachers, get_educators
        year = get_scholar_year()
        self.print_log("Collecting teachers from ProEco database…")
        teachers = get_teachers(year, self.server, self.teaching_type,
                                classe_format=self.classe_format)
        self.is_teacher = True
        self.is_educator = False
        self._sync(teachers.items())

        self.print_log("Collecting educators from ProEco database…")
        educators = get_educators(self.server)
        self.is_teacher = False
        self.is_educator = True
        self._sync(educators.items())
Esempio n. 7
0
class ImportStudentFDB(ImportStudent):
    column_map = {
        "last_name": "surname", "first_name": "firstname", "year": "classe_year",
        "doctor": "medecin", "doctor_phone": "medecin_phone", "mutual": "mutuelle",
        "medical_information": "medical_info",
        "street": "address", "locality": "city", "student_mobile": "student_gsm",
        "resp_last_name": "resp_surname", "resp_first_name": "resp_firstname",
        "resp_phone": "phone", "resp_mobile": "gsm", "resp_email": "email",
        "father_last_name": "father_surname", "father_first_name": "father_firstname", "father_mobile": "father_gsm",
        "mother_last_name": "mother_surname", "mother_first_name": "mother_firstname", "mother_mobile": "mother_gsm",
    }
    scholar_year = get_scholar_year()

    def __init__(self, teaching: TeachingModel, fdb_server, search_login_directory, teaching_type, classe_format="%C") -> None:
        super().__init__(teaching, search_login_directory)
        self.server = fdb_server
        self.teaching_type = teaching_type
        self.classe_format = classe_format

    def sync(self):
        from libreschoolfdb.reader import get_students
        self.print_log("Collecting students informations from ProEco database.")
        students = get_students(year=self.scholar_year, fdb_server=self.server,
                                teaching=self.teaching_type, absences_info=False,
                                classe_format=self.classe_format)
        # print(students)
        super()._sync(students.items())

    def get_value(self, entry: dict, column: str) -> Union[int, str, date, None]:
        if column == "matricule":
            return entry[0]
        elif column == "previous_class":
            if "previous_classe" in entry:
                return entry["previous_classe"]
            else:
                return None
        elif column == "username" or column == "password":
            return None
        elif column == "scholar_year":
            return self.scholar_year
        elif column in self.column_map:
            return entry[1][self.column_map[column]]
        else:
            return self.format_value(entry[1][column], column)
Esempio n. 8
0
    def handle(self, *args, **options):
        from libreschoolfdb import reader
        from libreschoolfdb.absences import Absence

        proecos = settings.SYNC_FDB_SERVER
        current_year = get_scholar_year()

        student_synced = set()
        for proeco in proecos:
            try:
                teaching_model = TeachingModel.objects.get(
                    name=proeco["teaching_name"])
            except ObjectDoesNotExist:
                print("teaching__name: %s, not found" %
                      proeco["teaching_name"])
                continue

            # ProEco student list.
            proeco_students = reader.get_students(
                year=current_year,
                fdb_server=proeco["server"],
                teaching=proeco["teaching_type"],
                med_info=False,
                parents_info=False)
            print("%s students found" % len(proeco_students))
            processed = 0
            for matricule, s in proeco_students.items():
                processed += 1
                if processed % 50 == 1:
                    print(processed - 1)
                try:
                    student = StudentModel.objects.get(matricule=matricule)
                except ObjectDoesNotExist:
                    # No student found, ignoring.
                    continue

                # Import absences.
                absences = s['absences'] if 'absences' in s else None
                if not absences:
                    continue
                absences_processed = set()
                for a in absences:
                    try:
                        absence = StudentAbsenceModel.objects.get(
                            student=student, date_absence=a.date)
                        absence.morning = a.morning
                        absence.afternoon = a.afternoon
                        absence.save()
                    except:
                        absence = StudentAbsenceModel.objects.create(
                            student=student,
                            date_absence=a.date,
                            morning=a.morning,
                            afternoon=a.afternoon)
                    absences_processed.add(absence.pk)

                # Remove deleted absences.
                StudentAbsenceModel.objects.filter(student=student).exclude(
                    pk__in=absences_processed).delete()

                # Import justifications.
                justifications = s['absences_justifications']
                # Clean first.
                JustificationModel.objects.filter(student=student).delete()
                for j in justifications:
                    JustificationModel.objects.create(
                        student=student,
                        date_just_start=j['start'][0],
                        date_just_end=j['end'][0],
                        half_day_start=j['start'][1],
                        half_day_end=j['end'][1],
                        short_name=j['code'],
                        half_days=j['half_days'])