Exemplo n.º 1
0
def user_page(environ, start_response):
    userpage = environ['wsgiorg.routing_args'][1]['userpage']
    user = environ['tiddlyweb.usersign']

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ['tiddlyweb.store']

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass  # roles will be empty
    if 'MEMBER' not in userpage_user.list_roles():
        raise HTTP404('%s has no page' % userpage)

    user_friend_names = get_friends(store, user['name'])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage),
                               user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage),
                               user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {
        'bags': kept_bags,
        'user_friends': user_friend_names,
        'friends': friends,
        'recipes': kept_recipes,
        'favorites': kept_favorites,
        'bookmarks': kept_bookmarks,
        'home': userpage,
        'profile': profile_html,
        'notice': {
            'html': notice_html,
            'modified': notice_tiddler.modified
        },
        'title': userpage,
        'email': email,
        'email_md5': email_md5,
        'user': get_user_object(environ)
    }

    return send_template(environ, 'profile.html', data)
Exemplo n.º 2
0
def user_page(environ, start_response):
    userpage = environ['wsgiorg.routing_args'][1]['userpage']
    user = environ['tiddlyweb.usersign']

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ['tiddlyweb.store']

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass # roles will be empty
    if 'MEMBER' not in userpage_user.list_roles():
        raise HTTP404('%s has no page' % userpage)

    user_friend_names = get_friends(store, user['name'])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage),
            user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage),
            user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {'bags': kept_bags,
            'user_friends': user_friend_names,
            'friends': friends,
            'recipes': kept_recipes,
            'favorites': kept_favorites,
            'bookmarks': kept_bookmarks,
            'home': userpage,
            'profile': profile_html,
            'notice': {'html': notice_html,
                'modified': notice_tiddler.modified},
            'title': userpage,
            'email': email,
            'email_md5': email_md5,
            'user': get_user_object(environ)}

    return send_template(environ, 'profile.html', data)
Exemplo n.º 3
0
def user_page(environ, start_response):
    userpage = environ["wsgiorg.routing_args"][1]["userpage"]
    user = environ["tiddlyweb.usersign"]

    userpage = _decode_name(userpage)

    first_time_check(environ, user)

    store = environ["tiddlyweb.store"]

    # If we try to go to a user page that doesn't exist,
    # just go to the home page. XXX maybe should 404 instead.
    try:
        userpage_user = User(userpage)
        userpage_user = store.get(userpage_user)
    except NoUserError:
        pass  # roles will be empty
    if "MEMBER" not in userpage_user.list_roles():
        raise HTTP404("%s has no page" % userpage)

    user_friend_names = get_friends(store, user["name"])
    friend_names = sorted(get_friends(store, userpage))
    friends = []
    for name in friend_names:
        email = get_email_tiddler(store, name)
        email_md5 = md5(email.lower()).hexdigest()
        friends.append((name, email_md5))

    profile_tiddler = get_profile(store, user, userpage)
    profile_html = render_wikitext(profile_tiddler, environ)
    notice_tiddler = get_notice(environ)
    notice_html = render_wikitext(notice_tiddler, environ)
    kept_recipes = get_stuff(store, store.list_recipes(), user, userpage)
    kept_bags = get_stuff(store, store.list_bags(), user, userpage)
    kept_favorites = get_stuff(store, get_favorited_bags(store, userpage), user)
    kept_bookmarks = get_stuff(store, get_bookmarked_recipes(store, userpage), user)
    email = get_email_tiddler(store, userpage)
    email_md5 = md5(email.lower()).hexdigest()
    data = {
        "bags": kept_bags,
        "user_friends": user_friend_names,
        "friends": friends,
        "recipes": kept_recipes,
        "favorites": kept_favorites,
        "bookmarks": kept_bookmarks,
        "home": userpage,
        "profile": profile_html,
        "notice": {"html": notice_html, "modified": notice_tiddler.modified},
        "title": userpage,
        "email": email,
        "email_md5": email_md5,
        "user": get_user_object(environ),
    }

    return send_template(environ, "profile.html", data)
Exemplo n.º 4
0
 def tiddler_as(self, tiddler):
     """
     Transform the provided tiddler into an HTML
     representation of the tiddler packaged in a
     DIV. Render the content using the render_wikitext
     subsystem. Links to the tiddler in the wiki are
     provided.
     """
     user = self.environ['tiddlyweb.usersign']
     store = self.environ['tiddlyweb.store']
     if tiddler.recipe:
         list_link = '/recipes/%s/tiddlers' % encode_name(tiddler.recipe)
         list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
     else:
         list_link = '/bags/%s/tiddlers' % encode_name(tiddler.bag)
         list_title = 'Tiddlers in Bag %s' % tiddler.bag
     try:
         store.get(Bag(tiddler.bag)).policy.allows(user, 'manage')
         container_policy = True
     except PermissionsError:
         container_policy = False
     space_link = self._space_link(tiddler)
     html = render_wikitext(tiddler, self.environ)
     return send_template(self.environ, 'tiddler.html', {
         'title': '%s' % tiddler.title,
         'tags': tiddler.tags,
         'fields': tiddler.fields,
         'html': html,
         'list_link': list_link,
         'list_title': list_title,
         'space_link': space_link,
         'tiddler': tiddler,
         'container_policy': container_policy,
         'tiddler_url': tiddler_url(self.environ, tiddler)})
Exemplo n.º 5
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})
Exemplo n.º 6
0
    def _add_tiddler_to_feed(self, feed, tiddler):
        do_revisions = self.environ.get('tiddlyweb.query', {}).get(
                'depth', [None])[0]

        if not do_revisions:
            if binary_tiddler(tiddler):
                # XXX: ought to be enclosures?
                if tiddler.type.startswith('image/'):
                    description = ('\n<img src="%s" />\n'
                            % tiddler_url(self.environ, tiddler))
                else:
                    description = ('\n<a href="%s">%s</a>\n'
                            % (tiddler_url(self.environ, tiddler),
                                tiddler.title))
            elif (renderable(tiddler, self.environ)):
                try:
                    description = render_wikitext(tiddler, self.environ)
                except KeyError:
                    description = 'Tiddler cannot be rendered.'
            else:
                description = '<pre>' + tiddler.text + '</pre>'

            self._add_item(feed, tiddler, tiddler_url(self.environ, tiddler),
                    tiddler.title, description)
        else:
            self._process_tiddler_revisions(feed, tiddler,
                    tiddler_url(self.environ, tiddler), do_revisions)
