本文整理汇总了Python中openPLM.plmapp.controllers.DocumentController类的典型用法代码示例。如果您正苦于以下问题:Python DocumentController类的具体用法?Python DocumentController怎么用?Python DocumentController使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
在下文中一共展示了DocumentController类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: test_doc_cad
def test_doc_cad(self):
doc1 = DocumentController.create("doc1", "Document", "a", self.user, self.DATA)
doc2 = DocumentController.create("doc2", "Document", "a", self.user, self.DATA)
self.controller.attach_to_document(doc1)
self.controller.attach_to_document(doc2)
response = self.get(self.base_url + "doc-cad/", page="doc-cad")
self.assertEqual(2, len(list(response.context["object_doc_cad"])))
示例2: search
def search(request, editable_only="true", with_file_only="true"):
"""
Returns all objects matching a query.
:param editable_only: if ``"true"`` (the default), returns only editable objects
:param with_file_only: if ``"true"`` (the default), returns only documents with
at least one file
:implements: :func:`http_api.search`
"""
if request.GET and "type" in request.GET:
form = forms.SimpleSearchForm(request.GET)
if form.is_valid():
# object may have been deleted but not yet unindexed
results = [r.object for r in form.search().load_all()[:30] if r is not None]
objects = []
ids = set()
for res in results:
if isinstance(res, models.DocumentFile):
res = res.document.get_leaf_object()
if res.id in ids: # avoiding duplicated results
continue
if editable_only == "false" or res.is_editable:
if with_file_only == "true" and hasattr(res, "files") \
and not bool(res.files):
continue
if editable_only == "true":
obj = DocumentController(res, request.user)
if not obj.check_in_group(request.user, False):
continue
ids.add(res.id)
objects.append(object_to_dict(res))
return {"objects" : objects}
return {"result": "error"}
示例3: test_doc_cad_update_post_empty_selection
def test_doc_cad_update_post_empty_selection(self):
doc1 = DocumentController.create("doc1", "Document", "a", self.user,
self.DATA)
doc2 = DocumentController.create("doc2", "Document", "a", self.user,
self.DATA)
self.controller.attach_to_document(doc1)
self.controller.attach_to_document(doc2)
data = {
'form-TOTAL_FORMS' : '2',
'form-INITIAL_FORMS' : '2',
'form-MAX_NUM_FORMS' : '',
'form-0-id' : doc1.get_attached_parts()[0].id,
'form-0-part' : self.controller.id,
'form-0-document' : doc1.id,
'form-0-delete' : '',
'form-1-id' : doc2.get_attached_parts()[0].id,
'form-1-part' : self.controller.id,
'form-1-document' : doc2.id,
'form-1-delete' : '',
}
response = self.post(self.base_url + "doc-cad/", data, page="doc-cad")
self.assertEqual(2, response.context["documents"].count())
forms_ = response.context["forms"]
self.assertEqual(set((doc1.id, doc2.id)),
set(f.instance.document.id for f in forms_.values()))
示例4: search
def search(request, editable_only="true", with_file_only="true"):
"""
Returns all objects matching a query.
:param editable_only: if ``"true"`` (the default), returns only editable objects
:param with_file_only: if ``"true"`` (the default), returns only documents with
at least one file
:implements: :func:`http_api.search`
"""
if request.GET and "type" in request.GET:
attributes_form = forms.TypeForm(request.GET)
if attributes_form.is_valid():
query_dict = {}
cls = models.get_all_plmobjects()[attributes_form.cleaned_data["type"]]
extra_attributes_form = forms.get_search_form(cls, request.GET)
results = cls.objects.all()
if extra_attributes_form.is_valid():
results = extra_attributes_form.search(results)
objects = []
for res in results:
if editable_only == "false" or res.is_editable:
if with_file_only == "true" and hasattr(res, "files") \
and not bool(res.files):
continue
if editable_only == "true":
obj = DocumentController(res, request.user)
if not obj.check_permission("owner", False):
continue
objects.append(object_to_dict(res))
return {"objects" : objects}
return {"result": "error"}
示例5: test_attached_documents_two_parts
def test_attached_documents_two_parts(self):
doc = DocumentController.create("Doc", "Document", "a", self.user,
self.DATA)
doc.attach_to_part(self.controller)
doc2 = DocumentController.create("Doc2", "Document", "a", self.user,
self.DATA)
doc2.attach_to_part(self.controller)
wanted = [
{
"id": doc.id,
"reference": doc.reference,
"type": doc.type,
"revision": doc.revision,
"name": doc.name,
},
{
"id": doc2.id,
"reference": doc2.reference,
"type": doc2.type,
"revision": doc2.revision,
"name": doc2.name,
},
]
key = lambda x: x["id"]
url = "/api/object/%d/attached_documents/" % self.controller.id
data = self.get(url)
self.assertEqual(sorted(data["documents"], key=key), sorted(wanted, key=key))
示例6: test_doc_cad_update_post_all_selected
def test_doc_cad_update_post_all_selected(self):
doc1 = DocumentController.create("doc1", "Document", "a", self.user,
self.DATA)
doc2 = DocumentController.create("doc2", "Document", "a", self.user,
self.DATA)
self.controller.attach_to_document(doc1)
self.controller.attach_to_document(doc2)
data = {
'form-TOTAL_FORMS' : '2',
'form-INITIAL_FORMS' : '2',
'form-MAX_NUM_FORMS' : '',
'form-0-id' : doc1.get_attached_parts()[0].id,
'form-0-part' : self.controller.id,
'form-0-document' : doc1.id,
'form-0-delete' : 'on',
'form-1-id' : doc2.get_attached_parts()[0].id,
'form-1-part' : self.controller.id,
'form-1-document' : doc2.id,
'form-1-delete' : 'on',
}
response = self.post(self.base_url + "doc-cad/", data, page="doc-cad")
self.assertEqual(0, response.context["documents"].count())
self.assertFalse(response.context["forms"])
示例7: test_doc_cad
def test_doc_cad(self):
doc1 = DocumentController.create("doc1", "Document", "a", self.user,
self.DATA)
doc2 = DocumentController.create("doc2", "Document", "a", self.user,
self.DATA)
self.controller.attach_to_document(doc1)
self.controller.attach_to_document(doc2)
doc2.object.state = doc2.object.lifecycle.last_state
doc2.object.save()
response = self.get(self.base_url + "doc-cad/", page="doc-cad")
self.assertEqual(2, response.context["documents"].count())
forms_ = response.context["forms"]
self.assertEqual([doc1.id], [f.instance.document.id for f in forms_.values()])
示例8: test_lock
def test_lock(self):
doc = DocumentController.create("Doc", "Document", "a", self.user,
self.DATA)
df = doc.add_file(self.get_file())
data = self.get("/api/object/%d/lock/%d/" % (doc.id, df.id))
self.assertEqual("ok", data["result"])
self.assertTrue(doc.files[0].locked)
示例9: test_files
def test_files(self):
doc = DocumentController.create("Doc", "Document", "a", self.user, self.DATA)
doc.object.state =doc.object.lifecycle.official_state
doc.object.save()
doc.add_reader(self.restricted_user)
self.assertViewErrorGet(doc.plmobject_url + "files/")
self.assertViewErrorGet(doc.plmobject_url + "files/add/")
示例10: test_get_files
def test_get_files(self):
doc = DocumentController.create("Doc", "Document", "a", self.user,
self.DATA)
df = doc.add_file(self.get_file())
data = self.get("/api/object/%d/files/" % doc.id)
self.assertEqual("ok", data["result"])
self.assertEqual([df.id], [f["id"] for f in data["files"]])
示例11: test_attach_doc_part_post
def test_attach_doc_part_post(self):
doc = DocumentController.create("Doc", "Document", "a", self.user,
self.DATA)
self.assertAjaxErrorPost("/ajax/attach/%d/" % doc.id,
type=self.ctrl.type, reference=self.ctrl.reference,
revision=self.ctrl.revision)
self.assertFalse(self.ctrl.get_attached_documents())
示例12: test_revise_one_deprecated_document_attached_post
def test_revise_one_deprecated_document_attached_post(self):
"""
Tests a post request to revise a part which has one deprecated
attached document.
This document must not be suggested when the user revises the part.
"""
document = DocumentController.create("RefDocument", "Document", "a", self.user, self.DATA)
self.controller.attach_to_document(document)
document.object.state = document.lifecycle.last_state
document.object.save()
data = { "revision" : "b",
"parents-TOTAL_FORMS" : "0",
"parents-INITIAL_FORMS" : "0",
"children-TOTAL_FORMS" : "0",
"children-INITIAL_FORMS" : "0",
"documents-TOTAL_FORMS" : "1",
"documents-INITIAL_FORMS" : "1",
"documents-0-selected" : "",
"documents-0-document" : document.id,
}
response = self.post(self.base_url + "revisions/", data)
# even if we submit a formset, it should not be parsed
revisions = self.controller.get_next_revisions()
self.assertEqual(1, len(revisions))
rev = revisions[0].part
# ensure document is still attached to the old revision
documents = self.controller.get_attached_documents().values_list("document", flat=True)
self.assertEqual([document.id], list(documents))
# ensure document is not attached to the new revision
self.assertFalse(rev.documentpartlink_part.now().exists())
# ensure only the old revision is attached to document
self.assertEqual([self.controller.id],
list(document.get_attached_parts().values_list("part", flat=True)))
示例13: test_unlock
def test_unlock(self):
doc = DocumentController.create("Doc", "Document", "a", self.user,
self.DATA)
df = doc.add_file(self.get_file())
doc.lock(df)
self.assertApiErrorGet("/api/object/%d/unlock/%d/" % (doc.id, df.id))
self.assertTrue(doc.files[0].locked)
示例14: test_add_file
def test_add_file(self):
doc = DocumentController.create("Doc", "Document", "a", self.user,
self.DATA)
mock_file = self.get_file()
self.assertApiErrorPost("/api/object/%d/add_file/" % doc.id,
filename=mock_file)
self.assertFalse(doc.files)
示例15: test_revise_one_attached_revised_document_post
def test_revise_one_attached_revised_document_post(self):
"""
Tests a post request to revise a part which has one attached document.
The document has been revised and its revision is selected.
"""
document = DocumentController.create("RefDocument", "Document", "a", self.user, self.DATA)
self.controller.attach_to_document(document)
d2 = document.revise("b")
data = { "revision" : "b",
"parents-TOTAL_FORMS" : "0",
"parents-INITIAL_FORMS" : "0",
"children-TOTAL_FORMS" : "0",
"children-INITIAL_FORMS" : "0",
"documents-TOTAL_FORMS" : "1",
"documents-INITIAL_FORMS" : "1",
"documents-0-selected" : "on",
"documents-0-document" : d2.id,
}
response = self.post(self.base_url + "revisions/", data)
revisions = self.controller.get_next_revisions()
self.assertEqual(1, len(revisions))
rev = revisions[0].part
self.assertEqual("b", rev.revision)
# ensure document is still attached to the old revision
documents = self.controller.get_attached_documents().values_list("document", flat=True)
self.assertEqual([document.id], list(documents))
# ensure d2 is attached to the new revision
documents = rev.documentpartlink_part.values_list("document", flat=True)
self.assertEqual([d2.id], list(documents))