Esempio n. 1
0
def test_readable_tiddlers_by_bag():
    bagone = Bag('cdentread')
    bagone.policy.read = ['cdent']
    store.put(bagone)
    bagtwo = Bag('fndread')
    bagtwo.policy.read = ['fnd']
    store.put(bagtwo)
    bagthree = Bag('allread')
    store.put(bagthree)

    count = 0
    tiddlers = []
    for bag in ['cdent', 'fnd', 'all', 'cdent', 'fnd', 'all', 'notreal']:
        count += 1
        tiddler = Tiddler('tiddler%s' % count, '%sread' % bag)
        tiddler.text = 'narf'
        tiddlers.append(tiddler)

    usersign = {'name': 'cdent', 'roles': []}
    readable = list(readable_tiddlers_by_bag(store, tiddlers, usersign))
    assert (['tiddler1', 'tiddler3', 'tiddler4', 'tiddler6', 'tiddler7'] ==
            [tiddler.title for tiddler in readable])

    usersign = {'name': 'fnd', 'roles': []}
    readable = list(readable_tiddlers_by_bag(store, tiddlers, usersign))
    assert (['tiddler2', 'tiddler3', 'tiddler5', 'tiddler6', 'tiddler7'] ==
            [tiddler.title for tiddler in readable])

    usersign = {'name': 'GUEST', 'roles': []}
    readable = list(readable_tiddlers_by_bag(store, tiddlers, usersign))
    assert (['tiddler3', 'tiddler6', 'tiddler7'] ==
            [tiddler.title for tiddler in readable])
Esempio n. 2
0
def test_readable_tiddlers_by_bag():
    bagone = Bag('cdentread')
    bagone.policy.read = ['cdent']
    store.put(bagone)
    bagtwo = Bag('fndread')
    bagtwo.policy.read = ['fnd']
    store.put(bagtwo)
    bagthree = Bag('allread')
    store.put(bagthree)

    count = 0
    tiddlers = []
    for bag in ['cdent', 'fnd', 'all', 'cdent', 'fnd', 'all', 'notreal']:
        count += 1
        tiddler = Tiddler('tiddler%s' % count, '%sread' % bag)
        tiddler.text = 'narf'
        tiddlers.append(tiddler)

    usersign = {'name': 'cdent', 'roles': []}
    readable = list(readable_tiddlers_by_bag(store, tiddlers, usersign))
    assert (['tiddler1', 'tiddler3', 'tiddler4', 'tiddler6',
             'tiddler7'] == [tiddler.title for tiddler in readable])

    usersign = {'name': 'fnd', 'roles': []}
    readable = list(readable_tiddlers_by_bag(store, tiddlers, usersign))
    assert (['tiddler2', 'tiddler3', 'tiddler5', 'tiddler6',
             'tiddler7'] == [tiddler.title for tiddler in readable])

    usersign = {'name': 'GUEST', 'roles': []}
    readable = list(readable_tiddlers_by_bag(store, tiddlers, usersign))
    assert (['tiddler3', 'tiddler6',
             'tiddler7'] == [tiddler.title for tiddler in readable])
Esempio n. 3
0
def get(environ, start_response):
    """
    Perform a search on the store. What search
    means and what results are returned is dependent
    on the search implementation (if any) in the
    chosen store.
    """
    store = environ['tiddlyweb.store']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = get_tiddlers(environ)

        usersign = environ['tiddlyweb.usersign']

        candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError, exc:
        raise HTTP400('Error while processing search: %s' % exc)
def whoosher_search(environ, start_response):
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = whoosh_search(environ)

        usersign = environ['tiddlyweb.usersign']

        if filters:
            candidate_tiddlers = Tiddlers(title=title)
        else:
            candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError as exc:
        raise HTTP400('Error while processing search: %s' % exc)

    return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
Esempio n. 5
0
def get_sidebar(environ, tags=None, users=None, gyms=None):
    store = environ['tiddlyweb.store']
    usersign = environ['tiddlyweb.usersign']
    if not tags:
        tags =  DEFAULT_SIDEBAR_TAGS
    query = ' OR '.join(['tag:%s' % tag for tag in tags])
    return (store.get(tiddler) for tiddler in
            readable_tiddlers_by_bag(store, store.search(query), usersign))
