コード例 #1
0
 def _create_group_comment_from_object_dict(self, object_dict):
     group_comment = self.get_model_class()()
     self.patch_model_from_object_dict(
         model_object=group_comment,
         object_dict=object_dict,
         attributes=[
             ('save_timestamp', 'created_datetime'),
             ('save_timestamp', 'published_datetime')
         ]
     )
     feedback_set = self._get_feedback_set_from_id(feedback_set_id=object_dict['fields']['deadline_id'])
     examiner_user = self._get_user_from_id_with_fallback(object_dict['fields']['saved_by'])
     group_comment.user = examiner_user
     self._save_and_publish_feedback_set(
         feedback_set=feedback_set,
         published_by=examiner_user,
         grading_points=object_dict['fields']['points'],
         publish_datetime=datetimeutils.from_isoformat(object_dict['fields']['save_timestamp'])
     )
     group_comment.feedback_set = feedback_set
     group_comment.part_of_grading = True
     group_comment.text = object_dict['fields']['rendered_view']
     group_comment.comment_type = GroupComment.COMMENT_TYPE_GROUPCOMMENT
     group_comment.user_role = GroupComment.USER_ROLE_EXAMINER
     group_comment.v2_id = modelimporter_utils.make_flat_v2_id(object_dict)
     if self.should_clean():
         group_comment.full_clean()
     group_comment.save()
     commentfiles = self._create_feedback_comment_files(
         group_comment,
         staticfeedback_id=object_dict['pk'],
         file_infos_dict=object_dict['fields']['files'])
     self.log_create(model_object=group_comment, data=object_dict)
     return group_comment, commentfiles
コード例 #2
0
 def _create_group_comment_from_object_dict(self, object_dict):
     group_comment = self.get_model_class()()
     self.patch_model_from_object_dict(
         model_object=group_comment,
         object_dict=object_dict,
         attributes=[
             ('save_timestamp', 'created_datetime'),
             ('save_timestamp', 'published_datetime')
         ]
     )
     feedback_set = self._get_feedback_set_from_id(feedback_set_id=object_dict['fields']['deadline_id'])
     examiner_user = self._get_user_from_id_with_fallback(object_dict['fields']['saved_by'])
     group_comment.user = examiner_user
     self._save_and_publish_feedback_set(
         feedback_set=feedback_set,
         published_by=examiner_user,
         grading_points=object_dict['fields']['points'],
         publish_datetime=datetimeutils.from_isoformat(object_dict['fields']['save_timestamp'])
     )
     group_comment.feedback_set = feedback_set
     group_comment.part_of_grading = True
     group_comment.text = object_dict['fields']['rendered_view']
     group_comment.comment_type = GroupComment.COMMENT_TYPE_GROUPCOMMENT
     group_comment.user_role = GroupComment.USER_ROLE_EXAMINER
     group_comment.v2_id = modelimporter_utils.make_flat_v2_id(object_dict)
     if self.should_clean():
         group_comment.full_clean()
     group_comment.save()
     commentfiles = self._create_feedback_comment_files(
         group_comment,
         staticfeedback_id=object_dict['pk'],
         file_infos_dict=object_dict['fields']['files'])
     self.log_create(model_object=group_comment, data=object_dict)
     return group_comment, commentfiles
コード例 #3
0
 def test_importer_start_time(self):
     test_admin_user = mommy.make(settings.AUTH_USER_MODEL)
     test_subject = mommy.make('core.Subject')
     self.create_v2dump(model_name='core.period',
                        data=self._create_period_dict(subject=test_subject, test_admin_user=test_admin_user))
     periodimporter = PeriodImporter(input_root=self.temp_root_dir)
     periodimporter.import_models()
     period = Period.objects.first()
     start_time = datetimeutils.from_isoformat('2017-02-14T11:04:46.585')
     self.assertEqual(period.start_time, start_time)