Exemplo n.º 7
0
 def _tiddler_dict(self, tiddler, fat=False, render=False):
     """
     Select fields from a tiddler to create
     a dictonary.
     """
     unwanted_keys = ['text', 'store']
     wanted_keys = [
         attribute for attribute in tiddler.slots
         if attribute not in unwanted_keys
     ]
     wanted_info = {}
     for attribute in wanted_keys:
         wanted_info[attribute] = getattr(tiddler, attribute, None)
     wanted_info['permissions'] = self._tiddler_permissions(tiddler)
     wanted_info['uri'] = tiddler_url(self.environ, tiddler)
     if fat:
         if tiddler.text:
             if binary_tiddler(tiddler):
                 wanted_info['text'] = b64encode(tiddler.text)
             else:
                 wanted_info['text'] = tiddler.text
         else:
             wanted_info['text'] = ''
     if render and renderable(tiddler, self.environ):
         wanted_info['render'] = render_wikitext(tiddler, self.environ)
     return wanted_info
Exemplo n.º 8
0
def test_render_wikitext_plain():
    renderer = config['wikitext.default_renderer']
    config['wikitext.default_renderer'] = 'raw'
    text = render_wikitext(tiddler, {'tiddlyweb.config': config})
    config['wikitext.default_renderer'] = renderer

    assert '<h1' not in text
    assert '<pre>' in text
Exemplo n.º 9
0
def test_render_wikitext_plain():
    renderer = config['wikitext.default_renderer']
    config['wikitext.default_renderer'] = 'raw'
    text = render_wikitext(tiddler, {'tiddlyweb.config': config})
    config['wikitext.default_renderer'] = renderer

    assert '<h1' not in text
    assert '<pre>' in text
Exemplo n.º 10
0
    def list_tiddlers(self, bag):
        tiddlers = bag.list_tiddlers()
        title = DEFAULT_TITLE
        subtitle = DEFAULT_SUBTITLE
        presenter = DEFAULT_PRESENTER
        affiliation = DEFAULT_AFFILIATION
        time_location = DEFAULT_TIME_LOCATION
        slides = {}
        slide_order = None
        original_slide_order = []
        for tiddler in tiddlers:
            if tiddler.title == 'SiteTitle':
                title = tiddler.text
                continue
            if tiddler.title == 'SiteSubtitle':
                subtitle = tiddler.text
                continue
            if tiddler.title == 'S5Presenter':
                presenter = tiddler.text
                continue
            if tiddler.title == 'S5Affiliation':
                affiliation = tiddler.text
                continue
            if tiddler.title == 'S5TimeLocation':
                time_location = render_wikitext(tiddler, self.environ)
                continue
            if tiddler.title == 'S5Sort':
                slide_order = tiddler.text.split('\n')
                continue
            slides[tiddler.title] = tiddler
            original_slide_order.append(tiddler.title)
            tiddler.html = render_wikitext(tiddler, self.environ)

        if slide_order is None:
            slide_order = original_slide_order

        return self.template.render(
            slides=slides,
            slide_order=slide_order,
            server_prefix=self.environ['tiddlyweb.config']['server_prefix'],
            title=title,
            subtitle=subtitle,
            presenter=presenter,
            affiliation=affiliation,
            time_location=time_location)
Exemplo n.º 11
0
    def list_tiddlers(self, bag):
        tiddlers = bag.list_tiddlers()
        title = DEFAULT_TITLE
        subtitle = DEFAULT_SUBTITLE
        presenter = DEFAULT_PRESENTER
        affiliation = DEFAULT_AFFILIATION
        time_location = DEFAULT_TIME_LOCATION
        slides = {}
        slide_order = None
        original_slide_order = []
        for tiddler in tiddlers:
            if tiddler.title == 'SiteTitle':
                title = tiddler.text
                continue
            if tiddler.title == 'SiteSubtitle':
                subtitle = tiddler.text
                continue
            if tiddler.title == 'S5Presenter':
                presenter = tiddler.text
                continue
            if tiddler.title == 'S5Affiliation':
                affiliation = tiddler.text
                continue
            if tiddler.title == 'S5TimeLocation':
                time_location = render_wikitext(tiddler, self.environ)
                continue
            if tiddler.title == 'S5Sort':
                slide_order = tiddler.text.split('\n')
                continue
            slides[tiddler.title] = tiddler
            original_slide_order.append(tiddler.title)
            tiddler.html = render_wikitext(tiddler, self.environ)

        if slide_order is None:
            slide_order = original_slide_order

        return self.template.render(slides=slides,
                slide_order=slide_order,
                server_prefix=self.environ['tiddlyweb.config']['server_prefix'],
                title=title,
                subtitle=subtitle,
                presenter=presenter,
                affiliation=affiliation,
                time_location=time_location)
Exemplo n.º 12
0
def wikifier(mystr, path):
    """
    Render TiddlyWiki wikitext in the provided
    string to HTML. This function taken and modified
    from wikklytextrender.py
    """
    tiddler = Tiddler('tmp')
    tiddler.text = mystr
    tiddler.recipe = path
    environ={'tiddlyweb.config': config}
    return render_wikitext(tiddler, environ)
Exemplo n.º 13
0
def wikifier(mystr, path):
    """
    Render TiddlyWiki wikitext in the provided
    string to HTML. This function taken and modified
    from wikklytextrender.py
    """
    tiddler = Tiddler('tmp')
    tiddler.text = mystr
    tiddler.recipe = path
    environ = {'tiddlyweb.config': config}
    return render_wikitext(tiddler, environ)
