コード例 #1
0
ファイル: models.py プロジェクト: spacedman/mayan
    def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None):
        if not document:
            document = Document()
            if document_type:
                document.document_type = document_type
            document.save()            

            if metadata_dict_list:
                save_metadata_list(metadata_dict_list, document, create=True)
            warnings = update_indexes(document)

            if user:
                document.add_as_recent_document_for_user(user)
                create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
            else:
                create_history(HISTORY_DOCUMENT_CREATED, document)
        else:
            if use_file_name:
                filename = None
            else:
                filename = filename if filename else document.latest_version.filename

        if not new_version_data:
            new_version_data = {}
            
        new_version = document.new_version(file=file_object, **new_version_data)
        if filename:
            new_version.filename = filename
            new_version.save()

        transformations, errors = self.get_transformation_list()

        new_version.apply_default_transformations(transformations)
コード例 #2
0
    def upload_single_file(self,
                           file_object,
                           filename=None,
                           use_file_name=False,
                           document_type=None,
                           metadata_dict_list=None,
                           user=None,
                           document=None,
                           new_version_data=None):
        new_document = not document

        if not document:
            document = Document()
            if document_type:
                document.document_type = document_type
            document.save()

            apply_default_acls(document, user)

            if user:
                document.add_as_recent_document_for_user(user)
                create_history(HISTORY_DOCUMENT_CREATED, document,
                               {'user': user})
            else:
                create_history(HISTORY_DOCUMENT_CREATED, document)
        else:
            if use_file_name:
                filename = None
            else:
                filename = filename if filename else document.latest_version.filename

        if not new_version_data:
            new_version_data = {}

        try:
            new_version = document.new_version(file=file_object,
                                               user=user,
                                               **new_version_data)
        except Exception:
            # Don't leave the database in a broken state
            # document.delete()
            transaction.rollback()
            raise

        if filename:
            document.rename(filename)

        transformations, errors = self.get_transformation_list()

        new_version.apply_default_transformations(transformations)
        #TODO: new HISTORY for version updates

        if metadata_dict_list and new_document:
            # Only do for new documents
            save_metadata_list(metadata_dict_list, document, create=True)
            warnings = update_indexes(document)

        return document
コード例 #3
0
ファイル: models.py プロジェクト: EmlynC/mayan-edms
    def upload_single_file(self, file_object, filename=None, use_file_name=False, document_type=None, metadata_dict_list=None, user=None, document=None, new_version_data=None, description=None):
        new_document = not document

        if not document:
            document = Document()
            if document_type:
                document.document_type = document_type

            if description:
                document.description = description

            document.save()

            apply_default_acls(document, user)

            if user:
                document.add_as_recent_document_for_user(user)
                create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
            else:
                create_history(HISTORY_DOCUMENT_CREATED, document)
        else:
            if use_file_name:
                filename = None
            else:
                filename = filename if filename else document.latest_version.filename

            if description:
                document.description = description
                document.save()

        if not new_version_data:
            new_version_data = {}

        new_version = document.new_version(file=file_object, user=user, **new_version_data)

        if filename:
            document.rename(filename)

        transformations, errors = self.get_transformation_list()

        new_version.apply_default_transformations(transformations)
        # TODO: new HISTORY for version updates

        if metadata_dict_list and new_document:
            # Only do for new documents
            save_metadata_list(metadata_dict_list, document, create=True)
            warnings = update_indexes(document)
コード例 #4
0
 def handle_noargs(self, **options):
     doc_dir = os.path.join(os.path.dirname(__file__), '..', '..',
         'fixtures')
     
     doctypes = DocumentType.objects.all()
     programs = Program.objects.all()
     users = IntranetUser.objects.all()
     
     for i in range(1000):
         for f in os.listdir(doc_dir):
             doc = Document()
             doc.title = random.random()
             doc.file = File(open(os.path.join(doc_dir, f)))
             doc.notes = random.random()
             doc.document_type = random.choice(doctypes)
             doc.save()
             doc.programs = random.sample(programs, 2)
             doc.authors = random.sample(users, 1)
コード例 #5
0
ファイル: models.py プロジェクト: IHLeanne/mayan
    def upload_single_file(self, file_object, filename=None, document_type=None, metadata_dict_list=None, user=None):
        transformations, errors = self.get_transformation_list()
        document = Document(file=file_object)
        if document_type:
            document.document_type = document_type
        document.save()
        if filename:
            document.file_filename = filename
            document.save()    

        document.apply_default_transformations(transformations)

        if metadata_dict_list:
            save_metadata_list(metadata_dict_list, document, create=True)
        warnings = update_indexes(document)

        if user:
            document.add_as_recent_document_for_user(user)
            create_history(HISTORY_DOCUMENT_CREATED, document, {'user': user})
        else:
            create_history(HISTORY_DOCUMENT_CREATED, document)