コード例 #4
0
    def handle(self, *args, **options):
        delete_older_than_datetime = datetimeutils.from_isoformat(
            options['datetime']).replace(second=0, microsecond=0)
        delete_empty_subjects = options['delete_empty_subjects']

        now = timezone.now()
        if delete_older_than_datetime >= now:
            self.stderr.write(
                'EXITING... Given datetime {} must be earlier than now ({})'.format(
                    arrow.get(delete_older_than_datetime.astimezone(
                        timezone.get_current_timezone())).format('MMM D. YYYY HH:mm'),
                    arrow.get(
                        now.astimezone(timezone.get_current_timezone())).format('MMM D. YYYY HH:mm')
                ))
            raise SystemExit()

        if not Period.objects.filter(end_time__lt=delete_older_than_datetime).exists():
            self.stderr.write(
                'EXITING... There are no semesters that ended before {}.'.format(
                    arrow.get(delete_older_than_datetime).format('MMM D. YYYY HH:mm')))
            raise SystemExit()

        self.stdout.write('###########################################################\n'
                          '# Delete all semesters that ended before: {}\n'
                          '# Delete subjects if all semester are deleted: {}'
                          '\n###########################################################'.format(
            arrow.get(delete_older_than_datetime).format('MMM D. YYYY HH:mm'),
            'YES' if delete_empty_subjects else 'NO'
        ))

        # Instantiate period deleter
        period_deleter = PeriodDelete(
            end_time_older_than_datetime=delete_older_than_datetime,
            delete_empty_subjects=delete_empty_subjects,
            log_info=True)

        self.stdout.write(
            '\nPreview of semesters that will be deleted:\n'.format(
                arrow.get(delete_older_than_datetime).format('MMM D. YYYY HH:mm')))
        self.stdout.write('\n')
        self.stdout.write(period_deleter.get_preview())
        self.stdout.write('\n')

        # User must confirm the deletion.
        self.__confirm_delete()

        # Start deletion
        with transaction.atomic():
            call_command('ievvtasks_customsql', '--clear')

            self.stdout.write('Deleting periods...')
            period_deleter.delete()

            call_command('ievvtasks_customsql', '-i', '-r')
コード例 #5
0
 def test_importer_end_time(self):
     test_admin_user = mommy.make(settings.AUTH_USER_MODEL)
     test_subject = mommy.make('core.Subject')
     self.create_v2dump(model_name='core.period',
                        data=self._create_period_dict(
                            subject=test_subject,
                            test_admin_user=test_admin_user))
     periodimporter = PeriodImporter(input_root=self.temp_root_dir)
     periodimporter.import_models()
     period = Period.objects.first()
     end_time = datetimeutils.from_isoformat('2017-08-13T11:04:46.585')
     self.assertEquals(period.end_time, end_time)
コード例 #6
0
    def handle(self, *args, **options):
        inactive_since_datetime = datetimeutils.from_isoformat(
            options['inactive_since_datetime']).replace(second=0, microsecond=0)

        # Inactive since must be earlier than now
        now = timezone.now()
        if inactive_since_datetime >= now:
            self.stderr.write(
                'EXITING... Given datetime ({}) must be earlier than now ({})'.format(
                    arrow.get(inactive_since_datetime.astimezone(
                        timezone.get_current_timezone())).format('MMM D. YYYY HH:mm'),
                    arrow.get(now.astimezone(timezone.get_current_timezone())).format('MMM D. YYYY HH:mm')
                ))
            raise SystemExit()

        # Instantiate the user deleter.
        user_deleter = InactiveUserDeleter(inactive_since_datetime=inactive_since_datetime)

        # Check if users exist.
        if not user_deleter.get_users_to_delete_queryset().exists():
            self.stdout.write(self.style.ERROR('EXITING... There are no users with last login before {}.'.format(
                arrow.get(inactive_since_datetime).format('MMM D. YYYY HH:mm'))))
            raise SystemExit()

        self.stdout.write('############################################################\n'
                          '# Delete all users with last login before: {}'
                          '\n############################################################'.format(
            arrow.get(inactive_since_datetime).format('MMM D. YYYY HH:mm')
        ))
        self.stdout.write('\n')

        # Confirm show preview of users to be deleted
        self.stdout.write('Preview of all users that will be deleted:\n\n')
        self.__preview(user_deleter=user_deleter)

        # User must confirm the deletion.
        self.stdout.write('\n\nThis action will delete {} users.'.format(
            user_deleter.get_users_to_delete_queryset().count()))
        self.__confirm_delete()

        # Start deletion
        with transaction.atomic():
            call_command('ievvtasks_customsql', '--clear')

            self.stdout.write('Deleting users...')
            user_deleter.delete()

            call_command('ievvtasks_customsql', '-i', '-r')