Exemplo n.º 14
0
    def tiddler_as(self, tiddler):
        """
        Transform the provided tiddler into an HTML
        representation of the tiddler packaged in a
        DIV. Render the content using the render_wikitext
        subsystem. Links to the tiddler in the wiki are
        provided.
        """
        user = self.environ['tiddlyweb.usersign']
        store = self.environ['tiddlyweb.store']
        if tiddler.recipe:
            list_link = '/recipes/%s/tiddlers' % encode_name(tiddler.recipe)
            list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
        else:
            list_link = '/bags/%s/tiddlers' % encode_name(tiddler.bag)
            list_title = 'Tiddlers in Bag %s' % tiddler.bag
        try:
            store.get(Bag(tiddler.bag)).policy.allows(user, 'manage')
            container_policy = True
        except PermissionsError:
            container_policy = False
        if not self.environ['tiddlyweb.space_settings'].get('index', None):
            space_link = self._space_link(tiddler)
        else:
            space_link = ''
        try:
            modifier_link = space_uri(self.environ, tiddler.modifier)
        except AttributeError:
            modifier_link = ""
        try:
            creator_link = space_uri(self.environ, tiddler.creator)
        except AttributeError:
            creator_link = ""

        html = render_wikitext(tiddler, self.environ)
        return send_template(
            self.environ, 'tiddler.html', {
                'meta_keywords': ', '.join(tiddler.tags),
                'meta_description': tiddler.title,
                'title': '%s' % tiddler.title,
                'tags': tiddler.tags,
                'modifier_link': modifier_link,
                'creator_link': creator_link,
                'fields': tiddler.fields,
                'html': html,
                'list_link': list_link,
                'list_title': list_title,
                'space_link': space_link,
                'tiddler': tiddler,
                'container_policy': container_policy,
                'tiddler_url': tiddler_url(self.environ, tiddler)
            })
Exemplo n.º 15
0
    def tiddler_as(self, tiddler):
        """
        Transform the provided tiddler into an HTML
        representation of the tiddler packaged in a
        DIV. Render the content using the render_wikitext
        subsystem. Links to the tiddler in the wiki are
        provided.
        """
        user = self.environ['tiddlyweb.usersign']
        store = self.environ['tiddlyweb.store']
        if tiddler.recipe:
            list_link = '/recipes/%s/tiddlers' % encode_name(tiddler.recipe)
            list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
        else:
            list_link = '/bags/%s/tiddlers' % encode_name(tiddler.bag)
            list_title = 'Tiddlers in Bag %s' % tiddler.bag
        try:
            store.get(Bag(tiddler.bag)).policy.allows(user, 'manage')
            container_policy = True
        except PermissionsError:
            container_policy = False
        if not self.environ['tiddlyweb.space_settings'].get('index', None):
            space_link = self._space_link(tiddler)
        else:
            space_link = ''
        try:
            modifier_link = space_uri(self.environ, tiddler.modifier)
        except AttributeError:
            modifier_link = ""
        try:
            creator_link = space_uri(self.environ, tiddler.creator)
        except AttributeError:
            creator_link = ""

        html = render_wikitext(tiddler, self.environ)
        return send_template(self.environ, 'tiddler.html', {
            'meta_keywords': ', '.join(tiddler.tags),
            'meta_description': tiddler.title,
            'title': '%s' % tiddler.title,
            'tags': tiddler.tags,
            'modifier_link': modifier_link,
            'creator_link': creator_link,
            'fields': tiddler.fields,
            'html': html,
            'list_link': list_link,
            'list_title': list_title,
            'space_link': space_link,
            'tiddler': tiddler,
            'container_policy': container_policy,
            'tiddler_url': tiddler_url(self.environ, tiddler)})
Exemplo n.º 16
0
def page(environ, start_response):
    """
    Display a page created from the tiddler named in the URL.
    If the tiddler title is in SPECIAL_PAGES, run the special
    page handling code. Otherwise, render the tiddler to html
    and provide it to the page.html template.
    """
    tiddler = _determine_tiddler(environ)

    if tiddler.title in SPECIAL_PAGES:
        return SPECIAL_PAGES[tiddler.title](tiddler, environ)

    template = get_template(environ, "page.html")
    environ["tiddlyweb.title"] = tiddler.title
    return template.generate(html=render_wikitext(tiddler, environ), tiddler=tiddler)
Exemplo n.º 17
0
def frontpage(environ, start_response):
    username = environ['tiddlyweb.usersign']['name']

    tiddler = Tiddler('index', 'meta')
    store = environ['tiddlyweb.store']
    try:
        tiddler = store.get(tiddler)
    except NoTiddlerError: # this should never occur
        pass

    uris = None if username != 'GUEST' else {
        'register': uri('register', environ),
        'login': uri('login', environ)
    }
    return _render_template(environ, start_response, 'frontpage.html',
            contents=render_wikitext(tiddler, environ),
            nav=nav('front page', environ), uris=uris)
Exemplo n.º 18
0
 def tiddler_as(self, tiddler):
     """
     Transform the provided tiddler into an HTML
     representation of the tiddler packaged in a
     DIV. Render the content using the render_wikitext
     subsystem.
     """
     if tiddler.recipe:
         list_link = 'recipes/%s/tiddlers' % encode_name(tiddler.recipe)
         list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
     else:
         list_link = 'bags/%s/tiddlers' % encode_name(tiddler.bag)
         list_title = 'Tiddlers in Bag %s' % tiddler.bag
     list_html = ('<div class="tiddlerslink"><a href="%s/%s" ' %
             (self._server_prefix(), list_link) +
             'title="tiddler list">%s</a></div>' % list_title)
     html = render_wikitext(tiddler, self.environ)
     self.environ['tiddlyweb.title'] = tiddler.title
     return list_html + self._tiddler_div(tiddler) + html + '</div>'
Exemplo n.º 19
0
def wiki_page(environ, start_response):
    wiki_name, bag = _ensure_wiki_readable(environ)

    page_name = get_route_value(environ, 'page_name')
    tiddler = Tiddler(page_name, bag.name)
    try:
        tiddler = bag.store.get(tiddler)
    except NoTiddlerError:
        raise HTTP302(_uri(environ, 'editor',
                page='%s/%s' % (wiki_name, page_name)))

    title = wiki_name if page_name == 'index' else page_name # XXX: undesirable?
    uris = {
        'edit': _uri(environ, 'editor', page='%s/%s' % (wiki_name, page_name)),
        'source': _uri(environ, 'bags', wiki_name, 'tiddlers', page_name)
    }
    return _render_template(environ, start_response, 'wiki_page.html',
            title=title, page_title=page_name, uris=uris,
            contents=render_wikitext(tiddler, environ))
