Esempio n. 1
0
def _validate_tiddler_content(environ, tiddler):
    """
    Unless tiddler is valid raise a 409 with the reason why
    things to check are presumably tags and title, but we don't
    want to worry about that here, we want to dispatch elsewhere.
    """
    try:
        validate_tiddler(tiddler, environ)
    except InvalidTiddlerError, exc:
        raise HTTP409('Tiddler content is invalid: %s' % exc)
Esempio n. 2
0
def _validate_tiddler_content(environ, tiddler):
    """
    Unless tiddler is valid raise a 409 with the reason why
    things to check are presumably tags and title, but we don't
    want to worry about that here, we want to dispatch elsewhere.
    """
    try:
        validate_tiddler(tiddler, environ)
    except InvalidTiddlerError, exc:
        raise HTTP409('Tiddler content is invalid: %s' % exc)
Esempio n. 3
0
def test_validate_tiddler():
    tiddler = Tiddler('foobar', 'barney')
    tiddler.text = 'I am a dinosaur'
    tiddler.tags = ['tag1', 'tag2']

    py.test.raises(InvalidTiddlerError, 'validate_tiddler(tiddler)')

    tiddler.text = 'I am a dinosaur who likes to foobar'

    validate_tiddler(tiddler)

    assert 'FOOBAR' in tiddler.text
def test_validate_tiddler():
    tiddler = Tiddler('foobar', 'barney')
    tiddler.text = 'I am a dinosaur'
    tiddler.tags = ['tag1', 'tag2']

    py.test.raises(InvalidTiddlerError, 'validate_tiddler(tiddler)')

    tiddler.text = 'I am a dinosaur who likes to foobar'

    validate_tiddler(tiddler)

    assert 'FOOBAR' in tiddler.text
Esempio n. 5
0
def edit(environ, start_response):
    """
    XXX: Lots of duplication from editor.
    """
    store = environ['tiddlyweb.store']
    usersign = environ['tiddlyweb.usersign']
    query = environ['tiddlyweb.query']

    try:
        bag_name = query['bag'][0]
        title = query['title'][0]
        text = query['text'][0]
        tiddler_type = query['type'][0]
        tags = query['tags'][0]
        etag = query['etag'][0]
    except KeyError as exc:
        raise HTTP400('bad query: incomplete form, %s' % exc)

    tags = [tag.strip() for tag in tags.split(',')]

    if not (bag_name and title):
        raise HTTP400('bad query: bag and title required')

    bag = Bag(bag_name)
    try:
        bag = store.get(bag)
    except NoBagError:
        raise HTTP404('that tank does not exist')

    tiddler = Tiddler(title, bag_name)
    tiddler_new = False
    conflict = False
    try:
        tiddler = store.get(tiddler)
        existing_etag = tiddler_etag(environ, tiddler).replace('"',
                '').split(':', 1)[0]
        if etag != existing_etag:
            conflict = True
    except NoTiddlerError:
        tiddler.type = tiddler_type
        tiddler_new = True

    if tiddler_new:
        bag.policy.allows(usersign, 'create')
    else:
        bag.policy.allows(usersign, 'write')

    tiddler.text = text
    tiddler.tags = tags
    tiddler.modifier = usersign['name']
    tiddler.modified = current_timestring()

    if conflict:
        return editor(environ, start_response, tiddler,
                message='conflict')

    try:
        validate_tiddler(tiddler, environ)
    except InvalidTiddlerError as exc:
        return editor(environ, start_response, tiddler,
                message='Tiddler content is invalid: %s' % exc)

    store.put(tiddler)

    redirect_uri = tank_page_uri(environ, tiddler.bag, tiddler.title)

    start_response('303 See Other', [
        ('Location', str(redirect_uri))])

    return []