コード例 #7
0
    def handle(self, *args, **options):
        inactive_since_datetime = datetimeutils.from_isoformat(
            options['inactive_since_datetime']).replace(second=0, microsecond=0)

        # Inactive since must be earlier than now
        now = timezone.now()
        if inactive_since_datetime >= now:
            self.stderr.write(
                'EXITING... Given datetime ({}) must be earlier than now ({})'.format(
                    arrow.get(inactive_since_datetime.astimezone(
                        timezone.get_current_timezone())).format('MMM D. YYYY HH:mm'),
                    arrow.get(now.astimezone(timezone.get_current_timezone())).format('MMM D. YYYY HH:mm')
                ))
            raise SystemExit()

        # Instantiate the user deleter.
        user_deleter = InactiveUserDeleter(inactive_since_datetime=inactive_since_datetime)

        # Check if users exist.
        if not user_deleter.get_users_to_delete_queryset().exists():
            self.stdout.write(self.style.ERROR('EXITING... There are no users with last login before {}.'.format(
                arrow.get(inactive_since_datetime).format('MMM D. YYYY HH:mm'))))
            raise SystemExit()

        self.stdout.write('############################################################\n'
                          '# Delete all users with last login before: {}'
                          '\n############################################################'.format(
            arrow.get(inactive_since_datetime).format('MMM D. YYYY HH:mm')
        ))
        self.stdout.write('\n')

        # Confirm show preview of users to be deleted
        self.stdout.write('Preview of all users that will be deleted:\n\n')
        self.__preview(user_deleter=user_deleter)

        # User must confirm the deletion.
        self.stdout.write('\n\nThis action will delete {} users.'.format(
            user_deleter.get_users_to_delete_queryset().count()))
        self.__confirm_delete()

        # Start deletion
        with transaction.atomic():
            call_command('ievvtasks_customsql', '--clear')

            self.stdout.write('Deleting users...')
            user_deleter.delete()

            call_command('ievvtasks_customsql', '-i', '-r')
コード例 #8
0
 def patch_model_from_object_dict(self, model_object, object_dict,
                                  attributes):
     for attribute in attributes:
         if isinstance(attribute, tuple):
             from_attribute, to_attribute = attribute
         else:
             from_attribute = attribute
             to_attribute = attribute
         if from_attribute == 'pk':
             value = object_dict[from_attribute]
         else:
             value = object_dict['fields'][from_attribute]
             if value:
                 field = model_object._meta.get_field(to_attribute)
                 if isinstance(field, models.DateTimeField):
                     value = datetimeutils.from_isoformat(value)
         setattr(model_object, to_attribute, value)
