示例#1
0
    def test_get_correct_semester(self):
        winter_semester = Semester.get_semester(datetime(2015, 12, 25))
        self.assertEqual(winter_semester.type, Semester.TYPE_WINTER)
        summer_semester = Semester.get_semester(datetime(2016, 5, 20))
        self.assertEqual(summer_semester.type, Semester.TYPE_SUMMER)

        some_semester = Semester.get_semester(winter_semester.semester_ending + timedelta(days=1))
        self.assertEqual(some_semester.type, Semester.TYPE_SUMMER)
示例#2
0
    def test_count_changed_days_in_winter_semester(self):
        semester = Semester.get_semester(datetime(2015, 11, 10))
        self.assertNotEqual(semester, None)
        changed_days = ChangedDay.get_added_days_of_week(semester.semester_beginning,
                                                         semester.semester_ending)

        self.assertEqual(len(changed_days), 3)
示例#3
0
 def test_get_all_sundays_in_winter_semester(self):
     winter_semester = Semester.get_semester(datetime(2015, 12, 1))
     sundays = winter_semester.get_all_days_of_week(common.SUNDAY)
     self.assertTrue(sundays)
     # a sunday in winter semester
     a_sunday = date(2015, 12, 6)
     another_sunday = date(2015, 11, 22)
     self.assertTrue(a_sunday in sundays)
     self.assertTrue(another_sunday in sundays)
示例#4
0
 def test_clean_on_overlapping_reservation_where_both_are_same(self):
     semester = Semester.get_semester(date(2016, 5, 12))  # summer20152016
     room = Classroom.get_by_number('110')
     reservation = SpecialReservation(
         semester=semester,
         title='overlapping',
         classroom=room,
         dayOfWeek=common.WEDNESDAY,
         start_time=time(15),
         end_time=time(16)
     )
示例#5
0
 def test_try_clean_on_overlapping_reservation(self):
     semester = Semester.get_semester(date(2016, 5, 12))
     room = Classroom.get_by_number('110')
     reservation = SpecialReservation(
         semester=semester,
         title='overlapping',
         classroom=room,
         dayOfWeek=common.THURSDAY,
         start_time=time(14),
         end_time=time(16)
     )
示例#6
0
    def __init__(self, user, data=None, **kwargs):

        if data:
            data = deepcopy(data)
            if 'type' not in data:
                data['type'] = Event.TYPE_GENERIC

        super(EventForm, self).__init__(data, **kwargs)
        if not self.instance.pk:
            self.instance.author = user
        if BaseUser.is_employee(user):
            self.fields['type'].choices = Event.TYPES_FOR_TEACHER
        else:
            self.fields['type'].choices = Event.TYPES_FOR_STUDENT

        if not BaseUser.is_employee(user):
            self.fields['course'].queryset = CourseInstance.objects.none()
        else:
            semester = Semester.get_current_semester()

            previous_semester = Semester.get_semester(datetime.now().date() -
                                                      timedelta(days=30))

            queryset = CourseInstance.objects.filter(semester__in=[semester, previous_semester]). \
                select_related('semester'). \
                order_by('semester')

            if not user.has_perm('schedule.manage_events'):
                queryset = CourseInstance.objects.filter(
                    groups__type='1',
                    groups__teacher=user.employee,
                    semester__in=[semester, previous_semester])

            self.fields['course'].queryset = queryset

        self.fields['title'].widget.attrs.update({'class': 'form-control'})
        self.fields['type'].widget.attrs.update({'class': 'form-control'})
        self.fields['course'].widget.attrs.update({'class': 'form-control'})
        self.fields['description'].widget.attrs.update(
            {'class': 'form-control'})
        self.fields['visible'].widget.attrs.update({
            'checked':
            '',
            'class':
            'custom-control-input'
        })
示例#7
0
    def validate_against_course_terms(self):
        assert (self.room is not None)
        semester = Semester.get_semester(self.day)
        if not semester:
            return
        if semester.lectures_beginning <= self.day and self.day <= semester.lectures_ending:

            course_terms = CourseTerm.get_terms_for_semester(
                semester=semester,
                day=self.day,
                classrooms=[self.room],
                start_time=self.start,
                end_time=self.end)
            if course_terms:
                raise ValidationError(message={
                    '__all__': [
                        'W tym samym czasie w tej sali odbywają się zajęcia: '
                        + course_terms[0].group.course.name + ' ' +
                        str(course_terms[0])
                    ]
                },
                                      code='overlap')
示例#8
0
 def test_count_added_sundays(self):
     winter_semester = Semester.get_semester(datetime(2015, 12, 1))
     sundays_added = winter_semester.get_all_added_days_of_week(common.SUNDAY)
     self.assertTrue(sundays_added)
示例#9
0
    def get_terms_in_day(cls, date, ajax=False):
        from apps.schedule.models.term import Term as EventTerm
        from apps.enrollment.courses.models.semester import Semester, Freeday, ChangedDay
        from apps.enrollment.courses.models.term import Term

        rooms = cls.get_in_institute(reservation=True)

        if not ajax:
            return rooms

        # build a dictionary

        result = {}

        for room in rooms:

            if room.number not in result:
                result[room.number] = {
                    'id': room.id,
                    'number': room.number,
                    'capacity': room.capacity,
                    'type': room.get_type_display(),
                    'description': room.description,
                    'title': room.number,
                    'terms': []
                }

        # fill event terms

        terms = EventTerm.objects.filter(day=date,
                                         room__in=rooms,
                                         event__status='1').select_related(
                                             'room', 'event')

        def make_dict(start_time, end_time, title):
            return {
                'begin': ':'.join(str(start_time).split(':')[:2]),
                'end': ':'.join(str(end_time).split(':')[:2]),
                'title': title
            }

        for term in terms:
            result[term.room.number]['terms'].append(
                make_dict(term.start, term.end, term.event.title))

        if not Freeday.is_free(date):

            # get weekday and semester

            weekday = ChangedDay.get_day_of_week(date)
            selected_semester = Semester.get_semester(date)

            if selected_semester is None:
                return

            if selected_semester.lectures_beginning > date or date > selected_semester.lectures_ending:
                return json.dumps(result)

            # get courses data

            course_terms = Term.objects.filter(dayOfWeek=weekday,
                                               group__course__semester=selected_semester)\
                .select_related('classroom', 'group').prefetch_related('classrooms')

            # fill courses data

            for course_term in course_terms:
                for classroom in course_term.classrooms.all():
                    if classroom not in rooms:
                        continue
                    result[classroom.number]['terms'].append(
                        make_dict(course_term.start_time, course_term.end_time,
                                  course_term.group.course.name))
                if course_term.classroom is None:
                    continue
                result[course_term.classroom.number]['terms'].append(
                    make_dict(course_term.start_time, course_term.end_time,
                              course_term.group.course.name))
        return json.dumps(result)
示例#10
0
 def test_number_of_reservations(self):
     semester = Semester.get_semester(date(2016, 5, 12))
     reservations = SpecialReservation.get_reservations_for_semester(semester)
     self.assertEqual(len(reservations), 3)
示例#11
0
 def test_no_reservations_on_not_reserved_day(self):
     semester = Semester.get_semester(date(2016, 5, 12))
     reservations = SpecialReservation.get_reservations_for_semester(semester, day=common.FRIDAY)
     self.assertFalse(reservations)
示例#12
0
 def test_created_reservation_is_present(self):
     semester = Semester.get_semester(date(2016, 5, 12))
     reservations = SpecialReservation.get_reservations_for_semester(semester)
     self.assertTrue(reservations)