def show_person(uid=None): """ One Person with all connected nodes - NEW version 3. Arguments: - uuid= persons uuid - debug=1 optinal for javascript tests """ t0 = time.time() uid = request.args.get('uuid', uid) dbg = request.args.get('debug', None) u_context = UserContext(user_session, current_user, request) # v3 Person page person, objs, jscode = get_person_full_data(uid, u_context.user, u_context.use_common()) if not person: return redirect( url_for('virhesivu', code=2, text="Ei oikeutta katsoa tätä henkilöä")) stk_logger(u_context, f"-> bp.scene.routes.show_person n={len(objs)}") #for ref in person.media_ref: print(f'media ref {ref}') last_year_allowed = datetime.now().year - shareds.PRIVACY_LIMIT return render_template("/scene/person.html", person=person, obj=objs, jscode=jscode, menuno=12, debug=dbg, root=person.root, last_year_allowed=last_year_allowed, elapsed=time.time() - t0, user_context=u_context)
def test_ownerfilter_user_selection(user_env): ''' Example: - Show all my data / div=2 - with common data / cmp=1 <Request 'http://127.0.0.1:5000/scene/persons_all/?div=2&cmp=1' [GET]> <User Session {'_fresh': True, '_id': '...', 'csrf_token': '...', 'lang': 'en', 'next_person': ['', '>'], 'user_context': 2, 'user_id': 'juha'}> ''' user_session, current_user, request = user_env f = UserContext(user_session, current_user, request) assert f.context == 1 assert f.owner_str() == 'Isotammi database' x = f.use_owner_filter() assert x == False, "use_owner_filter() failed" x = f.use_common() assert x == True, "use_common() failed"
def get_family_data( uuid, context: UserContext): # -> bl.family.FamilyReader.get_family_data """ Read Family information including Events, Children, Notes and Sources. 1) read (f:Family) --> (e:Event) (f:Family) -[:PARENT]-> (pp:Person) -> (np:Name) (f:Family) -[:CHILD]-> (pc:Person) -> (nc:Name) (f:Family) --> (fn:Note) (e:Event) --> (en:Note) (f:Family) --> (fac:Citation) --> (fas:Source) --> (far:Repository) (e:Event) --> (evc:Citation) --> (evs:Source) --> (evr:Repository) 2) read (pp:Person) --> (ppe:Event) --> (:Place) (pc:Person) --> (pce:Event) --> (:Place) 3) build Family_combo.mother, .names, event_birth, event_death Family_combo.father, .names, event_birth, event_death Family_combo.events Family_combo.notes Family_combo.sources / citation -> source -> repocitory ? Family_combo.children, .names, event_birth, event_death Returns a Family object with other objects included """ # Import here to handle circular dependency from .person_combo import Person_combo def set_birth_death(person, birth_node, death_node): ''' Set person.birth and person.death events from db nodes ''' if birth_node: person.event_birth = Event_combo.from_node(birth_node) if death_node: person.event_death = Event_combo.from_node(death_node) #------------ family = None with shareds.driver.session() as session: try: result = session.run(Cypher_family.get_family_data, pid=uuid) for record in result: if record['f']: # <Node id=272710 labels={'Family'} # properties={'father_sortname': '#Andersson#Anders', # 'change': 1519839324, 'rel_type': 'Married', 'handle': '_dcf94f357ea7b126cd8277f4495', # 'id': 'F0268', 'mother_sortname': 'Gröndahl#Juhantytär#Fredrika', # 'datetype': 3, 'date2': 1878089, 'date1': 1875043}> node = record['f'] family = Family_combo.from_node(node) for event_node, place_node in record['family_event']: if event_node: # event_node: # <Node id=242570 labels={'Event'} # properties={'datetype': 0, 'change': 1528183878, 'description': '', # 'handle': '_dcf94f35ea262b7e1a0a0066d6e', 'id': 'E1692', # 'date2': 1875043, 'type': 'Marriage', 'date1': 1875043}> e = Event_combo.from_node(event_node) if place_node: # place_node: <Node id=73479 labels={'Place'} properties={'coord': # [60.5625, 21.609722222222224], 'id': 'P0468', 'type': 'City', 'uuid': # 'd1d0693de1714a47acf6442d64246a50', 'pname': 'Taivassalo', 'change': # 1556953682}> e.place = PlaceBl.from_node(place_node) # Look for surrounding place: res = session.run(Cypher_person.get_places, uid_list=[e.uniq_id]) for rec in res: e.place.names = place_names_from_nodes( rec['pnames']) if rec['pi']: pl_in = PlaceBl.from_node( rec['pi']) pl_in.names = place_names_from_nodes( rec['pinames']) e.place.uppers.append(pl_in) family.events.append(e) uniq_id = -1 for role, person_node, name_node, birth_node, death_node in record[ 'parent']: # ['mother', # <Node id=235105 labels={'Person'} # properties={'sortname': 'Gröndahl#Juhantytär#Fredrika', 'datetype': 19, # 'confidence': '2.0', 'sex': 2, 'change': 1536161195, # 'handle': '_dcf94f357d9f565664a975f99f', 'id': 'I2475', # 'date2': 1937706, 'date1': 1856517}>, # <Node id=235106 labels={'Name'} # properties={'firstname': 'Fredrika', 'type': 'Married Name', # 'suffix': 'Juhantytär', 'prefix': '', 'surname': 'Gröndahl', 'order': 0}>, # <Node id=242532 labels={'Event'} # properties={'datetype': 0, 'change': 1519151217, 'description': '', # 'handle': '_dcf94f357db6f3c846e6472915f', 'id': 'E1531', # 'date2': 1856517, 'type': 'Birth', 'date1': 1856517}>, # <Node id=242536 labels={'Event'} # properties={'datetype': 0, 'change': 1519150640, 'description': '', # 'handle': '_dcf94f357e2d61f5f76e1ba7cb', 'id': 'E1532', # 'date2': 1937700, 'type': 'Death', 'date1': 1937700}> # ] if person_node: if uniq_id != person_node.id: # Skip person with double default name p = Person_combo.from_node(person_node) p.role = role if name_node: p.names.append( Name.from_node(name_node)) set_birth_death(p, birth_node, death_node) if role == 'father': family.father = p elif role == 'mother': family.mother = p if not context.use_common(): if family.father: family.father.too_new = False if family.mother: family.mother.too_new = False family.no_of_children = 0 family.num_hidden_children = 0 for person_node, name_node, birth_node, death_node in record[ 'child']: # record['child'][0]: # [<Node id=235176 labels={'Person'} # properties={'sortname': '#Andersdotter#Maria Christina', # 'datetype': 19, 'confidence': '2.0', 'sex': 2, 'change': 1532009600, # 'handle': '_dd2a65b2f8c7e05bc664bd49d54', 'id': 'I0781', 'date2': 1877226, 'date1': 1877219}>, # <Node id=235177 labels={'Name'} # properties={'firstname': 'Maria Christina', 'type': 'Birth Name', 'suffix': 'Andersdotter', # 'prefix': '', 'surname': '', 'order': 0}>, # <Node id=242697 labels={'Event'} # properties={'datetype': 0, 'change': 1532009545, 'description': '', 'handle': '_dd2a65b218a14e81692d77955d2', # 'id': 'E1886', 'date2': 1877219, 'type': 'Birth', 'date1': 1877219}>, # <Node id=242702 labels={'Event'} # properties={'datetype': 0, 'change': 1519916327, 'description': '', 'handle': '_dd2a65b218a4e85ab141faeab48', # 'id': 'E1887', 'date2': 1877226, 'type': 'Death', 'date1': 1877226}> # ] if person_node: family.no_of_children += 1 p = Person_combo.from_node(person_node) if name_node: p.names.append(Name.from_node(name_node)) set_birth_death(p, birth_node, death_node) if context.use_common(): if p.too_new: family.num_hidden_children += 1 continue else: p.too_new = False family.children.append(p) #family.no_of_children = len(family.children) for repository_node, source_node, citation_node in record[ 'sources']: # record['sources'][0]: # [<Node id=253027 labels={'Repository'} # properties={'handle': '_dcad22f5914b34fe61c341dad0', 'id': 'R0068', 'rname': 'Taivassalon seurakunnan arkisto', # 'type': 'Archive', 'change': '1546265916'}>, # <Node id=247578 labels={'Source'} # properties={'handle': '_e085cd6d68d256a94afecd2162d', 'id': 'S1418', # 'stitle': 'Taivassalon seurakunnan syntyneiden ja kastettujen luettelot 1790-1850 (I C:4)', # 'change': '1543186596'}>, # <Node id=246371 labels={'Citation'} # properties={'handle': '_dd12b0b88d5741ee11d8bef1ca5', 'id': 'C0854', 'page': 'Vigde år 1831 April 4', # /* dates missing here */, 'change': 1543186596, 'confidence': '2'}> # ] if repository_node: source = Source.from_node(source_node) cita = Citation.from_node(citation_node) repo = Repository.from_node(repository_node) source.repositories.append(repo) source.citations.append(cita) family.sources.append(source) for node in record['note']: note = Note.from_node(node) family.notes.append(note) except Exception as e: print('Error get_family_data: {} {}'.format( e.__class__.__name__, e)) raise return family