コード例 #1
0
 def test_post_edit_entity_new_type(self):
     self._create_entity_data("entityedittype")
     e1 = self._check_entity_data_values("entityedittype")
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     newtype = RecordType.create(self.testcoll, "newtype",
                                 recordtype_create_values("newtype"))
     newtypedata = RecordTypeData(self.testcoll, "newtype")
     self.assertTrue(RecordType.exists(self.testcoll, "newtype"))
     self.assertFalse(RecordTypeData.exists(self.testcoll, "newtype"))
     # Now post edit form submission with new type id
     f = entitydata_form_data(entity_id="entityedittype",
                              orig_id="entityedittype",
                              type_id="newtype",
                              orig_type="testtype",
                              action="edit")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "testtype",
                             entity_id="entityedittype")
     r = self.client.post(u, f)
     # log.info("***********\n"+r.content)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(
         r['location'],
         TestHostUri + entitydata_list_type_url("testcoll", "testtype"))
     # Check that new record type data now exists, and that new record exists and old does not
     self.assertTrue(RecordTypeData.exists(self.testcoll, "newtype"))
     self.assertFalse(EntityData.exists(self.testdata, "entityedittype"))
     self.assertTrue(EntityData.exists(newtypedata, "entityedittype"))
     self._check_entity_data_values("entityedittype", type_id="newtype")
     return
コード例 #2
0
 def test_post_edit_entity_new_type(self):
     self._create_entity_data("entityedittype")
     e1 = self._check_entity_data_values("entityedittype")
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     newtype     = RecordType.create(self.testcoll, "newtype", recordtype_create_values("newtype"))
     newtypedata = RecordTypeData(self.testcoll, "newtype")
     self.assertTrue(RecordType.exists(self.testcoll, "newtype"))
     self.assertFalse(RecordTypeData.exists(self.testcoll, "newtype"))
     # Now post edit form submission with new type id
     f = default_view_form_data(
         entity_id="entityedittype", orig_id="entityedittype", 
         type_id="newtype", orig_type="testtype",
         action="edit")
     u = entitydata_edit_url("edit", "testcoll", "testtype", entity_id="entityedittype")
     r = self.client.post(u, f)
     # log.info("***********\n"+r.content)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "Found")
     self.assertEqual(r.content,       b"")
     self.assertEqual(r['location'],   entitydata_list_type_url("testcoll", "testtype"))
     # Check that new record type data now exists, and that new record exists and old does not
     self.assertTrue(RecordTypeData.exists(self.testcoll, "newtype"))
     self.assertFalse(EntityData.exists(self.testdata, "entityedittype"))
     self.assertTrue(EntityData.exists(newtypedata, "entityedittype"))
     self._check_entity_data_values("entityedittype", type_id="newtype")
     return
コード例 #3
0
 def test_exists_type(self):
     # Some type existence tests taking account of site data default type
     self.assertTrue(RecordType.exists(self.testcoll, "testtype"))
     self.assertFalse(RecordType.exists(self.testcoll, "notype"))
     self.assertFalse(RecordType.exists(self.testcoll, "Default_type"))
     self.assertTrue(RecordType.exists(self.testcoll, "Default_type", altscope="all"))
     return
コード例 #4
0
 def test_post_edit_type_new_id(self):
     # Check logic applied when type is renamed
     (t, d1, e1) = self._create_record_type("edittype1", entity_id="typeentity")
     self.assertTrue(RecordType.exists(self.testcoll, "edittype1"))
     self.assertFalse(RecordType.exists(self.testcoll, "edittype2"))
     self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype1"))
     self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype2"))
     self.assertTrue(EntityData.exists(d1, "typeentity"))
     self._check_record_type_values("edittype1")
     f = recordtype_entity_view_form_data(
         type_id="edittype2", orig_id="edittype1", 
         action="edit", update="Updated RecordType"
         )
     u = entitydata_edit_url(
         "edit", "testcoll", layout.TYPE_TYPEID, entity_id="edittype1", view_id="Type_view"
         )
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that new record type exists and old does not
     self.assertFalse(RecordType.exists(self.testcoll, "edittype1"))
     self.assertTrue(RecordType.exists(self.testcoll, "edittype2"))
     self._check_record_type_values("edittype2", update="Updated RecordType")
     # Check that type data directory has been renamed
     self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype1"))
     self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype2"))
     self.assertFalse(EntityData.exists(d1, "typeentity"))
     d2 = RecordTypeData.load(self.testcoll, "edittype2")
     self.assertTrue(EntityData.exists(d2, "typeentity"))
     return
