当前位置: 首页>>代码示例>>Python>>正文


Python Document.save方法代码示例

本文整理汇总了Python中documents.models.Document.save方法的典型用法代码示例。如果您正苦于以下问题:Python Document.save方法的具体用法?Python Document.save怎么用?Python Document.save使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在documents.models.Document的用法示例。


在下文中一共展示了Document.save方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。

示例1: upload_single_file

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
    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)
开发者ID:mabroor,项目名称:mayan,代码行数:35,代码来源:models.py

示例2: upload_document

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
def upload_document(request):
	if request.method == 'GET':
		return render_to_response('documents/document_upload.html',
								  RequestContext(request),
								  context_instance=RequestContext(request)
		)

	elif request.method == 'POST':
		
		try:
			content_type = ContentType.objects.get(name=request.POST['ctype'])
			object_id = request.POST['objid']
		except:
			content_type = None
			object_id = None
		try:
			int(object_id)
		except: 
			if object_id is not None:
				object_id = Layer.objects.get(uuid=object_id).id

		file = request.FILES['file']
		title = request.POST['title']
		document = Document(content_type=content_type, object_id=object_id, title=title, file=file)
		document.owner = request.user
		document.save()
		document.set_default_permissions()
		permissionsStr = request.POST['permissions']
		permissions = json.loads(permissionsStr)
		set_document_permissions(document, permissions)

		return HttpResponse(json.dumps({'success': True,'redirect_to':'/documents/' + str(document.id)}))
开发者ID:sativa,项目名称:geonode-documents,代码行数:34,代码来源:views.py

示例3: save_document

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
def save_document(provider, title, href, images, embed, desc, duration, views, categories):
    from documents.models import Document, Category, Image

    try:
        doc = Document.objects.get(href=href)
    except Document.DoesNotExist:
        doc = Document()
        doc.provider = provider
        doc.title = title
        doc.href = href
        doc.embed = embed
        doc.desc = desc
        doc.duration = duration

    locale.setlocale(locale.LC_ALL, 'en_US.UTF-8')
    doc.views = locale.atoi(views)
    doc.save()
    
    if doc.images.count() == 0:
        for image_url in images:
            response = requests.get(image_url)
            if response.status_code == 200:
                image = Image()
                image.document = doc
                image.url = image_url
                image.save()

    for category in categories:
        cat = Category.objects.get_or_create(title=category)
        doc.categories.add(cat[0])
开发者ID:genxstylez,项目名称:meow,代码行数:32,代码来源:signals.py

示例4: report

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
def report(request, lot_number):
    report = Report.objects.get(lot_number=lot_number)
    audit_log = target_stream(report)
    orders = OrderLineItem.objects.filter(report=report)
    newdoc = NewDocumentForm(None)

    if 'document_button' in request.POST:
        newdoc = NewDocumentForm(request.POST, request.FILES)
        if newdoc.is_valid():
            doc = Document(type=newdoc.cleaned_data['type'],
                           file=request.FILES['file'], created_by=request.user)
            doc.save()
            action.send(request.user, verb="created document", action_object=doc)
            rd = ReportDocument(report=report, document=doc, primary_document=newdoc.cleaned_data['primary'], created_by=request.user, internal_cert=newdoc.cleaned_data['internal'])
            rd.save()
            action.send(request.user, verb="attached document", action_object=rd, target=report)
            report.save()
            messages.success(request, 'Document upload successful.')

            return HttpResponseRedirect(reverse('reports.views.report',
                                                    args=[report.lot_number]))
	
	
    return render_to_response('reports/report.html', 
                              {
                                  'report': report,
                                  'new_document_form': newdoc,
                                  'orders': orders,
                                  'audit_log': audit_log,
                              },
                              context_instance=RequestContext(request))
开发者ID:DisfluxTest,项目名称:django-mtr,代码行数:33,代码来源:views.py

示例5: split_doc

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
def split_doc(request):
    if request.is_ajax():
        results = {}
        cut = int(request.GET["modal_split_cut"][0])
        doc = Document.objects.get(pk=int(request.GET["modal_split_doc_id"]))
        doc.name = request.GET["modal_split_name"]
        new_doc = Document(
            name=request.GET["modal_split_new_name"],
            owner=request.user,
            refer_category=doc.refer_category,
            complete=True,
        )
        pages = doc.pages.all()
        new_doc.save()
        i = 0
        for p in pages:
            if i >= cut:
                new_doc.pages.add(p)
                new_doc.size += p.get_size()
                p.refer_document = new_doc
                p.save()
                doc.size -= p.get_size()
                doc.pages.remove(p)
            i += 1
        doc.refer_category.documents.add(new_doc)
        doc.save()
        new_doc.save()
        results["valid"] = True
        return HttpResponse(json.dumps(results))
