Beispiel #1
0
 def _get_list(self):
     qry = Period.where_is_admin_or_superadmin(self.request.user)
     qry = qry.filter(Period.q_is_active())
     qry = qry.prefetch_related("qualifiedforexams_status")
     qry = qry.select_related("parentnode")
     qry = qry.order_by("start_time")
     return [self._listserialize_period(period) for period in qry]
 def test_q_is_active(self):
     activeperiods = Period.objects.filter(Period.q_is_active())
     self.assertEquals(activeperiods.count(), 1)
     self.assertEqual(activeperiods[0], self.inf1100_looong)
     self.inf1100_old.end_time = datetime.now() + timedelta(days=10)
     self.inf1100_old.save()
     self.assertEquals(Period.objects.filter(Period.q_is_active()).count(), 2)
Beispiel #3
0
 def test_q_is_active(self):
     activeperiods = Period.objects.filter(Period.q_is_active())
     self.assertEquals(activeperiods.count(), 1)
     self.assertEqual(activeperiods[0], self.inf1100_looong)
     self.inf1100_old.end_time = timezone.now() + timedelta(days=10)
     self.inf1100_old.save()
     self.assertEquals(
         Period.objects.filter(Period.q_is_active()).count(), 2)
Beispiel #4
0
 def _get_list(self):
     qry = Period.where_is_admin_or_superadmin(self.request.user)
     qry = qry.filter(Period.q_is_active())
     if self.request.GET.get('node_id', None) != None:
         qry = qry.filter(parentnode__parentnode=self.request.GET['node_id'])
     qry = qry.prefetch_related('qualifiedforexams_status')
     qry = qry.select_related('parentnode')
     qry = qry.order_by('parentnode__long_name', 'start_time')
     return [self._listserialize_period(period) for period in qry]
Beispiel #5
0
 def test_unique(self):
     n = Period(parentnode=Subject.objects.get(short_name='inf1100'),
                short_name='old',
                long_name='Old',
                start_time=timezone.now(),
                end_time=timezone.now())
     self.assertRaises(IntegrityError, n.save)
 def test_published_where_is_examiner(self):
     examiner1 = User.objects.get(username='******')
     self.add_to_path('uio.ifi;inf1010.spring10:begins(-1):ends(2).oblig1.student1:examiner(examiner1)')
     q = Period.published_where_is_examiner(examiner1).order_by('short_name')
     self.assertEquals(q.count(), 3)
     assignment1010 = self.inf1010_spring10_oblig1_student1.parentnode
     assignment1010.publishing_time = datetime.now() + timedelta(10)
     assignment1010.save()
     self.assertEquals(q.count(), 2)
 def test_where_is_examiner(self):
     q = Period.where_is_examiner(self.examiner1).order_by('short_name')
     self.assertEquals(q.count(), 2)
     self.assertEquals(q[0].short_name, 'looong')
     self.assertEquals(q[1].short_name, 'old')
     # Add on different period
     self.add_to_path('uio.ifi;inf1010.spring10.oblig1.student1:examiner(examiner1)')
     self.assertEquals(q.count(), 3)
     self.assertEquals(q[0].short_name, 'looong')
     self.assertEquals(q[1].short_name, 'old')
     self.assertEquals(q[2].short_name, 'spring10')
Beispiel #8
0
 def test_where_is_examiner(self):
     q = Period.where_is_examiner(self.examiner1).order_by('short_name')
     self.assertEquals(q.count(), 2)
     self.assertEquals(q[0].short_name, 'looong')
     self.assertEquals(q[1].short_name, 'old')
     # Add on different period
     self.add_to_path(
         'uio.ifi;inf1010.spring10.oblig1.student1:examiner(examiner1)')
     self.assertEquals(q.count(), 3)
     self.assertEquals(q[0].short_name, 'looong')
     self.assertEquals(q[1].short_name, 'old')
     self.assertEquals(q[2].short_name, 'spring10')
