Example #1
0
def submit(environ, start_response):
    """
    Take POSTed input, put it in a Tiddler and save
    it into the store, and redirect back to the user
    page.
    """
    user = environ['tiddlyweb.usersign']['name']
    if user == 'GUEST':
        raise UserRequiredError, 'real user required to twote'

    recent_recipe = _check_recipe('recent', environ, user)
    all_recipe = _check_recipe('all', environ, user)

    tiddler = _make_tiddler(environ, user)

    bag = control.determine_bag_for_tiddler(all_recipe, tiddler)
    tiddler.bag = bag.name

    store = environ['tiddlyweb.store']

    original_title = tiddler.title
    tester_tiddler = Tiddler(original_title, bag=bag.name)
    addendum = 2
    while 1:
        try:
            tester_tiddler = store.get(tester_tiddler)
            new_title = '%s-%s' % (original_title, addendum)
            tiddler.title = new_title
            tester_tiddler.title = new_title
            addendum += 1
        except NoTiddlerError:
            store.put(tiddler)
            break

    raise HTTP302, '%s/twoter/%s' % (server_base_url(environ), urllib.quote(user))
Example #2
0
def edit(environ, start_response):
    """
    Save POSTed text to the named page/tiddler. If there
    are insufficient permissions to write to the destination,
    send the edit form with a warning message. Otherwise redirect
    to the display page of the named page.
    """
    user = environ['tiddlyweb.usersign']
    tiddler = _determine_tiddler(environ)
    tiddler.text = environ['tiddlyweb.query']['text'][0]
    store = environ['tiddlyweb.store']
    config = environ['tiddlyweb.config']

    # if _determine_tiddler loaded the tiddler from the store
    # then bag will be set and we know that the tiddler is not new
    tiddler_new = True
    if tiddler.bag:
        tiddler_new = False

    try:
        recipe = _get_recipe(config)
        recipe = store.get(Recipe(recipe))
        bag = control.determine_bag_for_tiddler(recipe, tiddler, environ)
        tiddler.bag = bag.name
    except NoBagError, exc:
        raise HTTP404('No suitable bag to store tiddler %s found, %s' % (tiddler.title, exc))
Example #3
0
def submit(environ, start_response):
    """
    Take POSTed input, put it in a Tiddler and save
    it into the store, and redirect back to the user
    page.
    """
    user = environ['tiddlyweb.usersign']['name']
    if user == 'GUEST':
        raise UserRequiredError, 'real user required to twote'

    recent_recipe = _check_recipe('recent', environ, user)
    all_recipe = _check_recipe('all', environ, user)

    tiddler = _make_tiddler(environ, user)

    bag = control.determine_bag_for_tiddler(all_recipe, tiddler)
    tiddler.bag = bag.name

    store = environ['tiddlyweb.store']

    original_title = tiddler.title
    tester_tiddler = Tiddler(original_title, bag=bag.name)
    addendum = 2
    while 1:
        try:
            tester_tiddler = store.get(tester_tiddler)
            new_title = '%s-%s' % (original_title, addendum)
            tiddler.title = new_title
            tester_tiddler.title = new_title
            addendum += 1
        except NoTiddlerError:
            store.put(tiddler)
            break

    raise HTTP302, '%s/twoter/%s' % (server_base_url(environ), urllib.quote(user))
Example #4
0
def test_determine_bag_for_tiddler():
    recipe = Recipe('example')
    recipe.set_recipe([('bagone', ''), ('bagtwo', 'select=title:monkey')])

    tiddler = Tiddler('happy')

    bag = determine_bag_for_tiddler(recipe, tiddler)
    assert bag.name == 'bagone'

    tiddler = Tiddler('monkey')
    bag = determine_bag_for_tiddler(recipe, tiddler)
    assert bag.name == 'bagtwo'

    recipe.set_recipe([('bagone', 'select=tag:foo'),
                       ('bagtwo', 'select=title:monkeys')])

    py.test.raises(NoBagError, 'determine_bag_for_tiddler(recipe, tiddler)')