开发者ID:Foxugly,项目名称:MyTaxAccountant,代码行数:31,代码来源:views.py

示例6: DocumentSearchTestCase

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
class DocumentSearchTestCase(unittest.TestCase):
    def setUp(self):
        # Start the OCR queue
        self.default_queue = DocumentQueue.objects.get(name='default')

    def test_do_document_ocr(self):
        self.document_type = DocumentType(name='test doc type')
        self.document_type.save()

        self.document = Document(
            document_type=self.document_type,
            description='description',
        )
        self.document.save()

        file_object = open(os.path.join(settings.SITE_ROOT, 'contrib', 'sample_documents', 'title_page.png'))
        new_version = self.document.new_version(file=File(file_object, name='title_page.png'))
        file_object.close()

        self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 1)

        do_document_ocr(self.default_queue.queuedocument_set.all()[0])

        self.assertTrue(u'Mayan EDMS' in self.document.pages.all()[0].content)

    def tearDown(self):
        self.document.delete()
        self.document_type.delete()
开发者ID:cccs-web,项目名称:mayan-edms,代码行数:30,代码来源:tests.py

示例7: DocumentSearchTestCase

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
class DocumentSearchTestCase(unittest.TestCase):
    def setUp(self):
        # Start the OCR queue
        self.default_queue = DocumentQueue.objects.get(name='default')

    def test_do_document_ocr(self):
        self.document_type = DocumentType(name='test doc type')
        self.document_type.save()

        self.document = Document(
            document_type=self.document_type,
            description='description',
        )
        self.document.save()

        with open(TEST_DOCUMENT_PATH) as file_object:
            self.document.new_version(file=File(file_object, name='title_page.png'))

        self.failUnlessEqual(self.default_queue.queuedocument_set.count(), 1)

        do_document_ocr(self.default_queue.queuedocument_set.all()[0])

        self.assertTrue(u'Mayan EDMS' in self.document.pages.all()[0].content)

    def tearDown(self):
        self.document.delete()
        self.document_type.delete()
开发者ID:pwhipp,项目名称:mayan-edms,代码行数:29,代码来源:tests.py

示例8: add_documents

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
def add_documents(request, category_id):
    if request.is_ajax():
        files = request.GET.getlist('files', False)
        cat = Category.objects.get(id=category_id)
        l_doc = []
        l_pdf = []
        cmds = []
        paths = []
        for f in list(files):
            mime = MimeTypes()
            path = os.path.join(settings.MEDIA_ROOT, settings.UPLOAD_DIR, f)
            m = mime.guess_type(path)[0]
            d = Document(name=f.encode('ascii', 'ignore'), owner=request.user, refer_category=cat)
            d.save()
            cat.add_doc(d)
            if m == 'application/pdf':
                l_pdf.append(([cat], path, f, [d]))
            elif m in ['image/png', 'image/jpeg', 'image/bmp']:
                im = Image.open(path)
                w, h = im.size
                new_filename = str(d.id) + '_' + f
                new_path = os.path.join(cat.get_absolute_path(), new_filename)
                shutil.copy2(path, new_path)
                d.add_page(d.get_npages() + 1, new_filename, w, h)
                for fu in FileUpload.objects.all():
                    if fu.file.path == path:
                        fu.delete()
                d.complete = True
                d.save()
                remove_fileupload([path])
            elif m in ['application/msword', 'application/vnd.openxmlformats-officedocument.wordprocessingml.document']:
                p = re.compile(r'.[Dd][Oo][Cc][xX]?$')
                new_f = p.sub('.pdf', f)
                new_path = path.replace(f, new_f)
                cmd = 'soffice --headless --convert-to pdf  %s --outdir %s/upload' % (path, settings.MEDIA_ROOT)
                cmds.append(cmd)
                paths.append(path)
                l_doc.append(([cat], new_path, new_f, [d]))
            elif m in ['application/vnd.ms-excel', 'application/vnd.openxmlformats-officedocument.spreadsheetml.sheet']:
                p = re.compile(r'.[Xx][Ll][Ss][xX]?$')
                new_f = p.sub('.pdf', f)
                new_path = path.replace(f, new_f)
                cmd = 'soffice --headless --convert-to pdf  %s --outdir %s/upload' % (path, settings.MEDIA_ROOT)
                cmds.append(cmd)
                paths.append(path)
                l_doc.append(([cat], new_path, new_f, [d]))
            else:
                print 'ERREUR FORMAT FICHIER'
        if len(l_doc):
            thread1 = Timer(0, manage_convert_doc_to_pdf, (cmds, paths, l_doc,))
            thread1.start()
        if len(l_pdf):
            thread = Timer(0, manage_convert_pdf_to_jpg, (l_pdf,))
            thread.start()
        results = {'doc_list': [d.as_json() for d in cat.get_docs()], 'n': cat.count_docs()}
        return HttpResponse(json.dumps(results))
