예제 #1
0
    def add_file(self, submission_gus, file_name, content_type, file_size):

        store = self.getStore('add_file')

        try:
            submission_r = store.find(Submission, Submission.submission_gus==submission_gus).one()
        except NotOneError:
            store.close()
            raise SubmissionGusNotFound
        if not submission_r:
            store.close()
            raise SubmissionGusNotFound

        new_file = File()
        new_file.file_gus = ret_file_gus = unicode(idops.random_file_gus())
        new_file.name = file_name
        new_file.content_type = content_type
        new_file.size = file_size

        submission_r.files.update({ new_file.file_gus : file_name })

        log.debug("Added file %s in submission %s with name %s" % (ret_file_gus, submission_gus, file_name))

        store.add(new_file)
        store.commit()
        store.close()

        return ret_file_gus
예제 #2
0
    def new(self, received_dict):

        try:
            self.file_gus = unicode(idops.random_file_gus())

            self._import_dict(received_dict)

            # these fields are accepted only in new()
            self.content_type = unicode(received_dict['content_type'])
            self.size = int(received_dict['file_size'])
            self.context_gus = unicode(received_dict['context_gus'])

            # catch a file uploaded in a Tip of in a Submission
            if received_dict['submission_gus']:
                self.submission_gus = unicode(received_dict['submission_gus'])
                self.internaltip_id = 0
            elif received_dict['internaltip_id']:
                self.internaltip_id = int(received_dict['internaltip_id'])
                self.submission_gus = None
            else:
                raise NotImplementedError("Missing Submission/InternalTip value")

        except KeyError, e:
            raise InvalidInputFormat("File import failed (missing %s)" % e)
예제 #3
0
            raise InvalidInputFormat("File import failed (missing %s)" % e)
        except TypeError, e:
            raise InvalidInputFormat("File import failed (wrong %s)" % e)

        try:
            self.context = store.find(Context, Context.context_gus == self.context_gus).one()

        except NotOneError:
            # This can never happen
            raise Exception("Internal Impossible Error")

        self.mark = self._marker[0] # not processed
        self.completed = False
        self.uploaded_date = gltime.utcTimeNow()

        self.file_gus = unicode(idops.random_file_gus())

        # When the file is 'not processed', this value stay to 0
        self.internaltip_id = 0

        store.add(self)
        return self._description_dict()


    # update in short modify only filename and description, at the moment API is missing
    # Remind open ticket with GLClient
    @transact
    def update(self, file_gus, received_dict):

        store = self.getStore()