Esempio n. 6
0
def get(environ, start_response):
    """
    Handle ``GET`` on the search URI.

    Perform a search against the :py:class:`store <tiddlyweb.store.Store>`.

    What search means and what results are returned is dependent
    on the search implementation (if any) in the :py:class:`chosen store
    <tiddlyweb.stores.StorageInterface>`.
    """
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = get_tiddlers(environ)

        usersign = environ['tiddlyweb.usersign']

        if filters:
            candidate_tiddlers = Tiddlers(title=title)
        else:
            candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError as exc:
        raise HTTP400('Error while processing search: %s' % exc)

    return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
Esempio n. 7
0
def get(environ, start_response):
    """
    Handle ``GET`` on the search URI.

    Perform a search against the :py:class:`store <tiddlyweb.store.Store>`.

    What search means and what results are returned is dependent
    on the search implementation (if any) in the :py:class:`chosen store
    <tiddlyweb.stores.StorageInterface>`.
    """
    store = environ['tiddlyweb.store']
    filters = environ['tiddlyweb.filters']
    search_query = get_search_query(environ)
    title = 'Search for %s' % search_query
    title = environ['tiddlyweb.query'].get('title', [title])[0]

    try:
        tiddlers = get_tiddlers(environ)

        usersign = environ['tiddlyweb.usersign']

        if filters:
            candidate_tiddlers = Tiddlers(title=title)
        else:
            candidate_tiddlers = Tiddlers(title=title, store=store)
        candidate_tiddlers.is_search = True

        for tiddler in readable_tiddlers_by_bag(store, tiddlers, usersign):
            candidate_tiddlers.add(tiddler)

    except StoreMethodNotImplemented:
        raise HTTP400('Search system not implemented')
    except StoreError as exc:
        raise HTTP400('Error while processing search: %s' % exc)

    return send_tiddlers(environ, start_response, tiddlers=candidate_tiddlers)
Esempio n. 8
0
        store.get(User(username))
    except NoUserError:
        raise HTTP404('Profile not found for %s' % username)

    activity_feed = profile_atom_url(environ, username)

    profile_tiddler = Tiddler('profile', '%s_public' % username)
    try:
        profile_tiddler = store.get(profile_tiddler)
    except StoreError, exc:
        raise HTTP404('No profile for %s: %s' % (username, exc))

    profile_text = render_wikitext(profile_tiddler, environ)

    tiddlers = store.search(_search_string(username))
    tiddlers_list = readable_tiddlers_by_bag(store, tiddlers, usersign)

    avatar_path = '/recipes/%s_public/tiddlers/SiteIcon' % username

    start_response('200 OK', [
        ('Content-Type', 'text/html; charset=UTF-8')])

    return send_template(environ, 'tsprofile.html', {
        'css': ['/bags/common/tiddlers/profile.css'],
        'title': 'Profile for %s' % username,
        'username': username,
        'activity_feed': activity_feed,
        'avatar_path': avatar_path,
        'space_uri': space_uri(environ, username),
        'profile': profile_text,
        'tiddler_url': tiddler_url,
Esempio n. 9
0
        store.get(User(username))
    except NoUserError:
        raise HTTP404('Profile not found for %s' % username)

    activity_feed = profile_atom_url(environ, username)

    profile_tiddler = Tiddler('profile', '%s_public' % username)
    try:
        profile_tiddler = store.get(profile_tiddler)
    except StoreError, exc:
        raise HTTP404('No profile for %s: %s' % (username, exc))

    profile_text = render_wikitext(profile_tiddler, environ)

    tiddlers = store.search(_search_string(username))
    tiddlers_list = readable_tiddlers_by_bag(store, tiddlers, usersign)

    avatar_path = '/recipes/%s_public/tiddlers/SiteIcon' % username

    start_response('200 OK', [('Content-Type', 'text/html; charset=UTF-8')])

    return send_template(
        environ, 'tsprofile.html', {
            'css': ['/bags/common/tiddlers/profile.css'],
            'title': 'Profile for %s' % username,
            'username': username,
            'activity_feed': activity_feed,
            'avatar_path': avatar_path,
            'space_uri': space_uri(environ, username),
            'profile': profile_text,
            'tiddler_url': tiddler_url,