开发者ID:Foxugly,项目名称:MyTaxAccountant,代码行数:58,代码来源:views.py

示例9: DocumentTestCase

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
class DocumentTestCase(TestCase):
    def setUp(self):
        self.document_type = DocumentType(name='test doc type')
        self.document_type.save()

        self.document = Document(
            document_type=self.document_type,
            description='description',
        )
        self.document.save()

        with open(TEST_DOCUMENT_PATH) as file_object:
            self.document.new_version(file=File(file_object, name='mayan_11_1.pdf'))

        with open(TEST_KEY_FILE) as file_object:
            gpg.import_key(file_object.read())

    def test_document_no_signature(self):
        self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False)

    def test_new_document_version_signed(self):
        with open(TEST_SIGNED_DOCUMENT_PATH) as file_object:
            new_version_data = {
                'comment': 'test comment 1',
                'version_update': VERSION_UPDATE_MAJOR,
                'release_level': RELEASE_LEVEL_FINAL,
                'serial': 0,
            }

            self.document.new_version(file=File(file_object, name='mayan_11_1.pdf.gpg'), **new_version_data)

        self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False)
        self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID)

    def test_detached_signatures(self):
        new_version_data = {
            'comment': 'test comment 2',
            'version_update': VERSION_UPDATE_MAJOR,
            'release_level': RELEASE_LEVEL_FINAL,
            'serial': 0,
        }
        with open(TEST_DOCUMENT_PATH) as file_object:
            self.document.new_version(file=File(file_object), **new_version_data)

        # GPGVerificationError
        self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document), None)

        with open(TEST_SIGNATURE_FILE_PATH, 'rb') as file_object:
            DocumentVersionSignature.objects.add_detached_signature(self.document, File(file_object))

        self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), True)
        self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID)

    def tearDown(self):
        self.document.delete()
        self.document_type.delete()
开发者ID:EmlynC,项目名称:mayan-edms,代码行数:58,代码来源:tests.py

示例10: DocumentTestCase

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
class DocumentTestCase(unittest.TestCase):
    def setUp(self):
        self.document_type = DocumentType(name='test doc type')
        self.document_type.save()

        self.document = Document(
            document_type=self.document_type,
            description='description',
        )
        self.document.save()

        file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf'))
        new_version = self.document.new_version(file=File(file_object, name='mayan_11_1.pdf'))
        file_object.close()

    def test_document_no_signature(self):
        self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False)

    def test_new_document_version_signed(self):
        file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf.gpg'))
        new_version_data = {
            'comment': 'test comment 1',
            'version_update': VERSION_UPDATE_MAJOR,
            'release_level': RELEASE_LEVEL_FINAL,
            'serial': 0,
        }

        self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), False)
        # self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID)
        # TODO: verify_signature is failing, check

    def test_detached_signatures(self):
        new_version_data = {
            'comment': 'test comment 2',
            'version_update': VERSION_UPDATE_MAJOR,
            'release_level': RELEASE_LEVEL_FINAL,
            'serial': 0,
        }
        file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf'))
        new_version = self.document.new_version(file=File(file_object), **new_version_data)
        file_object.close()

        # GPGVerificationError
        self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document), None)

        file_object = open(os.path.join(settings.PROJECT_ROOT, 'contrib', 'mayan_11_1.pdf.sig'), 'rb')
        DocumentVersionSignature.objects.add_detached_signature(self.document, File(file_object))
        file_object.close()

        self.failUnlessEqual(DocumentVersionSignature.objects.has_detached_signature(self.document), True)
        # self.failUnlessEqual(DocumentVersionSignature.objects.verify_signature(self.document).status, SIGNATURE_STATE_VALID)
        # TODO: verify_signature is failing, check

    def tearDown(self):
        self.document.delete()
        self.document_type.delete()
开发者ID:simone,项目名称:mayan-edms,代码行数:58,代码来源:tests.py

示例11: upload_document

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
    def upload_document(self, file_object, document_type, description=None, label=None, language=None, metadata_dict_list=None, metadata_dictionary=None, tag_ids=None, user=None):
        """
        Upload an individual document
        """
        try:
            with transaction.atomic():
                document = Document(
                    description=description or '', document_type=document_type,
                    label=label or file_object.name,
                    language=language or setting_language.value
                )
                document.save(_user=user)
        except Exception as exception:
            logger.critical(
                'Unexpected exception while trying to create new document '
                '"%s" from source "%s"; %s',
                label or file_object.name, self, exception
            )
            raise
        else:
            try:
                document_version = document.new_version(
                    file_object=file_object, _user=user,
                )

                if user:
                    document.add_as_recent_document_for_user(user)

                Transformation.objects.copy(
                    source=self, targets=document_version.pages.all()
                )

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

                if metadata_dictionary:
                    set_bulk_metadata(
                        document=document,
                        metadata_dictionary=metadata_dictionary
                    )

                if tag_ids:
                    for tag in Tag.objects.filter(pk__in=tag_ids):
                        tag.documents.add(document)
            except Exception as exception:
                logger.critical(
                    'Unexpected exception while trying to create version for '
                    'new document "%s" from source "%s"; %s',
                    label or file_object.name, self, exception
                )
                document.delete(to_trash=False)
                raise