Exemplo n.º 20
0
 def tiddler_as(self, tiddler):
     """
     Transform the provided tiddler into an HTML
     representation of the tiddler packaged in a
     DIV. Render the content using the render_wikitext
     subsystem.
     """
     if tiddler.recipe:
         list_link = 'recipes/%s/tiddlers' % encode_name(tiddler.recipe)
         list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
     else:
         list_link = 'bags/%s/tiddlers' % encode_name(tiddler.bag)
         list_title = 'Tiddlers in Bag %s' % tiddler.bag
     list_html = ('<div class="tiddlerslink"><a href="%s/%s" ' %
                  (self._server_prefix(), list_link) +
                  'title="tiddler list">%s</a></div>' % list_title)
     html = render_wikitext(tiddler, self.environ)
     self.environ['tiddlyweb.title'] = tiddler.title
     return list_html + self._tiddler_div(tiddler) + html + '</div>'
Exemplo n.º 21
0
def frontpage(environ, start_response):
    current_user = environ['tiddlyweb.usersign']['name']

    if current_user != 'GUEST': # auth'd
        raise HTTP302(_uri(environ, '~'))
    else: # unauth'd
        uris = {
            'register': _uri(environ, 'register'),
            'login': _uri(environ, 'challenge', 'cookie_form')
        }

        tiddler = Tiddler('index', 'meta')
        store = environ['tiddlyweb.store']
        try:
            tiddler = store.get(tiddler)
        except NoTiddlerError: # this should never occur
            pass

        return _render_template(environ, start_response, 'frontpage.html',
                contents=render_wikitext(tiddler, environ), uris=uris)
Exemplo n.º 22
0
 def tiddler_as(self, tiddler):
     """
     Transform the provided :py:class:`tiddler
     <tiddlyweb.model.tiddler.Tiddler>` into an HTML representation.
     :py:mod:`Render <tiddlyweb.wikitext>` the ``text`` of the tiddler
     if its ``type`` is configured.
     """
     if tiddler.recipe:
         list_link = 'recipes/%s/tiddlers' % encode_name(tiddler.recipe)
         list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
     else:
         list_link = 'bags/%s/tiddlers' % encode_name(tiddler.bag)
         list_title = 'Tiddlers in Bag %s' % tiddler.bag
     list_html = ('<div class="tiddlerslink"><a href="%s/%s" ' %
                  (self._server_prefix(), list_link) +
                  'title="tiddler list">%s</a></div>' % list_title)
     html = render_wikitext(tiddler, self.environ)
     self.environ['tiddlyweb.title'] = tiddler.title
     return (self._header() + list_html + self._tiddler_div(tiddler) +
             html + '</div>' + self._footer())
Exemplo n.º 23
0
 def tiddler_as(self, tiddler):
     """
     Transform the provided :py:class:`tiddler
     <tiddlyweb.model.tiddler.Tiddler>` into an HTML representation.
     :py:mod:`Render <tiddlyweb.wikitext>` the ``text`` of the tiddler
     if its ``type`` is configured.
     """
     if tiddler.recipe:
         list_link = 'recipes/%s/tiddlers' % encode_name(tiddler.recipe)
         list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
     else:
         list_link = 'bags/%s/tiddlers' % encode_name(tiddler.bag)
         list_title = 'Tiddlers in Bag %s' % tiddler.bag
     list_html = ('<div class="tiddlerslink"><a href="%s/%s" ' %
             (self._server_prefix(), list_link) +
             'title="tiddler list">%s</a></div>' % list_title)
     html = render_wikitext(tiddler, self.environ)
     self.environ['tiddlyweb.title'] = tiddler.title
     return (self._header() + list_html + self._tiddler_div(tiddler)
             + html + '</div>' + self._footer())
    def transcluder(self, match):
        if 'markdown.transclusions' in self.environ:
            seen_titles = self.environ['markdown.transclusions']
        else:
            seen_titles = []

        interior_title = match.group(1)
        try:
            target = match.group(2) or match.group(3)
        except IndexError:
            target = None

        # bail out if we have no store
        if not self.store:
            return match.group(0)

        try:
            interior_tiddler = self.resolve_tiddler(target, interior_title)
            interior_tiddler = self.store.get(interior_tiddler)
        except (StoreError, KeyError, PermissionsError):
            return match.group(0)

        semaphore_title = '%s:%s' % (interior_tiddler.bag,
                interior_tiddler.title)

        if semaphore_title not in seen_titles:
            seen_titles.append(semaphore_title)
            self.environ['markdown.transclusions'] = seen_titles
            if renderable(interior_tiddler, self.environ):
                content = render_wikitext(interior_tiddler, self.environ)
            else:
                content = ''
            seen_titles.pop()
            return '<article id="%s" class="transclusion" data-uri="%s" ' \
                    'data-title="%s" data-bag="%s">%s</article>' % (
                            self._make_id(interior_tiddler),
                            self.interior_url(interior_tiddler),
                            interior_tiddler.title,
                            interior_tiddler.bag, content)
        else:
            return match.group(0)
Exemplo n.º 25
0
def gym_info(environ, start_response):
    """
    Display the info about a single gym for the public.
    """
    store = environ['tiddlyweb.store']
    gym = get_route_value(environ, 'gym')
    news_tiddlers = []
    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)
Exemplo n.º 26
0
    def _add_tiddler_to_feed(self, feed, tiddler):
        if tiddler.recipe:
            tiddler_link = 'recipes/%s/tiddlers' % tiddler.recipe
            link = u'%s/recipes/%s/tiddlers/%s' % \
                    (self._server_url(), iri_to_uri(tiddler.recipe), iri_to_uri(tiddler.title))
        else:
            tiddler_link = 'bags/%s/tiddlers' % tiddler.bag
            link = u'%s/bags/%s/tiddlers/%s' % \
                    (self._server_url(), iri_to_uri(tiddler.bag), iri_to_uri(tiddler.title))
 
        if tiddler.type and tiddler.type != 'None':
            description = 'Binary Content'
        else:
            description = render_wikitext(tiddler, self.environ)
 
        feed.add_item(title=tiddler.title,
                link=link,
                description=description,
                author_name=tiddler.modifier,
                pubdate=self._tiddler_datetime(tiddler.modified)
                )
