示例#1
0
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)
示例#2
0
def show_families():
    """ List of Families for menu(3)
    """
    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, 'person_scope')
    opt = request.args.get('o', 'father', type=str)
    u_context.order = 'man' if opt == 'father' else 'wife'
    count = request.args.get('c', 100, type=int)
    t0 = time.time()

    # 'families' has Family objects
    families = Family_combo.get_families(o_context=u_context,
                                         opt=opt,
                                         limit=count)

    stk_logger(u_context,
               f"-> bp.scene.routes.show_families/{opt} n={len(families)}")
    return render_template("/scene/families.html",
                           families=families,
                           user_context=u_context,
                           elapsed=time.time() - t0)
示例#3
0
def read_families():
    """ Lukee tietokannasta Family- objektit näytettäväksi
    """

    u_context = UserContext(user_session, current_user, request)
    # Which range of data is shown
    u_context.set_scope_from_request(request, 'person_scope')
    opt = request.args.get('o', 'father', type=str)
    count = request.args.get('c', 100, type=int)

    families = Family_combo.get_families(o_context=u_context,
                                         opt=opt,
                                         limit=count)

    return (families)
示例#4
0
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)
示例#5
0
def show_medias():
    """ List of Medias for menu(5)
    """
    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, 'media_scope')
    try:
        medias = Media.read_my_media_list(u_context, 20)

    except KeyError as e:
        return redirect(url_for('virhesivu', code=1, text=str(e)))
    stk_logger(u_context, f"-> bp.scene.media.show_medias fw n={len(medias)}")
    return render_template("/scene/medias.html",
                           medias=medias,
                           user_context=u_context,
                           elapsed=time.time() - t0)
示例#6
0
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)
示例#7
0
def test_ownerfilter_next_item(user_env):
    ''' Example: Show all my data  with common data
            default direction (fw)
            - from previous next_person: start '<'
            - from previous next_person 'Abrahamsson##Juho Kustaa'
            - from previous next_person: end '>'

        <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

    # 0. Initialize UserContext with current session, user and request info
    f = UserContext(user_session, current_user, request)

    # 1. In the beginning
    user_session['person_scope'] = ['', '<']
    f.set_scope_from_request(request, 'person_scope')
    #    Read data here --> got required amount
    f.update_session_scope('person_name', '##Elisabet', '#Hansson#Lars', 100,
                           100)

    x = f.next_name_fw()
    assert x == '', "next fw not in the beginning"

    # 2. At given point
    user_session['person_scope'] = ['Za', None]
    f.set_scope_from_request(request, 'person_scope')
    #    Read data here --> reached end
    f.update_session_scope('person_name', 'Zakrevski##Arseni', 'Östling##Carl',
                           50, 28)

    x = f.next_name_fw()
    assert x == 'Zakrevski##Arseni', "next fw not at given point"

    # 3. At end
    user_session['person_scope'] = ['>', None]
    #    Read data here --> reached end
    f.set_scope_from_request(request, 'person_scope')

    x = f.next_name_fw()
    assert x == '> end', "next fw not at end"