Exemplo n.º 1
0
def test_determine_tiddler_from_recipe():
    """
    Work out what bag a provided tiddler is in, when we have no knowledge of the bag,
    but we do have a recipe.
    """
    short_recipe = Recipe(name='foobar')
    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagone']
        ])
    bag = control.determine_tiddler_bag_from_recipe(short_recipe, tiddlers[0])
    assert bag.name == bagfour.name, 'bag name should be bagfour, is %s' % bag.name

    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagthree']
        ])
    bag = control.determine_tiddler_bag_from_recipe(short_recipe, tiddlers[0])
    assert bag.name == bagone.name, 'bag name should be bagone, is %s' % bag.name

    lonely_tiddler = Tiddler('lonely')
    lonely_tiddler.bag = 'lonelybag'

    py.test.raises(NoBagError,
            'bag = control.determine_tiddler_bag_from_recipe(short_recipe, lonely_tiddler)')
def get(environ, start_response):
    """
    Using query parameters, determine the current tiddler
    and produce an editor for it.
    """
    usersign = environ['tiddlyweb.usersign']
    try:
        tiddler_name = environ['tiddlyweb.query'].get('tiddler', [''])[0]
        recipe_name = environ['tiddlyweb.query'].get('recipe', [''])[0]
        bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
        #tiddler_name = unicode(urllib.unquote(tiddler_name), 'utf-8')
        #bag_name = unicode(urllib.unquote(bag_name), 'utf-8')
        #recipe_name = unicode(urllib.unquote(recipe_name), 'utf-8')
    except (KeyError, IndexError):
        raise HTTP400('tiddler, recipe and bag query strings required')

    store = environ['tiddlyweb.store']

    tiddler = Tiddler(tiddler_name)
    if bag_name:
        tiddler.bag = bag_name
    else:
        recipe = Recipe(recipe_name)
        try:
            recipe = store.get(recipe)
            tiddler.bag = control.determine_tiddler_bag_from_recipe(recipe, tiddler).name
            tiddler.recipe = recipe.name
        except NoRecipeError, exc:
            raise HTTP404('unable to edit %s, recipe %s not found: %s' % (tiddler.title, recipe_name, exc))
        except NoBagError, exc:
            raise HTTP404('unable to edit %s: %s' % (tiddler.title, exc))
Exemplo n.º 3
0
def get(environ, start_response):
    """
    Using query parameters, determine the current tiddler
    and produce an editor for it.
    """
    usersign = environ['tiddlyweb.usersign']
    try:
        tiddler_name = environ['tiddlyweb.query'].get('tiddler', [''])[0]
        recipe_name = environ['tiddlyweb.query'].get('recipe', [''])[0]
        bag_name = environ['tiddlyweb.query'].get('bag', [''])[0]
    except (KeyError, IndexError):
        raise HTTP400('tiddler, recipe and bag query strings required')

    store = environ['tiddlyweb.store']

    tiddler = Tiddler(tiddler_name)
    if bag_name:
        tiddler.bag = bag_name
    else:
        recipe = Recipe(recipe_name)
        try:
            recipe = store.get(recipe)
            tiddler.bag = control.determine_tiddler_bag_from_recipe(
                recipe, tiddler).name
            tiddler.recipe = recipe.name
        except NoRecipeError, exc:
            raise HTTP404('unable to edit %s, recipe %s not found: %s' %
                          (tiddler.title, recipe_name, exc))
        except NoBagError, exc:
            raise HTTP404('unable to edit %s: %s' % (tiddler.title, exc))
Exemplo n.º 4
0
def get_bag(tiddler_name,environ):
  try:
    bag = environ['selector.vars']['bag_name']
  except KeyError:
    store=environ['tiddlyweb.store']
    recipe_name = environ['selector.vars']['recipe_name']
    try:
      recipe = store.get(Recipe("beefcaked_"+recipe_name))
    except NoRecipeError:
      recipe = store.get(Recipe(recipe_name))
    try:
      bagobj = control.determine_tiddler_bag_from_recipe(recipe, Tiddler(tiddler_name))
      bag = bagobj.name
    except NoBagError:
      bag = ""
  return bag
Exemplo n.º 5
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.º 6
0
def getBeefcakedTiddler(environ,start_response):
    store = environ['tiddlyweb.store']  
     
    start_response('200 OK', [
        ('Content-Type', 'text/html; charset=utf-8')
        ])
    
    tiddler_name = environ['wsgiorg.routing_args'][1]['tiddler']
    tiddler =Tiddler(tiddler_name)
    try:
      initial_recipe_name = environ['wsgiorg.routing_args'][1]['recipe'] 
      recipe_name = "beefcaked_"+initial_recipe_name
      environ['selector.vars']['recipe_name'] = environ['wsgiorg.routing_args'][1]['recipe'] 
      recipe = store.get(Recipe(recipe_name))
      bag = control.determine_tiddler_bag_from_recipe(recipe, Tiddler(tiddler_name))
      bag_name = bag.name
      tiddler.recipe = initial_recipe_name
    except KeyError:
      bag_name = environ['wsgiorg.routing_args'][1]['bag']
      environ['selector.vars']['bag_name'] = bag_name
    tiddler.bag = bag_name
    
    s = Serialization(environ)
    return s.tiddler_as(store.get(tiddler))