コード例 #5
0
 def test_new_entity_new_type(self):
     # Checks logic for creating an entity which may require creation of new recorddata
     # Create new type
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     f = type_view_form_data(action="new",
         coll_id="testcoll", 
         type_entity_id="newtype",            
         )
     u = entitydata_edit_url("new", "testcoll", type_id="_type", view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "Found")
     self.assertEqual(r.content,       b"")
     self.assertEqual(r['location'],   entitydata_list_type_url("testcoll", "_type"))
     self.assertTrue(RecordType.exists(self.testcoll, "newtype"))
     # Create new entity
     self.assertFalse(EntityData.exists(self.testdata, "newentity"))
     f = default_view_form_data(entity_id="newentity", type_id="newtype", action="new")
     u = entitydata_edit_url("new", "testcoll", "newtype", view_id="Default_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "Found")
     self.assertEqual(r.content,       b"")
     self.assertEqual(r['location'],   entitydata_list_type_url("testcoll", "newtype"))
     # Check new entity data created
     self._check_entity_data_values("newentity", type_id="newtype")
     return
コード例 #6
0
 def test_post_new_type_cancel(self):
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     f = recordtype_entity_view_form_data(
         type_id="newtype", action="new", cancel="Cancel", update="Updated RecordType"
         )
     u = entitydata_edit_url("new", "testcoll", layout.TYPE_TYPEID, view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that new record type still does not exist
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     return
コード例 #7
0
 def test_post_confirmed_remove_type(self):
     t = RecordType.create(self.testcoll, "deletetype",
                           recordtype_create_values("deletetype"))
     self.assertTrue(RecordType.exists(self.testcoll, "deletetype"))
     # Submit positive confirmation
     u = TestHostUri + recordtype_edit_url("delete", "testcoll")
     f = recordtype_delete_confirm_form_data("deletetype")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertMatch(
         r['location'],
         "^" + TestHostUri + collection_edit_url("testcoll") +
         r"\?info_head=.*&info_message=.*deletetype.*testcoll.*$")
     # Confirm deletion
     self.assertFalse(RecordType.exists(self.testcoll, "deletetype"))
     return
コード例 #8
0
 def test_post_new_type_cancel(self):
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     f = recordtype_entity_view_form_data(type_id="newtype",
                                          action="new",
                                          cancel="Cancel",
                                          update="Updated RecordType")
     u = entitydata_edit_url("new",
                             "testcoll",
                             "_type",
                             view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that new record type still does not exist
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     return
コード例 #9
0
 def _check_record_type_values(self, type_id, update="RecordType"):
     "Helper function checks content of record type entry with supplied type_id"
     self.assertTrue(RecordType.exists(self.testcoll, type_id))
     t = RecordType.load(self.testcoll, type_id)
     self.assertEqual(t.get_id(), type_id)
     self.assertEqual(t.get_view_url(),
                      TestHostUri + recordtype_url("testcoll", type_id))
     v = recordtype_values(type_id=type_id, update=update)
     self.assertDictionaryMatch(t.get_values(), v)
     return t
コード例 #10
0
 def test_post_copy_type_cancel(self):
     self.assertFalse(RecordType.exists(self.testcoll, "copytype"))
     f = recordtype_entity_view_form_data(type_id="copytype",
                                          orig_id="Default_type",
                                          action="copy",
                                          cancel="Cancel",
                                          update="RecordType")
     u = entitydata_edit_url("copy",
                             "testcoll",
                             layout.TYPE_TYPEID,
                             entity_id="Default_type",
                             view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that target record type still does not exist
     self.assertFalse(RecordType.exists(self.testcoll, "copytype"))
     return
コード例 #11
0
 def test_alt_parent_inherit_site(self):
     # Test inheritance of definitions from site with an alternative collection set
     coll_id = "newcoll"
     newcoll = Collection.create(self.testsite, coll_id, collection_create_values(coll_id))
     altparents = newcoll.set_alt_entities(self.testcoll)
     parentids  = [ p.get_id() for p in altparents ]
     self.assertEqual(parentids, ["newcoll", "testcoll", layout.SITEDATA_ID])
     self.assertTrue(RecordType.exists(newcoll, "Default_type", altscope="all"))
     def_type = RecordType.load(newcoll, "Default_type", altscope="all")
     self.assertEquals(def_type["rdfs:label"], "Default record")
     return
コード例 #12
0
 def test_post_confirmed_remove_type(self):
     t = RecordType.create(self.testcoll, "deletetype", recordtype_create_values("deletetype"))
     self.assertTrue(RecordType.exists(self.testcoll, "deletetype"))
     # Submit positive confirmation
     u = TestHostUri + recordtype_edit_url("delete", "testcoll")
     f = recordtype_delete_confirm_form_data("deletetype")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,     302)
     self.assertEqual(r.reason_phrase,   "FOUND")
     self.assertEqual(r.content,         "")
     self.assertMatch(r['location'],    
         "^"+TestHostUri+
         collection_edit_url("testcoll")+
         r"\?.*info_head=.*$"
         )
     self.assertMatch(r['location'],    
         "^"+TestHostUri+
         collection_edit_url("testcoll")+
         r"\?.*info_message=.*deletetype.*testcoll.*$"
         )
     # Confirm deletion
     self.assertFalse(RecordType.exists(self.testcoll, "deletetype"))
     return
コード例 #13
0
 def test_new_entity_new_type(self):
     # Checks logic for creating an entity which may require creation of new recorddata
     # Create new type
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     f = type_view_form_data(
         action="new",
         coll_id="testcoll",
         type_entity_id="newtype",
     )
     u = entitydata_edit_url("new",
                             "testcoll",
                             type_id="_type",
                             view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(
         r['location'],
         TestHostUri + entitydata_list_type_url("testcoll", "_type"))
     self.assertTrue(RecordType.exists(self.testcoll, "newtype"))
     # Create new entity
     self.assertFalse(EntityData.exists(self.testdata, "newentity"))
     f = default_view_form_data(entity_id="newentity",
                                type_id="newtype",
                                action="new")
     u = entitydata_edit_url("new", "testcoll", "newtype")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(
         r['location'],
         TestHostUri + entitydata_list_type_url("testcoll", "newtype"))
     # Check new entity data created
     self._check_entity_data_values("newentity", type_id="newtype")
     return
コード例 #14
0
 def test_post_edit_type_new_id(self):
     # Check logic applied when type is renamed
     (t, d1, e1) = self._create_record_type("edittype1",
                                            entity_id="typeentity")
     self.assertTrue(RecordType.exists(self.testcoll, "edittype1"))
     self.assertFalse(RecordType.exists(self.testcoll, "edittype2"))
     self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype1"))
     self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype2"))
     self.assertTrue(EntityData.exists(d1, "typeentity"))
     self._check_record_type_values("edittype1")
     f = recordtype_entity_view_form_data(type_id="edittype2",
                                          orig_id="edittype1",
                                          action="edit",
                                          update="Updated RecordType")
     u = entitydata_edit_url("edit",
                             "testcoll",
                             "_type",
                             entity_id="edittype1",
                             view_id="Type_view")
     r = self.client.post(u, f)
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that new record type exists and old does not
     self.assertFalse(RecordType.exists(self.testcoll, "edittype1"))
     self.assertTrue(RecordType.exists(self.testcoll, "edittype2"))
     self._check_record_type_values("edittype2",
                                    update="Updated RecordType")
     # Check that type data directory has been renamed
     self.assertFalse(RecordTypeData.exists(self.testcoll, "edittype1"))
     self.assertTrue(RecordTypeData.exists(self.testcoll, "edittype2"))
     self.assertFalse(EntityData.exists(d1, "typeentity"))
     d2 = RecordTypeData.load(self.testcoll, "edittype2")
     self.assertTrue(EntityData.exists(d2, "typeentity"))
     return
コード例 #15
0
    def get_type(self, type_id):
        """
        Retrieve identified type description

        type_id     local identifier for the type to retrieve.

        returns a RecordType object for the identified type, or None.
        """
        self._load_types()
        t = self._types_by_id.get(type_id, None)
        # Was it created but not cached?
        if not t and RecordType.exists(self, type_id, altscope="all"):
            log.info("___ Collection.get_type: " + type_id)
            t = RecordType.load(self, type_id, altscope="all")
            self._update_type_cache(t)
        return t
コード例 #16
0
ファイル: collection.py プロジェクト: juandesant/annalist
    def get_type(self, type_id):
        """
        Retrieve identified type description

        type_id     local identifier for the type to retrieve.

        returns a RecordType object for the identified type, or None.
        """
        self._load_types()
        t = self._types_by_id.get(type_id, None)
        # Was it created but not cached?
        if not t and RecordType.exists(self, type_id, altscope="all"):
            log.info("___ Collection.get_type: "+type_id)
            t = RecordType.load(self, type_id, altscope="all")
            self._update_type_cache(t)
        return t
コード例 #17
0
 def test_post_copy_type(self):
     self.assertFalse(RecordType.exists(self.testcoll, "copytype"))
     f = recordtype_entity_view_form_data(
         type_id="copytype", orig_id="Default_type", action="copy", update="RecordType"
         )
     u = entitydata_edit_url(
         "copy", "testcoll", layout.TYPE_TYPEID, entity_id="Default_type", view_id="Type_view"
         )
     r = self.client.post(u, f)
     self.assertEqual(r.status_code,   302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content,       "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that new record type exists
     self._check_record_type_values("copytype", update="RecordType")
     return
コード例 #18
0
 def test_post_new_type(self):
     self.assertFalse(RecordType.exists(self.testcoll, "newtype"))
     f = recordtype_entity_view_form_data(type_id="newtype",
                                          action="new",
                                          update="RecordType")
     u = entitydata_edit_url("new",
                             "testcoll",
                             "_type",
                             view_id="Type_view")
     r = self.client.post(u, f)
     # print r.content
     self.assertEqual(r.status_code, 302)
     self.assertEqual(r.reason_phrase, "FOUND")
     self.assertEqual(r.content, "")
     self.assertEqual(r['location'], self.continuation_url)
     # Check that new record type exists
     self._check_record_type_values("newtype", update="RecordType")
     return
コード例 #19
0
ファイル: collection.py プロジェクト: gklyne/annalist
    def cache_get_vocab(self, vocab_id):
        """
        Retrieve namespace vocabulary entity for id (namespace prefix) from cache.

        Returns namespace vocabulary entity if found, otherwise None.
        """
        vocab_cache.get_vocab(self, vocab_id)
        t = vocab_cache.get_vocab(self, vocab_id)
        # Was it previously created but not cached?
        if not t and RecordType.exists(self, vocab_id, altscope="all"):
            msg = (
                "Collection.get_vocab %s present but not cached for collection %s"%
                (vocab_id, self.get_id())
                )
            log.warning(msg)
            t = RecordType.load(self, vocab_id, altscope="all")
            vocab_cache.set_vocab(self, t)
            # raise ValueError(msg) #@@@ (used in testing to help pinpoint errors)
        return t
コード例 #20
0
ファイル: collection.py プロジェクト: gklyne/annalist
    def cache_get_type(self, type_id):
        """
        Retrieve type from cache.

        Returns type entity if found, otherwise None.
        """
        type_cache.get_type(self, type_id)
        t = type_cache.get_type(self, type_id)
        # Was it previously created but not cached?
        if not t and RecordType.exists(self, type_id, altscope="all"):
            msg = (
                "Collection.get_type %s present but not cached for collection %s"%
                (type_id, self.get_id())
                )
            log.warning(msg)
            t = RecordType.load(self, type_id, altscope="all")
            type_cache.set_type(self, t)
            # raise ValueError(msg) #@@@ (used in testing to help pinpoint errors)
        return t
コード例 #21
0
ファイル: collection.py プロジェクト: rklyne/annalist
    def cache_get_type(self, type_id):
        """
        Retrieve type from cache.

        Returns type entity if found, otherwise None.
        """
        type_cache.get_type(self, type_id)
        t = type_cache.get_type(self, type_id)
        # Was it previously created but not cached?
        if not t and RecordType.exists(self, type_id, altscope="all"):
            msg = (
                "Collection.get_type %s present but not cached for collection %s"%
                (type_id, self.get_id())
                )
            log.warning(msg)
            t = RecordType.load(self, type_id, altscope="all")
            type_cache.set_type(self, t)
            # raise ValueError(msg) #@@@ (used in testing to help pinpoint errors)
        return t
コード例 #22
0
ファイル: collection.py プロジェクト: rklyne/annalist
    def cache_get_vocab(self, vocab_id):
        """
        Retrieve namespace vocabulary entity for id (namespace prefix) from cache.

        Returns namespace vocabulary entity if found, otherwise None.
        """
        vocab_cache.get_vocab(self, vocab_id)
        t = vocab_cache.get_vocab(self, vocab_id)
        # Was it previously created but not cached?
        if not t and RecordType.exists(self, vocab_id, altscope="all"):
            msg = (
                "Collection.get_vocab %s present but not cached for collection %s"%
                (vocab_id, self.get_id())
                )
            log.warning(msg)
            t = RecordType.load(self, vocab_id, altscope="all")
            vocab_cache.set_vocab(self, t)
            # raise ValueError(msg) #@@@ (used in testing to help pinpoint errors)
        return t
コード例 #23
0
 def _check_record_type_values(self,
                               type_id,
                               update="RecordType",
                               type_uri=None,
                               extra_values=None):
     "Helper function checks content of record type entry with supplied type_id"
     self.assertTrue(RecordType.exists(self.testcoll, type_id))
     t = RecordType.load(self.testcoll, type_id)
     self.assertEqual(t.get_id(), type_id)
     self.assertEqual(t.get_view_url(),
                      TestHostUri + recordtype_url("testcoll", type_id))
     v = recordtype_values(type_id=type_id,
                           update=update,
                           type_uri=type_uri)
     if extra_values:
         v.update(extra_values)
     # print "t: "+repr(t.get_values())
     # print "v: "+repr(v)
     self.assertDictionaryMatch(t.get_values(), v)
     return t
コード例 #24
0
 def _check_record_type_values(self, type_id, 
         update="RecordType", 
         type_uri=None,
         extra_values=None
         ):
     "Helper function checks content of record type entry with supplied type_id"
     self.assertTrue(RecordType.exists(self.testcoll, type_id))
     t = RecordType.load(self.testcoll, type_id)
     self.assertEqual(t.get_id(), type_id)
     self.assertEqual(t.get_view_url(), TestHostUri + recordtype_url("testcoll", type_id))
     v = recordtype_values(
         type_id=type_id, 
         update=update, 
         type_uri=type_uri
         )
     if extra_values:
         v.update(extra_values)
     # print "t: "+repr(t.get_values())
     # print "v: "+repr(v)
     self.assertDictionaryMatch(t.get_values(), v)
     return t
コード例 #25
0
    def __init__(self, coll, type_id, create_typedata=False):
        """
        Set up type attribute values.

        site            current site object @@unused@@
        coll            collection object in which type is used
        type_id         entity type id, which is a collection-defined value,
                        or one of a number of special site-wide built-in types.
        create_typedata if true, requests that a RecordTypeData entity be created
                        and saved on disk for user-defined types if it does not 
                        already exist.  (Creating a RecordTypeData entity ensures
                        that the corresponding data storage location is available 
                        for saving entity data.)

        Attributes of type information object are:

        recordtype      type object describing the identified type
        entityparent    Parent enbtity for entities of this type, or None if 
                        the type is not defined for the collection
        entityaltparent Alternative (site-wide) parent entity for built-in types, 
                        or None
        entityclass     Python class object for entity
        entitymessages  a table of message strings for diagnostics relating to 
                        operations on this type.

        and other values as initialized here.
        """
        self.entitycoll = coll
        self.recordtype = None
        self.entityparent = None
        self.coll_id = coll.get_id()
        self.type_id = type_id
        self.permissions_map = None
        if type_id == "_coll":
            # NOTE:
            #
            # This setup defaults to using site permissions for collection operations.
            # But there is some special-case code in views.displayinfo that uses the
            # collection itself if it exists.
            #
            # (See use of attribute DisplayInfo.coll_perms.)
            #
            self.recordtype = coll.get_site().site_data_collection().get_type(
                type_id)
            self.entityparent = coll.get_site()
            self.entityaltparent = None
            self.entityclass = Collection
            self.entitymessages = COLL_MESSAGES
            self.permissions_map = CONFIG_PERMISSIONS  # unless entity is layout.SITEDATA_ID?
        elif type_id in TYPE_CLASS_MAP:
            self.recordtype = coll.get_type(type_id)
            self.entityparent = coll
            self.entityaltparent = coll.get_site()
            self.entityclass = TYPE_CLASS_MAP[type_id]
            self.entitymessages = TYPE_MESSAGE_MAP[type_id]
            if self.coll_id == layout.SITEDATA_ID:
                self.permissions_map = SITE_PERMISSIONS_MAP[type_id]
            else:
                self.permissions_map = TYPE_PERMISSIONS_MAP[type_id]
        else:
            if RecordType.exists(coll, type_id, altscope="all"):
                # log.info("@@ EntityTypeInfo: Type %s exists"%type_id)
                self.recordtype = coll.get_type(type_id)
            else:
                # log.info("@@ EntityTypeInfo: Type %s does not exist for collection %s"%(type_id,coll.get_id()))
                pass
            if create_typedata and not RecordTypeData.exists(coll, type_id):
                self.entityparent = RecordTypeData.create(coll, type_id, {})
            else:
                self.entityparent = RecordTypeData(coll, type_id)
            self.entityaltparent = None
            self.entityclass = EntityData
            self.entitymessages = ENTITY_MESSAGES
            self.permissions_map = ENTITY_PERMISSIONS
        if not self.recordtype:
            # .recordtype is used by views.displayinfo to locate the default
            # view and/or list id for examining records of a particular type.
            # Also used in entityedit for getting @type URI/CURIE values.
            # Used in bound_field to get link to type record
            log.warning("EntityTypeInfo.__init__: RecordType %s not found" %
                        type_id)
            # log.info("".join(traceback.format_stack()))
            # raise ValueError("Trace")
        return
コード例 #26
0
    def __init__(self, site, coll, type_id, create_typedata=False):
        """
        Set up type attribute values.

        site            current site object
        coll            collection object in which type is used
        type_id         entity type id, which is a collection-defined value,
                        or one of a number of special site-wide built-in types.
        create_typedata if true, requests that a RecordTypeData entity be created
                        and saved on disk for user-defined types if it does not 
                        already exist.  (Creating a RecordTypeData entity ensures
                        that the corresponding data storage location is available 
                        for saving entity data.)

        Attributes of type information object are:

        recordtype      type object describing the identified type
        entityparent    Parent enbtity for entities of this type, or None if 
                        the type is not defined for the collection
        entityaltparent Alternative (site-wide) parent entity for built-in types, 
                        or None
        entityclass     Python class object for entity
        entitymessages  a table of message strings for diagnostics relating to 
                        operations on this type.

        and other values as initialized here.
        """
        self.entitysite      = site
        self.entitycoll      = coll
        self.recordtype      = None
        self.entityparent    = None
        self.coll_id         = coll.get_id()
        self.type_id         = type_id
        self.permissions_map = None
        if type_id in TYPE_CLASS_MAP:
            self.recordtype      = RecordType.load(coll, type_id, site)
            self.entityparent    = coll
            self.entityaltparent = site
            self.entityclass     = TYPE_CLASS_MAP[type_id]
            self.entitymessages  = TYPE_MESSAGE_MAP[type_id]
            self.permissions_map = TYPE_PERMISSIONS_MAP[type_id]
        else:
            if RecordType.exists(coll, type_id, site):
                self.recordtype     = RecordType.load(coll, type_id, site)
            if create_typedata and not RecordTypeData.exists(coll, type_id):
                self.entityparent   = RecordTypeData.create(coll, type_id, {})
            else:
                self.entityparent   = RecordTypeData(coll, type_id)
            self.entityaltparent = None
            self.entityclass     = EntityData
            self.entitymessages  = ENTITY_MESSAGES
            self.permissions_map = ENTITY_PERMISSIONS
        if not self.recordtype:
            # .recordtype is used by views.displayinfo to locate the default
            # view and/or list id for examining records of a particular type.
            #
            # Also used in entityedit for getting @type URI/CURIE values.
            #
            # Used in render_utils to get link to type record
            log.warning("EntityTypeInfo.__init__: RecordType %s not found"%type_id)
        return