Exemplo n.º 27
0
 def _tiddler_dict(self, tiddler, fat=False, render=False):
     """
     Select fields from a tiddler to create
     a dictonary.
     """
     unwanted_keys = ['text', 'store']
     wanted_keys = [attribute for attribute in tiddler.slots if
             attribute not in unwanted_keys]
     wanted_info = {}
     for attribute in wanted_keys:
         wanted_info[attribute] = getattr(tiddler, attribute, None)
     wanted_info['permissions'] = self._tiddler_permissions(tiddler)
     if fat:
         if binary_tiddler(tiddler):
             wanted_info['text'] = b64encode(tiddler.text)
         else:
             wanted_info['text'] = tiddler.text
             if render and renderable(tiddler, self.environ):
                 wanted_info['render'] = render_wikitext(tiddler,
                         self.environ)
     return wanted_info
Exemplo n.º 28
0
	def _no_script(self, url):
		"""
		returns static HTML representation of a list of tiddlers
		"""
		try:
			static_index = self.environ["tiddlyweb.config"]["static_index"]
		except KeyError: # default
			static_index = default_static_index

		store = self.environ["tiddlyweb.store"]
		routing_args = self.environ["wsgiorg.routing_args"][1]

		try: # recipe
			recipe = routing_args["recipe_name"]
			recipe = Recipe(recipe)
			recipe = store.get(recipe)
			tiddlers = control.get_tiddlers_from_recipe(recipe, self.environ)
		except KeyError: # bag
			bag = routing_args["bag_name"]
			bag = Bag(bag)
			bag = store.get(bag)
			tiddlers = control.get_tiddlers_from_bag(bag)
		tiddlers = dict([(tiddler.title, tiddler) for tiddler in tiddlers])

		static_tiddlers = []
		try:
			index_tiddler = tiddlers[static_index]
			for title in _read_bracketed_list(index_tiddler.text):
				tiddler = tiddlers.get(title)
				try:
					text = render_wikitext(tiddler, self.environ)
					static_tiddlers.append(tiddler_template %
						(tiddler.title, text))
				except AttributeError: # tiddler does not exist
					pass
		except KeyError: # static_index tiddler does not exist
			pass

		intro = super(Serialization, self)._no_script(url)
		return "%s\n%s" % (intro, "\n".join(static_tiddlers))
Exemplo n.º 29
0
def wiki_page(environ, start_response):
    wiki_name, bag = _ensure_wiki_readable(environ)

    page_name = get_route_value(environ, 'page_name')
    tiddler = Tiddler(page_name, bag.name)
    try:
        tiddler = bag.store.get(tiddler)
    except NoTiddlerError:
        raise HTTP302(uri('page editor', environ, wiki=wiki_name,
                page=page_name))

    title = wiki_name if page_name == 'index' else page_name # XXX: undesirable?
    tags = [(tag, uri('tag', environ, tag=tag)) for tag in sorted(tiddler.tags)]
    uris = {
        'edit': uri('page editor', environ, wiki=wiki_name, page=page_name),
        'source': uri('tiddler', environ, bag=wiki_name, title=page_name)
    }

    return _render_template(environ, start_response, 'wiki_page.html',
            title=title, page_title=page_name, uris=uris, tags=tags,
            nav=nav('wiki page', environ, wiki=wiki_name, page=page_name),
            contents=render_wikitext(tiddler, environ))
Exemplo n.º 30
0
    def _add_tiddler_to_feed(self, feed, tiddler,view_template=False):
        if tiddler.recipe:
            tiddler_link = 'recipes/%s/tiddlers/' % iri_to_uri(tiddler.recipe)
            bagobject = control.determine_tiddler_bag_from_recipe(self.store.get(Recipe(tiddler.recipe)), tiddler)
            bag = bagobject.name
        else:
            tiddler_link = 'bags/%s/tiddlers/%s' % iri_to_uri(tiddler.bag)
            bag = tiddler.bag
        tiddler_link +=iri_to_uri(urllib.quote(tiddler.title.encode('utf-8'), safe=''))
        item_title = tiddler.title
        if view_template:
          if bag in view_template:
            if "link" in view_template[bag]:
              tiddler_link = wikitext_to_wikklyhtml("/", "/", view_template[bag]["link"], self.environ,tiddler=tiddler)
              #tiddler_link = render_wikitext(view_template[bag]["link"],self.environ)
            if "title" in view_template[bag]:
              item_title = wikitext_to_wikklyhtml("/", "/", view_template[bag]["title"], self.environ,tiddler=tiddler)
        link = u'%s/%s' % \
                (self._server_url(), tiddler_link)

              
        if tiddler.type and tiddler.type != 'None':
            description = 'Binary Content'
        else:
            description = render_wikitext(tiddler, self.environ)

        
        
        feed.add_item(title=item_title,
                unique_id=self._tiddler_id(tiddler),
                link=link,
                categories=tiddler.tags,
                description=description,
                author_name=tiddler.modifier,
                pubdate=self._tiddler_datetime(tiddler.modified)
                )
