Ejemplo n.º 1
0
    def check_program_files(self, data):
        self.__teachers_file = []
        if 'program_files' in self.changed_data:
            if data.get('program_files', ""):
                with Archive(fileobj=data['program_files']) as archive:
                    if archive.is_archive():
                        self.__teachers_file = [a.split("/")[-1] for a in archive.getfile_members()]
                    else:
                        if is_valid(filename=data['program_files'].name, interpreter=pickle.loads(data['execution_command'])[0]):
                            self.__teachers_file = [data['program_files'].name]
                        else:
                            self._errors['program_files'] = self.error_class(["This file was not valid."])
                            del data['program_files']
            else: # file is being deleted.
                pass
        else: # No change in file field. Check if file exist in database.
            if not hasattr(self, 'program_model'):
                return # Assignment is created without model solution.

            if not self.program_model.program_files: return # no file in database.

            with Archive(fileobj=self.program_model.program_files.file) as archive:
                if archive.is_archive():
                    self.__teachers_file = [a.split("/")[-1] for a in archive.getfile_members()]
                else:
                    if is_valid(filename=self.program_model.program_files.name, interpreter=pickle.loads(data['execution_command'])[0]):
                        self.__teachers_file = [self.program_model.program_files.name.split("/")[-1]]
                    else:
                        file_name = self.program_model.program_files.name.split("/")[-1]
                        self._errors['program_files'] = self.error_class(["File {0} is not valid. Please upload a valid file\
                            ".format(file_name)])
                        del data['program_files']
Ejemplo n.º 2
0
    def check_program_files(self, data):
        self.__teachers_file = []
        if 'program_files' in self.changed_data:
            if data.get('program_files', ""):
                with Archive(fileobj=data['program_files']) as archive:
                    if archive.is_archive():
                        self.__teachers_file = [
                            a.split("/")[-1]
                            for a in archive.getfile_members()
                        ]
                    else:
                        if is_valid(filename=data['program_files'].name,
                                    interpreter=pickle.loads(
                                        data['execution_command'])[0]):
                            self.__teachers_file = [data['program_files'].name]
                        else:
                            self._errors['program_files'] = self.error_class(
                                ["This file was not valid."])
                            del data['program_files']
            else:  # file is being deleted.
                pass
        else:  # No change in file field. Check if file exist in database.
            if not hasattr(self, 'program_model'):
                return  # Assignment is created without model solution.

            if not self.program_model.program_files:
                return  # no file in database.

            with Archive(
                    fileobj=self.program_model.program_files.file) as archive:
                if archive.is_archive():
                    self.__teachers_file = [
                        a.split("/")[-1] for a in archive.getfile_members()
                    ]
                else:
                    if is_valid(filename=self.program_model.program_files.name,
                                interpreter=pickle.loads(
                                    data['execution_command'])[0]):
                        self.__teachers_file = [
                            self.program_model.program_files.name.split("/")
                            [-1]
                        ]
                    else:
                        file_name = self.program_model.program_files.name.split(
                            "/")[-1]
                        self._errors['program_files'] = self.error_class([
                            "File {0} is not valid. Please upload a valid file\
                            ".format(file_name)
                        ])
                        del data['program_files']
Ejemplo n.º 3
0
    def check_model_solution(self, data):
        self._solution_file = []
        if 'model_solution' in self.changed_data:
            if data.get('model_solution', ""):
                with Archive(fileobj=data['model_solution']) as archive:
                    if not archive.is_archive():
                        if not is_valid(filename=data['model_solution'].name, lang=data['program_language']):
                            self._errors['model_solution'] = self.error_class(["This file was not valid."])
                            del data['model_solution']
                        else:
                            self._solution_file = [data['model_solution'].name]
                    else:
                        self._solution_file = [a.split("/")[-1] for a in archive.getfile_members()]
            else: # File is being deleted.
                pass
        else: # No change in file field. Check if file exist in database.
            if not hasattr(self, 'assignment_model'):
                return # Assignment is created without model solution.

            if not self.assignment_model.model_solution: return # no file in database.

            with Archive(fileobj=self.assignment_model.model_solution.file) as archive:
                if archive.is_archive():
                    self._solution_file = [a.split("/")[-1] for a in archive.getfile_members()]
                else:
                    file_name = self.assignment_model.model_solution.name.split("/")[-1]
                    self._solution_file = [file_name]