Beispiel #9
0
 def get(self, request, status_id):
     try:
         self.status = Status.objects.get(pk=status_id)
     except Status.DoesNotExist:
         return HttpResponseNotFound()
     else:
         if not Period.where_is_admin_or_superadmin(self.request.user).filter(id=self.status.period_id).exists():
             return HttpResponseForbidden()
         elif self.status.status != Status.READY:
             return HttpResponseNotFound()
         else:
             return super(StatusPrintView, self).get(request, status_id)
Beispiel #10
0
 def test_published_where_is_examiner(self):
     examiner1 = get_user_model().objects.get(shortname='examiner1')
     self.add_to_path(
         'uio.ifi;inf1010.spring10:begins(-1):ends(2).oblig1.student1:examiner(examiner1)'
     )
     q = Period.published_where_is_examiner(examiner1).order_by(
         'short_name')
     self.assertEquals(q.count(), 3)
     assignment1010 = self.inf1010_spring10_oblig1_student1.parentnode
     assignment1010.publishing_time = timezone.now() + timedelta(10)
     assignment1010.save()
     self.assertEquals(q.count(), 2)
    def get(self, request, id):
        qry = Period.where_is_admin_or_superadmin(self.request.user).filter(id=id)
        if len(qry) == 0:
            return HttpResponseForbidden()
        period = qry[0]

        format = self.request.GET.get('format', None)
        if not format:
            return HttpResponseBadRequest('format is required.')

        exporter = self.exporters.get(format)
        if not exporter:
            return HttpResponseBadRequest('Invalid format: {0}. Valid formats: {1!r}'.format(
                format, self.exporters.keys()))

        filenameprefix = period.get_path()
        grouper = GroupsGroupedByRelatedStudentAndAssignment(period)
        return exporter(grouper, query=self.request.GET, filenameprefix=filenameprefix).response()
Beispiel #12
0
 def is_active(self, instance):
     return instance in Period.objects.filter(Period.q_is_active())
class Command(RecordSaveModCommand):
    # args = '<course short name> <period short_name>'
    date_and_time_format = "%Y-%m-%dT%H:%M"
    help = 'Create a new period.'

    def add_arguments(self, parser):
        parser.add_argument(
            'subject_short_name',
            help='Short name of the subject to add the period within.')
        parser.add_argument(
            'period_short_name',
            help='Short name of the period you want to create.')
        parser.add_argument('--long-name',
                            dest='long_name',
                            default=None,
                            required=True,
                            help='Long name of period (Required)'),
        parser.add_argument(
            '--start-time',
            dest='start_time',
            default=None,
            required=True,
            help=
            'The start time of the period on the format specified in --datetime-format (Required)'
        ),
        parser.add_argument(
            '--end-time',
            dest='end_time',
            default=None,
            required=True,
            help=
            'The end time of the period on the format specified in --datetime-format (Required)'
        ),
        parser.add_argument(
            '--datetime-format',
            dest='datetime_format',
            default=self.date_and_time_format,
            help='The date format expressed in a format according to '
            'strftime http://docs.python.org/library/datetime.html#strftime-strptime-behavior. '
            'Defaults to YYYY-MM-DDThh:mm')

    def handle(self, *args, **options):
        from devilry.apps.core.models import Subject, Period
        subject_short_name = options['subject_short_name']
        period_short_name = options['period_short_name']
        # Get the subject
        try:
            self.subject = Subject.objects.get(short_name=subject_short_name)
        except Subject.DoesNotExist, e:
            raise CommandError('Subject with short name %s does not exist.' %
                               subject_short_name)

        verbosity = int(options.get('verbosity', '1'))
        date_and_time_format = options['datetime_format']
        start_time = datetime.strptime(options['start_time'],
                                       date_and_time_format)
        end_time = datetime.strptime(options['end_time'], date_and_time_format)

        if Period.objects.filter(parentnode=self.subject,
                                 short_name=period_short_name).count() == 0:
            period_long_name = options['long_name']
            record = Period(short_name=period_short_name,
                            long_name=period_long_name,
                            parentnode=self.subject,
                            start_time=start_time,
                            end_time=end_time)
            self.save_record(record, verbosity)
        else:
            raise CommandError(
                'Period "{0}" already exists.'.format(period_short_name))
 def test_where_is_admin(self):
     self.assertEquals(Period.where_is_admin(self.uioadmin).count(), 2)
 def check_permission(self, user):
     if user.is_superuser:
         return
     periodid = self.get_id()
     if Period.where_is_admin_or_superadmin(user).filter(id=periodid).count() == 0:
         raise PermissionDeniedError('Permission denied')
