Beispiel #1
0
def manage_gym(environ, start_response):
    store = environ['tiddlyweb.store']
    gym = get_route_value(environ, 'gym')
    routes_bag = store.get(Bag('%s_climbs' % gym))
    news_bag = Bag('%s_news' % gym)
    # Bail out if we are not allowed to manage. 
    routes_bag.policy.allows(environ['tiddlyweb.usersign'], 'manage')
    gym_tiddler = store.get(Tiddler(gym, GYMS_BAG))

    try:
        latest_news = [tiddler for tiddler in filter_tiddlers(
            store.list_bag_tiddlers(news_bag),
            'sort=-modified;limit=1', environ)][0]
        latest_news = store.get(latest_news)
        news_html = render_wikitext(latest_news, environ)
        latest_news.fields['html'] = news_html
    except IndexError:
        latest_news = Tiddler('tmp')
        latest_news.fields['html'] = '<p>No News</p>'

    routes = _get_gym_routes(environ, gym)

    return send_template(environ, 'manage_gym.html', {
        'title': 'Manage %s' % gym,
        'gym_tiddler': gym_tiddler,
        'latest_news': latest_news,
        'routes': routes})
Beispiel #2
0
def ticklist(environ, start_response):
    """
    Display a user's own ticklist.
    """
    store = environ['tiddlyweb.store']
    current_user = environ['tiddlyweb.usersign']['name']
    gym = get_route_value(environ, 'gym')
    routes = _get_gym_routes(environ, gym)

    climbtypes = [tiddler.title for tiddler in
            store.list_bag_tiddlers(Bag(CLIMBTYPES))]

    search_query = 'bag:%s tag:tickwish gym:%s _limit:%s' % (current_user,
            gym, len(routes))
    wished_climbs = dict([(tiddler.title, store.get(tiddler))
        for tiddler in store.search(search_query)])
    for route in routes:
        if route.title in wished_climbs:
            wished_climbs[route.title].fields['do'] = True

    return send_template(environ, 'gym_routes.html', {
        'gym': gym,
        'climbtypes': [''] + climbtypes,
        'title': 'Ticklist for %s@%s' % (current_user, gym),
        'routes': wished_climbs.values()})
Beispiel #3
0
def gym_routes(environ, start_response):
    """
    Display the routes from a single gym.
    """
    store = environ['tiddlyweb.store']
    current_user = environ['tiddlyweb.usersign']['name']
    gym = get_route_value(environ, 'gym')
    routes = _get_gym_routes(environ, gym)
    climbtypes = [tiddler.title for tiddler in
            store.list_bag_tiddlers(Bag(CLIMBTYPES))]
    if current_user:# != 'GUEST':
        search_query = 'bag:%s tag:climb gym:%s _limit:%s' % (current_user,
                gym, len(routes))
        recent_climbs = dict([(tiddler.title, store.get(tiddler))
            for tiddler in store.search(search_query)])
        search_query = 'bag:%s tag:tickwish gym:%s _limit:%s' % (current_user,
                gym, len(routes))
        wished_climbs = [tiddler.title for tiddler in store.search(search_query)]
        for route in routes:
            if route.title in recent_climbs:
                route.fields['climbtype'] = recent_climbs[
                        route.title].fields['climbtype']
            if route.title in wished_climbs:
                route.fields['do'] = True

    return send_template(environ, 'gym_routes.html', {
        'gym': gym,
        'climbtypes': [''] + climbtypes,
        'title': 'Routes @%s' % gym,
        'routes': routes})
Beispiel #4
0
def manager(environ, start_response):
    """
    Display all the gyms one manager can manage.
    """
    kept_bags, fullnames = get_gyms(environ, 'manage')
    return send_template(environ, 'manage_list.html', {'gyms': kept_bags,
        'title': 'Your Gyms', 'fullnames': fullnames})
Beispiel #5
0
def admin(environ, start_response):
    store = environ['tiddlyweb.store']
    gyms = (store.get(tiddler) for
            tiddler in filter_tiddlers(
                store.list_bag_tiddlers(Bag(GYMS_BAG)),
                'sort=title', environ))

    return send_template(environ, 'admin.html', { 'gyms': gyms,
        'title': 'Admin Page'})
Beispiel #6
0
def gym_routes(environ, start_response):
    """
    Display the routes from a single gym.
    """
    gym = get_route_value(environ, 'gym')
    routes = _get_gym_routes(environ, gym)
    return send_template(environ, 'gym_routes.html', {
        'title': 'Routes @%s' % gym,
        'routes': routes})
Beispiel #7
0
def gym_editor(environ, start_response):
    store = environ['tiddlyweb.store']
    gym = get_route_value(environ, 'gym')
    try:
        tiddler = Tiddler(gym, GYMS_BAG)
        tiddler = store.get(tiddler)
    except StoreError:
        pass  # new gym

    return send_template(environ, 'gym_editor.html', {'tiddler': tiddler,
        'title': 'Edit Gym %s' % gym})
Beispiel #8
0
def home(environ, start_response):
    kept_bags, fullnames = get_gyms(environ, 'read')
    return send_template(environ, 'home.html', { 'gyms': kept_bags,
        'fullnames': fullnames, 'title': 'Welcome to Nitor'})
Beispiel #9
0
def manager(environ, start_response):
    kept_bags, fullnames = get_gyms(environ, 'manage')
    return send_template(environ, 'manage_list.html', {'gyms': kept_bags,
        'title': 'Your Gyms', 'fullnames': fullnames})
Beispiel #10
0
    try:
        gym_tiddler = store.get(Tiddler(gym, GYMS_BAG))
        news_bag = Bag('%s_news' % gym)
        latest_news = [tiddler for tiddler in filter_tiddlers(
            store.list_bag_tiddlers(news_bag),
            'sort=-created;limit=10', environ)]
        for tiddler in latest_news:
            tiddler = store.get(tiddler)
            news_html = render_wikitext(tiddler, environ)
            tiddler.fields['html'] = news_html
            news_tiddlers.append(tiddler)

    except StoreError, exc:
        raise HTTP404('that gym does not exist: %s' % exc)
    return send_template(environ, 'gym.html', {
        'gym': gym_tiddler,
        'title': gym,
        'news_tiddlers': news_tiddlers})


@do_html()
def gym_routes(environ, start_response):
    """
    Display the routes from a single gym.
    """
    gym = get_route_value(environ, 'gym')
    routes = _get_gym_routes(environ, gym)
    return send_template(environ, 'gym_routes.html', {
        'title': 'Routes @%s' % gym,
        'routes': routes})