コード例 #1
0
ファイル: entity_model_tests.py プロジェクト: ryan86/arches
    def test_save(self):
        val = models.Values.objects.get(value='Legal')
        python_object = {
            "entityid":"",
            "entitytypeid":"PERSON.E1",
            "value":"",
            "property":"P1",
            "child_entities":[{
                "entityid":"",
                "entitytypeid":"NAME.E1",
                "value":"Alexei",
                "property":"P1",
                "child_entities":[{
                    "entityid":"",
                    "entitytypeid":"NAME_TYPE.E1",
                    "value":val.pk,
                    "property":"P1",
                    "child_entities":[]
                }]
            }]
        }
        entity = Entity(python_object)
        entity._save()
        self.assertNotEqual(python_object['entityid'], entity.entityid)

        entity = Entity().get(entity.entityid)
        self.assertEqual(entity.child_entities[0].value, 'Alexei')
        self.assertEqual(entity.child_entities[0].child_entities[0].value, val.pk)
コード例 #2
0
    def test_save(self):
        python_object = {
            "entityid":"",
            "entitytypeid":"CAR.E1",
            "value":"",
            "property":"P1",
            "child_entities":[{
                "entityid":"",
                "entitytypeid":"MAKE.E1",
                "value":"Porsche",
                "property":"P1",
                "child_entities":[{
                    "entityid":"",
                    "entitytypeid":"MODEL.E1",
                    "value":"911",
                    "property":"P1",
                    "child_entities":[]
                }]
            }]
        }
        entity = Entity(python_object)
        entity._save()
        self.assertNotEqual(python_object['entityid'], entity.entityid)

        entity = Entity().get(entity.entityid)
        self.assertEqual(entity.child_entities[0].value, 'Porsche')
        self.assertEqual(entity.child_entities[0].child_entities[0].value, '911')
コード例 #3
0
def insert_actors(settings=None):

    if not settings:
        from django.conf import settings

    logging.warning("INSERTING ACTORS")

    resource_entity_type = 'HERITAGE_RESOURCE_GROUP.E27'
    mapping_schema = Entity.get_mapping_schema(resource_entity_type)

    # access settings to determine which actor nodes should correspond to editors of which pre-existing nodes
    for entry in settings.ACTOR_NODES:

        # find all entities of the parent type
        actor_entitytypeid = entry[0]
        parent_entitytypeid = entry[1]
        source_entitytypeid = entry[2]

        mapping_step_to_actor = mapping_schema[actor_entitytypeid]['steps'][-1]

        parent_entities = models.Entities.objects.filter(
            entitytypeid=parent_entitytypeid).iterator()

        for parent_entity_model in parent_entities:
            # check whether an actor node already exists
            parent_entity = Entity().get(parent_entity_model.entityid)
            actors = parent_entity.find_entities_by_type_id(actor_entitytypeid)
            if (len(actors) == 0):
                # get the root resource
                root_resource_model = get_resource_for_entity(
                    parent_entity_model, resource_entity_type)
                if not root_resource_model:
                    continue

                # find the last edit to the node that the data originated at
                edits = models.EditLog.objects.filter(
                    resourceid=root_resource_model.entityid,
                    attributeentitytypeid=source_entitytypeid).order_by(
                        'timestamp')
                first_edit = edits[0]
                actor_name = '%s %s' % (edits[0].user_firstname,
                                        edits[0].user_lastname)

                # create the actor node
                parent_entity.add_child_entity(
                    actor_entitytypeid, mapping_step_to_actor['propertyid'],
                    actor_name, '')

                # logging.warning("\n\nParent after insert")
                log_entity(parent_entity)
                parent_entity._save()

                root_resource = Resource()
                root_resource.get(root_resource_model.entityid)
コード例 #4
0
    def test_save(self):
        val = models.Values.objects.get(value='Legal')
        python_object = {
            "entityid":
            "",
            "entitytypeid":
            "PERSON.E1",
            "value":
            "",
            "property":
            "P1",
            "child_entities": [{
                "entityid":
                "",
                "entitytypeid":
                "NAME.E1",
                "value":
                "Alexei",
                "property":
                "P1",
                "child_entities": [{
                    "entityid": "",
                    "entitytypeid": "NAME_TYPE.E1",
                    "value": val.pk,
                    "property": "P1",
                    "child_entities": []
                }]
            }]
        }
        entity = Entity(python_object)
        entity._save()
        self.assertNotEqual(python_object['entityid'], entity.entityid)

        entity = Entity().get(entity.entityid)
        self.assertEqual(entity.child_entities[0].value, 'Alexei')
        self.assertEqual(entity.child_entities[0].child_entities[0].value,
                         val.pk)
コード例 #5
0
    def test_save(self):
        python_object = {
            "entityid":
            "",
            "entitytypeid":
            "CAR.E1",
            "value":
            "",
            "property":
            "P1",
            "child_entities": [{
                "entityid":
                "",
                "entitytypeid":
                "MAKE.E1",
                "value":
                "Porsche",
                "property":
                "P1",
                "child_entities": [{
                    "entityid": "",
                    "entitytypeid": "MODEL.E1",
                    "value": "911",
                    "property": "P1",
                    "child_entities": []
                }]
            }]
        }
        entity = Entity(python_object)
        entity._save()
        self.assertNotEqual(python_object['entityid'], entity.entityid)

        entity = Entity().get(entity.entityid)
        self.assertEqual(entity.child_entities[0].value, 'Porsche')
        self.assertEqual(entity.child_entities[0].child_entities[0].value,
                         '911')