开发者ID:jorik041,项目名称:open-paperless,代码行数:56,代码来源:models.py

示例12: __upload_core

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
def __upload_core(request):
    form = DocumentForm(request.POST, request.FILES)
    if form.is_valid():
        u = request.user
        doc = Document(owner=u)
        file = request.FILES['file']
        doc.filename = request.FILES['file'].name
        doc.save()
        doc.file.save('file_' + str(doc.id), file)
        return doc
    else:
        return Exception()
开发者ID:mdavoodi,项目名称:konkourse-python,代码行数:14,代码来源:views.py

示例13: FolderTestCase

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
class FolderTestCase(unittest.TestCase):
    def setUp(self):
        self.document_type = DocumentType(name='test doc type')
        self.document_type.save()

        self.document = Document(
            document_type=self.document_type,
            description='description',
        )
        self.document.save()

        file_object = open(os.path.join(settings.SITE_ROOT, 'contrib', 'sample_documents', 'mayan_11_1.pdf'))
        new_version = self.document.new_version(file=File(file_object, name='mayan_11_1.pdf'))
        file_object.close()

    def test_creation_of_folder(self):
        user = User.objects.all()[0]
        folder = Folder.objects.create(title='test', user=user)

        self.assertEqual(Folder.objects.all().count(), 1)
        self.assertEqual(list(Folder.objects.all()), [folder])
        folder.delete()

    def test_addition_of_documents(self):
        user = User.objects.all()[0]
        folder = Folder.objects.create(title='test', user=user)
        folder.add_document(self.document)

        self.assertEqual(folder.documents.count(), 1)
        self.assertEqual(list(folder.documents), [self.document])
        folder.delete()

    def test_addition_and_deletion_of_documents(self):
        user = User.objects.all()[0]
        folder = Folder.objects.create(title='test', user=user)
        folder.add_document(self.document)

        self.assertEqual(folder.documents.count(), 1)
        self.assertEqual(list(folder.documents), [self.document])

        folder.remove_document(self.document)

        self.assertEqual(folder.documents.count(), 0)
        self.assertEqual(list(folder.documents), [])

        folder.delete()

    def tearDown(self):
        self.document.delete()
        self.document_type.delete()
开发者ID:cccs-web,项目名称:mayan-edms,代码行数:52,代码来源:tests.py

示例14: FolderTestCase

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
class FolderTestCase(TestCase):
    def setUp(self):
        self.document_type = DocumentType(name='test doc type')
        self.document_type.save()

        self.document = Document(
            document_type=self.document_type,
            description='description',
        )
        self.document.save()

        with open(TEST_DOCUMENT_PATH) as file_object:
            self.document.new_version(file=File(file_object, name='nucleos_11_1.pdf'))

    def test_creation_of_folder(self):
        user = User.objects.all()[0]
        folder = Folder.objects.create(title='test', user=user)

        self.assertEqual(Folder.objects.all().count(), 1)
        self.assertEqual(list(Folder.objects.all()), [folder])
        folder.delete()

    def test_addition_of_documents(self):
        user = User.objects.all()[0]
        folder = Folder.objects.create(title='test', user=user)
        folder.add_document(self.document)

        self.assertEqual(folder.documents.count(), 1)
        self.assertEqual(list(folder.documents), [self.document])
        folder.delete()

    def test_addition_and_deletion_of_documents(self):
        user = User.objects.all()[0]
        folder = Folder.objects.create(title='test', user=user)
        folder.add_document(self.document)

        self.assertEqual(folder.documents.count(), 1)
        self.assertEqual(list(folder.documents), [self.document])

        folder.remove_document(self.document)

        self.assertEqual(folder.documents.count(), 0)
        self.assertEqual(list(folder.documents), [])

        folder.delete()

    def tearDown(self):
        self.document.delete()
        self.document_type.delete()
开发者ID:jotagesales,项目名称:nucleos-edms,代码行数:51,代码来源:tests.py

示例15: upload_single_file

# 需要导入模块: from documents.models import Document [as 别名]
# 或者: from documents.models.Document import save [as 别名]
    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)
开发者ID:EmlynC,项目名称:mayan-edms,代码行数:49,代码来源:models.py


注:本文中的documents.models.Document.save方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。