Exemplo n.º 31
0
def wiki_page(environ, start_response):
    """
    Present a single tiddler from a given tank.
    """
    tank_name = get_route_value(environ, 'bag_name')
    store = environ['tiddlyweb.store']
    usersign = environ['tiddlyweb.usersign']
    config = environ['tiddlyweb.config']

    try:
        bag = store.get(Bag(tank_name))
        bag = augment_bag(store, bag)
    except NoBagError:
        raise HTTP404('no tank found for %s' % tank_name)

    try:
        tiddler_name = get_route_value(environ, 'tiddler_name')
    except (KeyError, AttributeError):
        raise HTTP302(tank_page_uri(environ, tank_name, INDEX_PAGE))

    if tiddler_name in SPECIAL_PAGES:
        return SPECIAL_PAGES[tiddler_name](environ, start_response)

    # let permissions problems raise
    bag.policy.allows(usersign, 'read')

    editable = True
    creatable = True
    deletable = True
    try:
        bag.policy.allows(usersign, 'write')
    except PermissionsError:
        editable = False
    try:
        bag.policy.allows(usersign, 'create')
    except PermissionsError:
        creatable = False
    try:
        bag.policy.allows(usersign, 'delete')
    except PermissionsError:
        deletable = False

    try:
        tiddler = Tiddler(tiddler_name, tank_name)
        tiddler = store.get(tiddler)
    except NoTiddlerError:
        tiddler.type = 'text/x-markdown'
        tiddler.text = '### This tiddler does not yet exist\n'
        if creatable:
            editable = True
        else:
            editable = False
        deletable = False
        if tiddler.title != INDEX_PAGE:
            sisterlinks = get_sisterlinks(environ, tiddler)
            tiddler.text = (tiddler.text +
                            '\n### Other tiddlers with similar names\n' +
                            ''.join([
                                '* [[%s]]@[[%s]] @%s\n' %
                                (stiddler.title, stiddler.bag, stiddler.bag)
                                for stiddler in sisterlinks
                            ]))

    if renderable(tiddler, environ):
        backlinks = get_backlinks(environ, tiddler)
        rellinks = get_rellinks(environ, tiddler)
        compable = full_search(config, 'id:"%s:app"' % tank_name)
        html = render_wikitext(tiddler, environ)
        start_response('200 OK', [('Content-Type', 'text/html; charset=UTF-8'),
                                  ('Cache-Control', 'no-cache')])
        return send_template(
            environ, WIKI_TEMPLATE, {
                'tiddler': tiddler,
                'html': html,
                'bag': bag,
                'backlinks': backlinks,
                'create': creatable,
                'edit': editable,
                'delete': deletable,
                'compable': compable,
                'links': rellinks,
            })
    else:
        return tiddler_get(environ, start_response)
Exemplo n.º 32
0
def test_render_no_config():
    text = render_wikitext(tiddler)
    assert '<pre>' in text
    assert '!Hello' in text
def _process_for_transclusion(output, tiddler, environ):
    """
    Process the output for transclusions.
    """
    if 'twikified.seen_titles' in environ:
        seen_titles = environ['twikified.seen_titles']
    else:
        seen_titles = []

    parser = html5lib.HTMLParser(
        tree=html5lib.treebuilders.getTreeBuilder("dom"))

    output = output.decode('utf-8', 'replace')
    try:
        dom = parser.parse('<div>' + output + '</div>')
        spans = dom.getElementsByTagName('span')
        for span in spans:
            for attribute in span.attributes.keys():
                if attribute == 'tiddler':
                    attr = span.attributes[attribute]
                    interior_title = attr.value
                    try:
                        span_class = span.attributes['class'].value
                        if span_class.startswith('@'):
                            interior_recipe = span_class[1:] + '_public'
                        else:
                            interior_recipe = ''
                    except KeyError:
                        interior_recipe = ''
                    title_semaphore = '%s:%s' % (interior_title,
                                                 interior_recipe)
                    if title_semaphore not in seen_titles:
                        seen_titles.append(title_semaphore)
                        interior_tiddler = Tiddler(interior_title)
                        try:
                            store = environ['tiddlyweb.store']
                            if interior_recipe:
                                recipe = store.get(Recipe(interior_recipe))
                                interior_tiddler.recipe = interior_recipe
                                interior_tiddler.bag = (
                                    determine_bag_from_recipe(
                                        recipe, interior_tiddler,
                                        environ).name)
                            else:
                                if tiddler.recipe:
                                    interior_tiddler.recipe = tiddler.recipe
                                    recipe = store.get(Recipe(tiddler.recipe))
                                    interior_tiddler.bag = (
                                        determine_bag_from_recipe(
                                            recipe, interior_tiddler,
                                            environ).name)
                                else:
                                    interior_tiddler.bag = tiddler.bag
                            interior_bag = store.get(Bag(interior_tiddler.bag))
                            interior_bag.policy.allows(
                                environ['tiddlyweb.usersign'], 'read')
                            interior_tiddler = store.get(interior_tiddler)
                        except (StoreError, PermissionsError):
                            continue
                        if renderable(interior_tiddler, environ):
                            environ['twikified.seen_titles'] = seen_titles
                            interior_content = render_wikitext(
                                interior_tiddler, environ)
                            interior_dom = parser.parse('<div>' +
                                                        interior_content
                                                        + '</div>')
                            span.appendChild(
                                interior_dom.getElementsByTagName(
                                    'div')[0])

        output = dom.getElementsByTagName('div')[0].toxml()
    except ExpatError, exc:
        # If expat couldn't process the output, we need to make it
        # unicode as what came over the socket was utf-8 but expat
        # needs that in the first place.
        LOGGER.warn('got expat error: %s:%s %s',
                    tiddler.bag, tiddler.title, exc)
        output = output.decode('utf-8', 'replace')
Exemplo n.º 34
0
def test_renderer_not_found():
    renderer = config['wikitext.default_renderer']
    config['wikitext.default_renderer'] = 'monkey'
    with py.test.raises(ImportError):
        render_wikitext(tiddler, {"tiddlyweb.config":config})
    config['wikitext.default_renderer'] = renderer
Exemplo n.º 35
0
def test_renderer_type_not_found_does_raw():
    tiddler.type = 'fake/type'
    text = render_wikitext(tiddler)
    assert '!Hello' in text
Exemplo n.º 36
0
    # creating links.
    return text2html(tiddler.text)


def init(config_in):
    config['wikitext.type_render_map']['text/x-creole'] = 'creolerender'


if __name__ == '__main__':
    from tiddlyweb.model.tiddler import Tiddler
    tiddler = Tiddler('foo')
    tiddler.text = '==Hello==\n[[Hello]]'

    print render_wikitext(
        tiddler, '', {
            'tiddlyweb.config': {
                'wikitext.type_render_map': {
                    'text/x-creole': 'creolerender'
                }
            }
        })
    tiddler.type = 'text/x-creole'
    print render_wikitext(
        tiddler, '', {
            'tiddlyweb.config': {
                'wikitext.type_render_map': {
                    'text/x-creole': 'creolerender'
                }
            }
        })
Exemplo n.º 37
0
def test_render_no_config():
    text = render_wikitext(tiddler)
    assert '<pre>' in text
    assert '!Hello' in text