コード例 #9
0
 def test_importer_feedback_set_grading_published_datetime(self):
     test_examiner_user = mommy.make(settings.AUTH_USER_MODEL)
     test_group = mommy.make('core.AssignmentGroup')
     mommy.make('core.Examiner',
                assignmentgroup=test_group,
                relatedexaminer__user=test_examiner_user,
                relatedexaminer__period=test_group.parentnode.parentnode)
     test_feedbackset = mommy.make('devilry_group.FeedbackSet', group=test_group)
     staticfeedback_data_dict = self._create_staticfeedback_dict(
         feedback_set=test_feedbackset,
         examiner_user_id=test_examiner_user.id
     )
     self.create_v2dump(
         model_name='core.staticfeedback',
         data=staticfeedback_data_dict
     )
     StaticFeedbackImporter(input_root=self.temp_root_dir).import_models()
     feedback_set = GroupComment.objects.first().feedback_set
     self.assertEqual(
         feedback_set.grading_published_datetime,
         datetimeutils.from_isoformat(staticfeedback_data_dict['fields']['save_timestamp']))
コード例 #10
0
 def test_importer_feedback_set_grading_published_datetime(self):
     test_examiner_user = mommy.make(settings.AUTH_USER_MODEL)
     test_group = mommy.make('core.AssignmentGroup')
     mommy.make('core.Examiner',
                assignmentgroup=test_group,
                relatedexaminer__user=test_examiner_user,
                relatedexaminer__period=test_group.parentnode.parentnode)
     test_feedbackset = mommy.make('devilry_group.FeedbackSet', group=test_group)
     staticfeedback_data_dict = self._create_staticfeedback_dict(
         feedback_set=test_feedbackset,
         examiner_user_id=test_examiner_user.id
     )
     self.create_v2dump(
         model_name='core.staticfeedback',
         data=staticfeedback_data_dict
     )
     StaticFeedbackImporter(input_root=self.temp_root_dir).import_models()
     feedback_set = GroupComment.objects.first().feedback_set
     self.assertEquals(
         feedback_set.grading_published_datetime,
         datetimeutils.from_isoformat(staticfeedback_data_dict['fields']['save_timestamp']))
コード例 #11
0
    def handle(self, *args, **options):
        delete_older_than_datetime = datetimeutils.from_isoformat(
            options['datetime']).replace(second=0, microsecond=0)
        delete_empty_subjects = options['delete_empty_subjects']

        now = timezone.now()
        if delete_older_than_datetime >= now:
            self.stderr.write(
                'EXITING... Given datetime {} must be earlier than now ({})'.
                format(
                    arrow.get(
                        delete_older_than_datetime.astimezone(
                            timezone.get_current_timezone())).format(
                                'MMM D. YYYY HH:mm'),
                    arrow.get(now.astimezone(
                        timezone.get_current_timezone())).format(
                            'MMM D. YYYY HH:mm')))
            raise SystemExit()

        if not Period.objects.filter(
                end_time__lt=delete_older_than_datetime).exists():
            self.stderr.write(
                'EXITING... There are no semesters that ended before {}.'.
                format(
                    arrow.get(delete_older_than_datetime).format(
                        'MMM D. YYYY HH:mm')))
            raise SystemExit()

        self.stdout.write(
            '###########################################################\n'
            '# Delete all semesters that ended before: {}\n'
            '# Delete subjects if all semester are deleted: {}'
            '\n###########################################################'.
            format(
                arrow.get(delete_older_than_datetime).format(
                    'MMM D. YYYY HH:mm'),
                'YES' if delete_empty_subjects else 'NO'))

        # Instantiate period deleter
        period_deleter = PeriodDelete(
            end_time_older_than_datetime=delete_older_than_datetime,
            delete_empty_subjects=delete_empty_subjects,
            log_info=True)

        self.stdout.write(
            '\nPreview of semesters that will be deleted:\n'.format(
                arrow.get(delete_older_than_datetime).format(
                    'MMM D. YYYY HH:mm')))
        self.stdout.write('\n')
        self.stdout.write(period_deleter.get_preview())
        self.stdout.write('\n')

        # User must confirm the deletion.
        self.__confirm_delete()

        # Start deletion
        with transaction.atomic():
            call_command('ievvtasks_customsql', '--clear')

            self.stdout.write('Deleting periods...')
            period_deleter.delete()

            call_command('ievvtasks_customsql', '-i', '-r')