Ejemplo n.º 1
0
def home(request):
    f = request.params['f']
    if f.startswith('_'): # Enforce hidden functions
        return ''
    args = json.loads(request.params['args'], object_hook=_decode_datetime)
    kwargs = json.loads(request.params['kwargs'], object_hook=_decode_datetime)
    to_return = json.dumps(getattr(pydiditbackend, f)(*args, **kwargs), default=_encode_datetime)
    pydiditbackend.commit()
    return to_return
Ejemplo n.º 2
0
def testTodoCommit():
    todos = get("Todo", all=True)
    for todo in todos:
        delete_from_db(todo)
        del todo
    commit()
    todos = get("Todo", all=True)
    assert len(todos) == 0
    todo = put("Todo", u"TESTDESCRIPTION")
    commit()
    del todo
    todos = get("Todo", all=True)
    assert len(todos) == 1
    assert todos[0]["description"] == u"TESTDESCRIPTION"
Ejemplo n.º 3
0
def edit(request):
    model_type = request.matchdict['model_type']
    primary_descriptor = None
    if model_type == 'todos':
        model_type = 'Todo'
        primary_descriptor = 'description'
    elif model_type == 'projects':
        model_type = 'Project'
        primary_descriptor = 'description'
    elif model_type == 'tags':
        model_type = 'Tag'
        primary_descriptor = 'name'

    to_update = b.get(model_type, filter_by={'id': request.matchdict['id']})[0]
    control = None
    if 'pydiditweb_control' in request.json_body:
        control = request.json_body['pydiditweb_control']
        del request.json_body['pydiditweb_control']
    # Right now, you can only do one thing per call: set completed, move, update other attributes
    # These are in no particular order, really
    if 'state' in request.json_body and request.json_body['state'] == 'completed':
        b.set_completed(to_update)
    elif control is not None:
        if 'move_to_anchor' in control:
            to_update['display_position'] = b.move(to_update, anchor=control['move_to_anchor'], model_name=model_type)
        elif 'sink_all_the_way' in control and control['sink_all_the_way']:
            to_update['display_position'] = b.move(to_update, direction='sink', all_the_way=True)
    else:
        # Todo: Convert all timestamps to datetime in json_body so that the whole thing can be passed below.
        new_attributes = {}
        new_attributes[primary_descriptor] = request.json_body[primary_descriptor]
        b.set_attributes(to_update, new_attributes)
    # I don't really understand why this flush() is needed, but it is.  Without it, sqlalchemy/transaction does a rollback inside the backend when DBSession.close() is called.
    b.flush()
    b.commit()
    return json.dumps(to_update, default=datetime_handler)
Ejemplo n.º 4
0
def testTodoDefaultState():
    todo = make("Todo", u"TESTDESCRIPTION")
    add_to_db(todo)
    set_completed(todo)
    commit()
    assert todo["state"] == u"completed"