Example #5
0
def test_determine_bag_filtered():
    """
    Work out which bag a tiddler should go to when no bag provided.
    """
    short_recipe = Recipe(name='foobar')
    short_recipe.set_recipe([
        [bagone, ''],
        [bagfour, 'select=tag:tagone']
        ])
    bag = control.determine_bag_for_tiddler(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_bag_for_tiddler(short_recipe, tiddlers[0])
    assert bag.name == bagone.name, 'bag name should be bagone, is %s' % bag.name
Example #6
0
def test_determine_bag_simple():
    """
    Given a tiddler, work out which bag in the recipe it should
    drop into. Usually this won't be used: the client will use
    the default bag.

    This means, which bag does the filter match for.
    """
    bag = control.determine_bag_for_tiddler(recipe, tiddlers[0])
    assert bag.name == bagone.name
Example #7
0
def test_determine_bag_for_tiddler():
    recipe = Recipe('example')
    recipe.set_recipe([
        ('bagone', u''),
        ('bagtwo', u'select=title:monkey')])

    tiddler = Tiddler('happy')

    bag = determine_bag_for_tiddler(recipe, tiddler)
    assert bag.name == 'bagone'

    tiddler = Tiddler('monkey')
    bag = determine_bag_for_tiddler(recipe, tiddler)
    assert bag.name == 'bagtwo'

    recipe.set_recipe([
        ('bagone', u'select=tag:foo'),
        ('bagtwo', u'select=title:monkeys')])

    py.test.raises(NoBagError, 'determine_bag_for_tiddler(recipe, tiddler)')
Example #8
0
def test_determine_bag_fail():

    lonely_recipe = Recipe(name='thing')
    lonely_recipe.set_recipe([
        [bagone, 'select=tag:hello']
        ])

    lonely_tiddler = Tiddler('lonely')
    lonely_tiddler.tags = ['hello']
    bag = control.determine_bag_for_tiddler(lonely_recipe, lonely_tiddler)
    assert bag.name == bagone.name

    lonely_recipe.set_recipe([
        [bagone, 'select=tag:goodbye']
        ])
    py.test.raises(NoBagError,
            'bag = control.determine_bag_for_tiddler(lonely_recipe, lonely_tiddler)')
Example #9
0
def test_where_this_tiddler():
    """
    recipe bag determination presumes there is a tiddler of the same name
    already in the bag. Is this right or not? Seems like maybe we want to 
    put the bag in the collection if it matches the filter stream.
    """
    tiddler_lonely = Tiddler('TiddlerOne')
    tiddler_lonely.text = 'tiddlerincookiesyay'

    recipe = Recipe('cookies')
    recipe = store.get(recipe)

    bag = control.determine_bag_for_tiddler(recipe, tiddler_lonely)

    assert bag.name == 'bagone'

    tiddler_lonely.bag = bag.name
    try:
        store.put(tiddler_lonely)
    except NoBagError:
        store.put(bag)
        store.put(tiddler_lonely)

    assert os.path.exists('store/bags/bagone/tiddlers/TiddlerOne')
Example #10
0
def test_where_this_tiddler():
    """
    recipe bag determination presumes there is a tiddler of the same name
    already in the bag. Is this right or not? Seems like maybe we want to
    put the bag in the collection if it matches the filter stream.
    """
    tiddler_lonely = Tiddler('TiddlerOne')
    tiddler_lonely.text = 'tiddlerincookiesyay'

    recipe = Recipe('cookies')
    recipe = store.get(recipe)

    bag = control.determine_bag_for_tiddler(recipe, tiddler_lonely)

    assert bag.name == 'bagone'

    tiddler_lonely.bag = bag.name
    try:
        store.put(tiddler_lonely)
    except NoBagError:
        store.put(bag)
        store.put(tiddler_lonely)

    assert os.path.exists('store/bags/bagone/tiddlers/TiddlerOne')