Ejemplo n.º 1
0
from journal.models import Squad, Subject, UserExtension
from django.shortcuts import render
from maintenance.helpers.named_tuple import namedtuple_wrapper

tSquadSubject = namedtuple_wrapper("tSquadSubject", [
    "id",
    "code",
    "subjects",
])

ERROR_403 = (
    """<h3 class="header-wo-margin" align="center">Недостаточно прав!</h3>"""
    """<p class="text-muted header-comment" align="center">"""
    "{}"
    "</p>")


def get_squads_with_subjects():
    ans = []
    for s in Squad.objects.order_by('code'):
        q = Subject.objects.filter(timetable__squad__code=s.code
                                   ).prefetch_related('timetable_set__squad')
        ans.append(tSquadSubject(
            code=s.code,
            id=s.id,
            subjects=q,
        ))
    return ans


tMarkValues = namedtuple_wrapper("tMarkValues", [
Ejemplo n.º 2
0
from django.shortcuts import render
from journal.models import Attendance, UserExtension
from maintenance.helpers.named_tuple import namedtuple_wrapper
from journal import constants
from journal.managers.context import with_context, get_user_extension
from datetime import date

tAttendanceRestriction = namedtuple_wrapper(
    "tAttendanceRestriction",
    (
        "date_restricted",
        "date",
        "squads",
        "can_edit",
    ),
)


def attendance(request):
    restrictions = None
    try:
        ext = UserExtension.objects.get(user=request.user)
    except UserExtension.DoesNotExist:
        ext = None
    if ext:
        allowed_squads = ext.squads.all()
        f = Attendance.objects.filter(squad__in=allowed_squads)
        restrictions = tAttendanceRestriction(
            date_restricted=ext.date_limit,
            date=date.today(),
            squads=allowed_squads,
Ejemplo n.º 3
0
from maintenance.helpers.named_tuple import namedtuple_wrapper

rMark = namedtuple_wrapper(
    "requestMark",
    [
        "value",
        "id",
        "student_id",
        "subject_id",
        "teacher_id",
        "lesson_id",
    ],
)

rLesson = namedtuple_wrapper(
    "requestLesson",
    [
        "name",
        "date",
        "subject_id",
        "squad_id",
    ],
)
Ejemplo n.º 4
0
from datetime import date, timedelta
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import ensure_csrf_cookie

from journal.managers.context import with_context
from journal.models import *
from journal.managers.marks import tAvg
from journal.views.common import avg_mark_student, get_attendance_stats
from maintenance.helpers.named_tuple import namedtuple_wrapper

tOption = namedtuple_wrapper("tOption", ("code", "label"))

tCount = namedtuple_wrapper("tCount", ("label", "count"))

tExamMark = namedtuple_wrapper("tExamMark", ("semester", "marks"))


@ensure_csrf_cookie
@login_required
def students(request):
    ls: [Student] = Student.objects.all()
    for student in ls:
        student_info = PersonalInfo.objects.filter(student=student)
        if student_info:
            student.deducted = student_info[0].end_date is not None
        else:
            student.deducted = False
    return render(
        request,
        "journal/students.html",
Ejemplo n.º 5
0
from datetime import date, timedelta
from django.shortcuts import render
from django.contrib.auth.decorators import login_required
from django.views.decorators.csrf import ensure_csrf_cookie

from journal.managers.context import with_context
from journal.models import *
from journal.managers.marks import tAvg
from journal.views.common import avg_mark_student, get_attendance_stats
from maintenance.helpers.named_tuple import namedtuple_wrapper

tOption = namedtuple_wrapper('tOption', ('code', 'label'))

tCount = namedtuple_wrapper('tCount', ('label', 'count'))

tExamMark = namedtuple_wrapper('tExamMark', ('semester', 'marks'))


@ensure_csrf_cookie
@login_required
def students(request):
    ls: [Student] = Student.objects.all()
    for student in ls:
        student_info = PersonalInfo.objects.filter(student=student)
        if student_info:
            student.deducted = student_info[0].end_date is not None
        else:
            student.deducted = False
    return render(
        request,
        "journal/students.html",
Ejemplo n.º 6
0
from django.shortcuts import render
from journal.models import Event, EventParticipant
from journal.managers.context import with_context
from maintenance.helpers.named_tuple import namedtuple_wrapper

tEventsParts = namedtuple_wrapper("tEventsParts", ("event", "participants"))


def events(request):
    f = Event.objects.all().order_by("-date")
    f = get_participants(f)

    return render(
        request,
        "journal/events.html",
        {
            "forms": f,
        },
    )


def get_participants(events):
    response = []
    for event in events:
        ps = (EventParticipant.objects.filter(event=event).all().order_by(
            "student__squad__code", "student__last_name"))
        response.append(tEventsParts(event=event, participants=ps))
    return response
Ejemplo n.º 7
0
from journal.managers.context import with_context
from journal.models import *
from maintenance.helpers.named_tuple import namedtuple_wrapper
from journal.views.common import (
    avg_mark_student,
    avg_marks_group,
    get_attendance_stats,
    students_to_ids,
    _count_mark_group,
    for_subj_mark_student,
    for_subj_marks_group,
)

tStudentRow = namedtuple_wrapper(
    "tStudentRow",
    ("student", "avg_marks", "attendance", "total_reprimands", "total_promotions"),
)

tUnitRow = namedtuple_wrapper(
    "tUnitRow",
    (
        "unit",
        "rows",
        "subtotal",
    ),
)

tSubjectMark = namedtuple_wrapper(
    "tSubjectMark",
    (
        "semester",
Ejemplo n.º 8
0
from django.shortcuts import render
from journal.models import Attendance, UserExtension
from maintenance.helpers.named_tuple import namedtuple_wrapper
from journal import constants
from journal.managers.context import with_context, get_user_extension
from datetime import date

tAttendanceRestriction = namedtuple_wrapper('tAttendanceRestriction', (
    'date_restricted',
    'date',
    'squads',
    'can_edit',
))


def attendance(request):
    restrictions = None
    try:
        ext = UserExtension.objects.get(user=request.user)
    except UserExtension.DoesNotExist:
        ext = None
    if ext:
        allowed_squads = ext.squads.all()
        f = Attendance.objects.filter(squad__in=allowed_squads)
        restrictions = tAttendanceRestriction(
            date_restricted=ext.date_limit,
            date=date.today(),
            squads=allowed_squads,
            can_edit=ext.can_edit_attendance,
        )
    else:
Ejemplo n.º 9
0
from datetime import datetime as dt

from journal.models import Mark, Student
from maintenance.helpers.named_tuple import namedtuple_wrapper

tMark = namedtuple_wrapper("tMark", [
    "id",
    "x_key",
    "y_key",
    "val",
])
tKey = namedtuple_wrapper(
    "tKey",
    ["id", "display", "sort", "val", "comment", "exam_id", "exam_name"])
tAvg = namedtuple_wrapper('tAvg', ["short", "avg", "exams"])


def by_subject(marks_list: [Mark]) -> [tMark]:
    ls = []

    for m in marks_list:
        mr = tMark(
            id=m.id,
            x_key=student_to_key(m.student),
            y_key=date_to_key(m.date),
            val=m.val,
        )
        ls.append(mr)
    return ls

Ejemplo n.º 10
0
from django.shortcuts import render
from datetime import date, timedelta, datetime
from django.db.models import QuerySet
from django.contrib.auth.decorators import login_required

from journal.managers.context import with_context
from journal.models import *
from maintenance.helpers.named_tuple import namedtuple_wrapper
from journal.views.common import avg_mark_student, avg_marks_group, get_attendance_stats, students_to_ids, \
    _count_mark_group, for_subj_mark_student, for_subj_marks_group

tStudentRow = namedtuple_wrapper('tStudentRow',
                                 ('student', 'avg_marks', 'attendance',
                                  'total_reprimands', 'total_promotions'))

tUnitRow = namedtuple_wrapper('tUnitRow', (
    'unit',
    'rows',
    'subtotal',
))

tSubjectMark = namedtuple_wrapper('tSubjectMark', (
    'semester',
    'mark',
))

tSubjectAvgs = namedtuple_wrapper('tSubjectAvgs', (
    'subject',
    'avgs',
))
Ejemplo n.º 11
0
from django.shortcuts import render
from journal.models import Event, EventParticipant
from journal.managers.context import with_context
from maintenance.helpers.named_tuple import namedtuple_wrapper

tEventsParts = namedtuple_wrapper('tEventsParts', ('event', 'participants'))


def events(request):
    f = Event.objects.all().order_by('-date')
    f = get_participants(f)

    return render(request, 'journal/events.html', {
        'forms': f,
    })


def get_participants(events):
    response = []
    for event in events:
        ps = EventParticipant.objects.filter(event=event).all().order_by(
            'student__squad__code', 'student__last_name')
        response.append(tEventsParts(event=event, participants=ps))
    return response