Exemplo n.º 38
0
    # Confirm username is a real User
    try:
        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,
Exemplo n.º 39
0
def wiki_page(environ, start_response):
    """
    Present a single tiddler from a given tank.
    """
    tank_name = get_route_value(environ, "bag_name")
    store = environ["tiddlyweb.store"]
    usersign = environ["tiddlyweb.usersign"]
    config = environ["tiddlyweb.config"]

    try:
        bag = store.get(Bag(tank_name))
        bag = augment_bag(store, bag)
    except NoBagError:
        raise HTTP404("no tank found for %s" % tank_name)

    try:
        tiddler_name = get_route_value(environ, "tiddler_name")
    except (KeyError, AttributeError):
        raise HTTP302(tank_page_uri(environ, tank_name, INDEX_PAGE))

    if tiddler_name in SPECIAL_PAGES:
        return SPECIAL_PAGES[tiddler_name](environ, start_response)

    # let permissions problems raise
    bag.policy.allows(usersign, "read")

    editable = True
    creatable = True
    deletable = True
    try:
        bag.policy.allows(usersign, "write")
    except PermissionsError:
        editable = False
    try:
        bag.policy.allows(usersign, "create")
    except PermissionsError:
        creatable = False
    try:
        bag.policy.allows(usersign, "delete")
    except PermissionsError:
        deletable = False

    try:
        tiddler = Tiddler(tiddler_name, tank_name)
        tiddler = store.get(tiddler)
    except NoTiddlerError:
        tiddler.type = "text/x-markdown"
        tiddler.text = "### This tiddler does not yet exist\n"
        if creatable:
            editable = True
        else:
            editable = False
        deletable = False
        if tiddler.title != INDEX_PAGE:
            sisterlinks = get_sisterlinks(environ, tiddler)
            tiddler.text = (
                tiddler.text
                + "\n### Other tiddlers with similar names\n"
                + "".join(
                    ["* [[%s]]@[[%s]] @%s\n" % (stiddler.title, stiddler.bag, stiddler.bag) for stiddler in sisterlinks]
                )
            )

    if renderable(tiddler, environ):
        backlinks = get_backlinks(environ, tiddler)
        rellinks = get_rellinks(environ, tiddler)
        compable = full_search(config, 'id:"%s:app"' % tank_name)
        html = render_wikitext(tiddler, environ)
        start_response("200 OK", [("Content-Type", "text/html; charset=UTF-8"), ("Cache-Control", "no-cache")])
        return send_template(
            environ,
            WIKI_TEMPLATE,
            {
                "tiddler": tiddler,
                "html": html,
                "bag": bag,
                "backlinks": backlinks,
                "create": creatable,
                "edit": editable,
                "delete": deletable,
                "compable": compable,
                "links": rellinks,
            },
        )
    else:
        return tiddler_get(environ, start_response)
Exemplo n.º 40
0
def _process_for_transclusion(output, tiddler, environ):
    """
    Process the output for transclusions.
    """
    if 'twikified.seen_titles' in environ:
        seen_titles = environ['twikified.seen_titles']
    else:
        seen_titles = []

    parser = html5lib.HTMLParser(
        tree=html5lib.treebuilders.getTreeBuilder("dom"))

    output = output.decode('utf-8', 'replace')
    try:
        dom = parser.parse('<div>' + output + '</div>')
        spans = dom.getElementsByTagName('span')
        for span in spans:
            for attribute in span.attributes.keys():
                if attribute == 'tiddler':
                    attr = span.attributes[attribute]
                    interior_title = attr.value
                    try:
                        span_class = span.attributes['class'].value
                        if span_class.startswith('@'):
                            interior_recipe = span_class[1:] + '_public'
                        else:
                            interior_recipe = ''
                    except KeyError:
                        interior_recipe = ''
                    title_semaphore = '%s:%s' % (interior_title,
                                                 interior_recipe)
                    if title_semaphore not in seen_titles:
                        seen_titles.append(title_semaphore)
                        interior_tiddler = Tiddler(interior_title)
                        try:
                            store = environ['tiddlyweb.store']
                            if interior_recipe:
                                recipe = store.get(Recipe(interior_recipe))
                                interior_tiddler.recipe = interior_recipe
                                interior_tiddler.bag = (
                                    determine_bag_from_recipe(
                                        recipe, interior_tiddler,
                                        environ).name)
                            else:
                                if tiddler.recipe:
                                    interior_tiddler.recipe = tiddler.recipe
                                    recipe = store.get(Recipe(tiddler.recipe))
                                    interior_tiddler.bag = (
                                        determine_bag_from_recipe(
                                            recipe, interior_tiddler,
                                            environ).name)
                                else:
                                    interior_tiddler.bag = tiddler.bag
                            interior_bag = store.get(Bag(interior_tiddler.bag))
                            interior_bag.policy.allows(
                                environ['tiddlyweb.usersign'], 'read')
                            interior_tiddler = store.get(interior_tiddler)
                        except (StoreError, PermissionsError):
                            continue
                        if renderable(interior_tiddler, environ):
                            environ['twikified.seen_titles'] = seen_titles
                            interior_content = render_wikitext(
                                interior_tiddler, environ)
                            interior_dom = parser.parse('<div>' +
                                                        interior_content +
                                                        '</div>')
                            span.appendChild(
                                interior_dom.getElementsByTagName('div')[0])

        output = dom.getElementsByTagName('div')[0].toxml()
    except ExpatError, exc:
        # If expat couldn't process the output, we need to make it
        # unicode as what came over the socket was utf-8 but expat
        # needs that in the first place.
        LOGGER.warn('got expat error: %s:%s %s', tiddler.bag, tiddler.title,
                    exc)
        output = output.decode('utf-8', 'replace')
Exemplo n.º 41
0
    tiddler = Tiddler('manifesto', manifesto_bag)
    try:
        tiddler = store.get(tiddler)
    except NoTiddlerError:
        pass

    dictionary_bag = None
    for bag, filter in recipe.get_recipe():
        if bag.endswith('-dictionary'):
            dictionary_bag = bag
            break

    environ['tiddlyweb.manifesto'] = manifesto
    environ['tiddlyweb.dictionary'] = dictionary_bag
    output = render_wikitext(tiddler, environ)

    if output == '':
        output = 'Pontificate!'

    template = get_template(environ, 'display.html')
    return template.generate(weAuthed='hi', tiddler='manifesto',
            dictionary=dictionary_bag, bag=manifesto_bag, title=manifesto,
            output=output)


