def show_places(): """ List of Places for menu(4) """ t0 = time.time() print(f"--- {request}") print(f"--- {user_session}") # Set context by owner and the data selections u_context = UserContext(user_session, current_user, request) # Which range of data is shown u_context.set_scope_from_request(request, 'place_scope') u_context.count = request.args.get('c', 50, type=int) dbdriver = Neo4jReadDriver(shareds.driver) reader = PlaceReader(dbdriver, u_context) # The list has Place objects, which include also the lists of # nearest upper and lower Places as place[i].upper[] and place[i].lower[] results = reader.get_list() elapsed = time.time() - t0 stk_logger( u_context, f"-> bp.scene.routes.show_places n={len(results['items'])} e={elapsed:.3f}" ) return render_template("/scene/places.html", places=results['items'], menuno=4, user_context=u_context, elapsed=elapsed)
def show_source_page(sourceid=None): """ Home page for a Source with referring Event and Person data """ uuid = request.args.get('uuid', sourceid) if not uuid: return redirect(url_for('virhesivu', code=1, text="Missing Source key")) u_context = UserContext(user_session, current_user, request) try: dbdriver = Neo4jReadDriver(shareds.driver) reader = SourceReader(dbdriver, u_context) results = reader.get_source_with_references(uuid, u_context) if results['status'] == Status.NOT_FOUND: msg = results.get('statustext', _('No objects found')) return redirect(url_for('virhesivu', code=1, text=msg)) if results['status'] != Status.OK: msg = results.get('statustext', _('Error')) return redirect(url_for('virhesivu', code=1, text=msg)) except KeyError as e: return redirect(url_for('virhesivu', code=1, text=str(e))) stk_logger( u_context, f"-> bp.scene.routes.show_source_page n={len(results['citations'])}") # for c in results.citations: # for i in c.citators: # if i.id[0] == "F": print(f'{c} – family {i} {i.clearname}') # else: print(f'{c} – person {i} {i.sortname}') return render_template("/scene/source_events.html", source=results['item'], citations=results['citations'], user_context=u_context)
def show_place(locid): """ Home page for a Place, shows events and place hierarchy. """ t0 = time.time() try: u_context = UserContext(user_session, current_user, request) dbdriver = Neo4jReadDriver(shareds.driver) reader = PlaceReader(dbdriver, u_context) results = reader.get_with_events(locid) if results['status'] == Status.NOT_FOUND: return redirect( url_for('virhesivu', code=1, text=f'Ei löytynyt yhtään')) if results['status'] != Status.OK: return redirect(url_for('virhesivu', code=1, text=f'Virhetilanne')) except KeyError as e: traceback.print_exc() return redirect(url_for('virhesivu', code=1, text=str(e))) stk_logger(u_context, f"-> bp.scene.routes.show_place n={len(results['events'])}") return render_template("/scene/place_events.html", place=results['place'], pl_hierarchy=results['hierarchy'], events=results['events'], user_context=u_context, elapsed=time.time() - t0)
def show_family_page(uid=None): """ One Family. """ uid = request.args.get('uuid', uid) if not uid: return redirect(url_for('virhesivu', code=1, text="Missing Family key")) t0 = time.time() try: u_context = UserContext(user_session, current_user, request) dbdriver = Neo4jReadDriver(shareds.driver) reader = FamilyReader(dbdriver, u_context) results = reader.get_family_data(uid) #family = Family_combo.get_family_data(uid, u_context) except KeyError as e: return redirect(url_for('virhesivu', code=1, text=str(e))) stk_logger(u_context, "-> bp.scene.routes.show_family_page") if results['status']: return redirect( url_for('virhesivu', code=1, text=results['statustext'])) return render_template("/scene/family.html", menuno=3, family=results['item'], user_context=u_context, elapsed=time.time() - t0)
def show_persons_all(): """ List all persons for menu(12). Both my own and other persons depending on sum of url attributes div + div2 or session variables. The position in persons list is defined by – 1. by attribute fw, if defined (the forward arrow or from seach field) 2. by session next_person[1], if defined (the page last visited) #TODO: next_person[0] is not in use, yet (backward arrow) 3. otherwise "" (beginning) """ print(f"--- {request}") print(f"--- {user_session}") # Set filter by owner and the data selections u_context = UserContext(user_session, current_user, request) # Which range of data is shown u_context.set_scope_from_request(request, 'person_scope') # How many objects are shown? u_context.count = int(request.args.get('c', 100)) u_context.privacy_limit = shareds.PRIVACY_LIMIT t0 = time.time() dbdriver = Neo4jReadDriver(shareds.driver) db = DBreader(dbdriver, u_context) results = db.get_person_list() elapsed = time.time() - t0 hidden = f" hide={results.num_hidden}" if results.num_hidden > 0 else "" stk_logger( u_context, f"-> bp.scene.routes.show_persons_all" f" n={len(results.items)}{hidden} e={elapsed:.3f}") # print(f"Got {len(results.items)} persons" # f" with {len(results.items)-results.num_hidden} hidden" # f" and {results.error} errors" # f" in {elapsed:.3f}s") return render_template("/scene/persons_list.html", persons=results.items, num_hidden=results.num_hidden, user_context=u_context, menuno=12, elapsed=elapsed)
def show_sources(series=None): """ Lähdeluettelon näyttäminen ruudulla for menu(5) Possible args example: ?years=1800-1899&series=birth - source years (#todo) - series, one of {"birth", "babtism", "wedding", "death", "move"} Missing series or years = all Theme may also be expressed in url path """ print(f"--- {request}") print(f"--- {user_session}") t0 = time.time() # Set context by owner and the data selections u_context = UserContext(user_session, current_user, request) # Which range of data is shown u_context.set_scope_from_request(request, 'source_scope') u_context.count = request.args.get('c', 100, type=int) dbdriver = Neo4jReadDriver(shareds.driver) reader = SourceReader(dbdriver, u_context) if series: u_context.series = series try: results = reader.get_source_list() if results['status'] == Status.NOT_FOUND: return redirect( url_for('virhesivu', code=1, text=f'Ei löytynyt yhtään')) if results['status'] != Status.OK: return redirect(url_for('virhesivu', code=1, text=f'Virhetilanne')) except KeyError as e: return redirect(url_for('virhesivu', code=1, text=str(e))) series = u_context.series if u_context.series else "all" stk_logger( u_context, f"-> bp.scene.routes.show_sources/{series} n={len(results['items'])}") return render_template("/scene/sources.html", sources=results['items'], user_context=u_context, elapsed=time.time() - t0)
def show_event_v1(uuid): """ Event page with accompanied persons and families. Derived from bp.tools.routes.show_baptism_data() """ u_context = UserContext(user_session, current_user, request) dbdriver = Neo4jReadDriver(shareds.driver) reader = EventReader(dbdriver, u_context) results = reader.get_event_data(uuid) status = results.get('status') if status != Status.OK: flash(f'{_("Event not found")}: {results.get("statustext")}', 'error') event = results.get('event', None) members = results.get('members', []) stk_logger(u_context, f"-> bp.scene.routes.show_event_page n={len(members)}") return render_template("/scene/event.html", event=event, participants=members)
def json_get_person_families(): """ Get all families for a Person as json structure. The families are ordered by marriage time. """ t0 = time.time() try: args = request.args if args: print(f'got request args: {args}') else: args = json.loads(request.data) print(f'got request data: {args}') uuid = args.get('uuid') if not uuid: print("bp.scene.routes.json_get_person_families: Missing uuid") return jsonify({ "records": [], "status": Status.ERROR, "statusText": "Missing uuid" }) u_context = UserContext(user_session, current_user, request) dbdriver = Neo4jReadDriver(shareds.driver) reader = FamilyReader(dbdriver, u_context) results = reader.get_person_families(uuid) if results.get('status') == Status.NOT_FOUND: return jsonify({ "member": uuid, "records": [], "statusText": _('No families'), "status": Status.NOT_FOUND }) items = results['items'] res_dict = { 'records': items, "member": uuid, 'statusText': f'Löytyi {len(items)} perhettä', 'translations': { 'family': _('Family'), 'children': _('Children') } } response = json.dumps(res_dict, cls=StkEncoder) t1 = time.time() - t0 stk_logger( u_context, f"-> bp.scene.routes.show_person_families_json n={len(items)} e={t1:.3f}" ) print(response) return response except Exception as e: traceback.print_exc() return jsonify({ "records": [], "status": Status.ERROR, "member": uuid, "statusText": f"Failed {e.__class__.__name__}" })
def json_get_event(): """ Get Event page data. """ t0 = time.time() try: args = request.args if args: print(f'got request args: {args}') else: args = json.loads(request.data) print(f'got request data: {args}') uuid = args.get('uuid') if not uuid: print("bp.scene.routes.json_get_person_families: Missing uuid") return jsonify({ "records": [], "status": Status.ERROR, "statusText": "Missing uuid" }) u_context = UserContext(user_session, current_user, request) dbdriver = Neo4jReadDriver(shareds.driver) reader = EventReader(dbdriver, u_context) results = reader.get_event_data(uuid, args) status = results.get('status') if status != Status.OK: flash(f'{_("Event not found")}: {results.get("statustext")}', 'error') if status == Status.NOT_FOUND: return jsonify({ "event": None, "members": [], "statusText": _('No event found'), "status": status }) elif status != Status.OK: return jsonify({ "event": None, "members": [], "statusText": _('No event found'), "status": status }) # Event event = results.get('event', None) event.type_lang = jinja_filters.translate(event.type, 'evt').title() # Event members members = results.get('members', []) for m in members: if m.label == "Person": m.href = '/scene/person?uuid=' + m.uuid m.names[0].type_lang = jinja_filters.translate( m.names[0].type, 'nt') elif m.label == "Family": m.href = '/scene/family?uuid=' + m.uuid m.role_lang = jinja_filters.translate(m.role, 'role') if m.role else '' # Actually there is one place and one pl.uppers places = results.get('places', []) for pl in places: pl.href = '/scene/location/uuid=' + pl.uuid pl.type_lang = jinja_filters.translate(pl.type, 'lt').title() for up in pl.uppers: up.href = '/scene/location/uuid=' + up.uuid up.type_lang = jinja_filters.translate(up.type, 'lt_in').title() # Event notes notes = results.get('notes', []) # Medias medias = results.get('medias', []) for m in medias: m.href = '/scene/media?uuid=' + m.uuid #TODO: The auditor may edit, not user self as here if u_context.user and u_context.context == u_context.choices.OWN: allow_edit = True else: allow_edit = False res_dict = { "event": event, 'members': members, 'notes': notes, 'places': places, 'medias': medias, 'statusText': f'Löytyi {len(members)} tapahtuman osallista', 'allow_edit': allow_edit, 'translations': { 'myself': _('Self') } } response = json.dumps(res_dict, cls=StkEncoder) print(response) t1 = time.time() - t0 stk_logger( u_context, f"-> bp.scene.routes.json_get_event n={len(members)} e={t1:.3f}") return response except Exception as e: traceback.print_exc() return jsonify({ "records": [], "status": Status.ERROR, "member": uuid, "statusText": f"Failed {e.__class__.__name__}" })