Beispiel #16
0
 def _permissioncheck(self, period):
     if self.request.user.is_superuser:
         return
     if not Period.where_is_admin(self.request.user).filter(id=period.id).exists():
         raise ErrorResponse(status=statuscodes.HTTP_403_FORBIDDEN)
Beispiel #17
0
 def get_plugin_input_and_authenticate(self):
     self.periodid = self.request.GET['periodid']
     if not Period.where_is_admin_or_superadmin(self.request.user).filter(id=self.periodid).exists():
         raise PermissionDenied()
     self.period = get_object_or_404(Period, pk=self.periodid)
     self.pluginsessionid = self.request.GET['pluginsessionid']
Beispiel #18
0
class Command(RecordSaveModCommand):
    args = '<course short name> <period short_name>'
    date_and_time_format = "%Y-%m-%dT%H:%M"
    help = 'Create a new period.'
    option_list = BaseCommand.option_list + (
        make_option('--admins',
                    dest='admins',
                    default=None,
                    help='Administrator usernames separated by comma (,).'),
        make_option('--long-name',
                    dest='long_name',
                    default=None,
                    help='Long name of period (Required)'),
        make_option(
            '--start-time',
            dest='start_time',
            default=None,
            help='The start time of the period on the ISO format %s (Required)'
            % date_and_time_format),
        make_option(
            '--end-time',
            dest='end_time',
            default=None,
            help='The end time of the period on the ISO format %s (Required)' %
            date_and_time_format),
        make_option(
            '--date-format',
            dest='date_format',
            default=None,
            help=
            'The date format expressed in a format according to strftime http://docs.python.org/library/datetime.html#strftime-strptime-behavior'
        ))

    def handle(self, *args, **options):
        if len(args) != 2:
            raise CommandError(
                'Course short name and period short name is required. See --help.'
            )
        if options['long_name'] == None:
            raise CommandError('Long name is required. See --help.')
        if options['start_time'] == None:
            raise CommandError('Start time name is required. See --help.')
        if options['end_time'] == None:
            raise CommandError('End time is required. See --help.')
        course_short_name = args[0]
        period_short_name = args[1]
        # Get the course
        try:
            self.subject = Subject.objects.get(short_name=course_short_name)
        except Subject.DoesNotExist, e:
            raise CommandError('Subject with short name %s does not exist.' %
                               course_short_name)

        verbosity = int(options.get('verbosity', '1'))

        if options['date_format'] != None:
            self.date_and_time_format = options['date_format']

        start_time = datetime.strptime(options['start_time'],
                                       self.date_and_time_format)
        end_time = datetime.strptime(options['end_time'],
                                     self.date_and_time_format)

        if Period.objects.filter(parentnode=self.subject,
                                 short_name=period_short_name).count() == 0:
            period_long_name = options['long_name']
            record = Period(short_name=period_short_name,
                            long_name=period_long_name,
                            parentnode=self.subject,
                            start_time=start_time,
                            end_time=end_time)
            self.save_record(record, verbosity)
        else:
            raise CommandError(
                'Period "{0}" already exists.'.format(period_short_name))