@do_html()
def definition(environ, start_response):
    store = environ['tiddlyweb.store']
    manifesto = get_route_value(environ, 'manifesto_name')
    definition = get_route_value(environ, 'definition')
Exemplo n.º 42
0
Arquivo: wiki.py Projeto: pads/tank
def wiki_page(environ, start_response):
    """
    Present a single tiddler from a given tank.
    """
    tank_name = get_route_value(environ, 'bag_name')
    store = environ['tiddlyweb.store']
    usersign = environ['tiddlyweb.usersign']
    config = environ['tiddlyweb.config']

    try:
        bag = store.get(Bag(tank_name))
    except NoBagError:
        raise HTTP404('no tank found for %s' % tank_name)

    try:
        tiddler_name = get_route_value(environ, 'tiddler_name')
    except (KeyError, AttributeError):
        raise HTTP302(tank_page_uri(environ, tank_name, 'index'))

    if tiddler_name in SPECIAL_PAGES:
        return SPECIAL_PAGES[tiddler_name](environ, start_response)

    # let permissions problems raise
    bag.policy.allows(usersign, 'read')

    editable = True
    creatable = True
    deletable = True
    try:
        bag.policy.allows(usersign, 'write')
    except PermissionsError:
        editable = False
    try:
        bag.policy.allows(usersign, 'create')
    except PermissionsError:
        creatable = False
    try:
        bag.policy.allows(usersign, 'delete')
    except PermissionsError:
        deletable = False

    try:
        tiddler = Tiddler(tiddler_name, tank_name)
        tiddler = store.get(tiddler)
    except NoTiddlerError:
        tiddler.type = 'text/x-markdown'
        tiddler.text = '### This tiddler does not yet exist\n'
        if creatable:
            editable = True
        deletable = False

    if renderable(tiddler, environ):
        backlinks = get_backlinks(environ, tiddler)
        compable = full_search(config, 'id:"%s:app"' % tank_name)
        html = render_wikitext(tiddler, environ)
        wiki_template = get_template(environ, WIKI_TEMPLATE)
        start_response('200 OK', [
            ('Content-Type', 'text/html; charset=UTF-8'),
            ('Cache-Control', 'no-cache')])
        return wiki_template.generate({
            'socket_link': config.get('socket.link'),
            'csrf_token': get_nonce(environ),
            'gravatar': gravatar(environ),
            'user': usersign['name'],
            'tiddler': tiddler,
            'html': html,
            'bag': bag,
            'backlinks': backlinks,
            'edit': editable,
            'delete': deletable,
            'compable': compable,
        })
    else:
        return tiddler_get(environ, start_response)
Exemplo n.º 43
0
    # Confirm username is a real User
    try:
        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,
Exemplo n.º 44
0
def test_renderer_type_found_no_import():
    tiddler.type = 'image/gif'
    config['wikitext.type_render_map'][tiddler.type] = 'monkey'
    with py.test.raises(ImportError):
        render_wikitext(tiddler, {"tiddlyweb.config":config})
Exemplo n.º 45
0
    def tiddler_as(self, tiddler):
        """
        Transform the provided tiddler into an HTML
        representation of the tiddler packaged in a
        DIV. Render the content using the render_wikitext
        subsystem. Links to the tiddler in the wiki are
        provided.
        """
        tiddlers_url = (self.environ.get('SCRIPT_NAME', '')
                + self.environ.get('PATH_INFO', ''))

        template_name = 'friendlytiddler.html'
        if '/tiddlers/' in tiddlers_url:
            template_name = 'tiddler.html'

        revision = False
        if '/revisions/' in tiddlers_url:
            revision = True

        user = self.environ['tiddlyweb.usersign']
        store = self.environ['tiddlyweb.store']
        if tiddler.recipe:
            list_link = '/recipes/%s/tiddlers' % encode_name(tiddler.recipe)
            list_title = 'Tiddlers in Recipe %s' % tiddler.recipe
        else:
            list_link = '/bags/%s/tiddlers' % encode_name(tiddler.bag)
            list_title = 'Tiddlers in Bag %s' % tiddler.bag
        tiddlerurl = tiddler_url(self.environ, tiddler)
        if revision:
            list_link = '%s/%s/revisions' % (list_link,
                    encode_name(tiddler.title))
            list_title = 'Revisions of %s' % tiddler.title
            tiddlerurl = '%s/revisions/%s' % (tiddlerurl,
                    encode_name('%s' % tiddler.revision))
        try:
            store.get(Bag(tiddler.bag)).policy.allows(user, 'manage')
            container_policy = True
        except PermissionsError:
            container_policy = False
        if not self.environ['tiddlyweb.space_settings'].get('index', None):
            space_link, space_name = self._space_link(tiddler)
        else:
            space_link = ''
            space_name = ''
        try:
            modifier_link = space_uri(self.environ, tiddler.modifier)
        except AttributeError:
            modifier_link = ""
        try:
            creator_link = space_uri(self.environ, tiddler.creator)
        except AttributeError:
            creator_link = ""

        links = self.environ.get('tiddlyweb.config',
                {}).get('extension_types', {}).keys()

        html = render_wikitext(tiddler, self.environ)
        return send_template(self.environ, template_name, {
            'meta_keywords': ', '.join(tiddler.tags),
            'meta_description': tiddler.title,
            'title': '%s' % tiddler.title,
            'tags': tiddler.tags,
            'modifier_link': modifier_link,
            'creator_link': creator_link,
            'fields': tiddler.fields,
            'html': html,
            'list_link': list_link,
            'list_title': list_title,
            'space_link': space_link,
            'space_name': space_name,
            'tiddler': tiddler,
            'container_policy': container_policy,
            'links': links,
            'tiddler_url': tiddlerurl})
Exemplo n.º 46
0
def test_renderer_type_not_found_does_raw():
    tiddler.type = 'fake/type'
    text = render_wikitext(tiddler)
    assert '!Hello' in text