Ejemplo n.º 4
0
 def check_student_program_files(self, data):
     file_list = data.get('student_program_files').split()
     language = data.get('program_language')
     for afile in file_list:
         if not is_valid(afile, language):
             self._errors['student_program_files'] = self.error_class(["Only {1} files are accepted for {0} language.\
                 ".format(language, " ".join(get_extension(language)))])
             del data['student_program_files']
             break
Ejemplo n.º 5
0
 def check_student_program_files(self, data):
     file_list = data.get('student_program_files').split()
     language = data.get('program_language')
     for afile in file_list:
         if not is_valid(afile, language):
             self._errors['student_program_files'] = self.error_class([
                 "Only {1} files are accepted for {0} language.\
                 ".format(language, " ".join(get_extension(language)))
             ])
             del data['student_program_files']
             break
Ejemplo n.º 6
0
 def check_execution_command(self, data):
     execution_command = pickle.loads(data.get('execution_command'))
     if get_interpreter_name(self.assignment.program_language) != execution_command[0]:
         self._errors['execution_command'] = self.error_class(["Invalid interpreter for {0} language .\
                 ".format(self.assignment.program_language)])
         del data['execution_command']
         return
     for afile in execution_command[2].split():
         if not is_valid(filename=afile, interpreter=execution_command[0]):
             self._errors['execution_command'] = self.error_class(["Only {1} files are accepted for {0} interpreter.\
                 ".format(execution_command[0], " ".join(get_extension(execution_command[0])))])
             del data['execution_command']
Ejemplo n.º 7
0
 def check_execution_command(self, data):
     execution_command = pickle.loads(data.get('execution_command'))
     if get_interpreter_name(
             self.assignment.program_language) != execution_command[0]:
         self._errors['execution_command'] = self.error_class([
             "Invalid interpreter for {0} language .\
                 ".format(self.assignment.program_language)
         ])
         del data['execution_command']
         return
     for afile in execution_command[2].split():
         if not is_valid(filename=afile, interpreter=execution_command[0]):
             self._errors['execution_command'] = self.error_class([
                 "Only {1} files are accepted for {0} interpreter.\
                 ".format(execution_command[0],
                          " ".join(get_extension(execution_command[0])))
             ])
             del data['execution_command']
Ejemplo n.º 8
0
    def check_model_solution(self, data):
        self._solution_file = []
        if 'model_solution' in self.changed_data:
            if data.get('model_solution', ""):
                with Archive(fileobj=data['model_solution']) as archive:
                    if not archive.is_archive():
                        if not is_valid(filename=data['model_solution'].name,
                                        lang=data['program_language']):
                            self._errors['model_solution'] = self.error_class(
                                ["This file was not valid."])
                            del data['model_solution']
                        else:
                            self._solution_file = [data['model_solution'].name]
                    else:
                        self._solution_file = [
                            a.split("/")[-1]
                            for a in archive.getfile_members()
                        ]
            else:  # File is being deleted.
                pass
        else:  # No change in file field. Check if file exist in database.
            if not hasattr(self, 'assignment_model'):
                return  # Assignment is created without model solution.

            if not self.assignment_model.model_solution:
                return  # no file in database.

            with Archive(fileobj=self.assignment_model.model_solution.file
                         ) as archive:
                if archive.is_archive():
                    self._solution_file = [
                        a.split("/")[-1] for a in archive.getfile_members()
                    ]
                else:
                    file_name = self.assignment_model.model_solution.name.split(
                        "/")[-1]
                    self._solution_file = [file_name]