Пример #1
0
def claim(user, worldname):
    # TODO: write tests for this
    if not re.match('\w+$', worldname):
        raise ClaimException, "Invalid world name."
    world, new = World.get_or_create(worldname)
    if new:
        return do_claim(user, world)
    if world.owner:
        raise ClaimException, "That world already has an owner."
    editors = set(world.edit_set.all().values_list('user', flat=True))
    if not editors:
        return do_claim(user, world)
    if len(editors) > 2:
        raise ClaimException, "Too many people have edited that world."
    if len(editors) == 2:
        if editors == set([user, None]):
            return do_claim(user, world)
        else:
            raise ClaimException, "Too many people have edited that world."
    assert len(editors) == 1
    obj = editors.pop()
    if obj == user:
        return do_claim(user, world)
    if obj is not None:
        raise ClaimException, "Too many people have edited that world."
    if world.created_at > datetime.datetime.now() - datetime.timedelta(
            minutes=5):
        raise ClaimException, "That world has been around too long to claim."
    return do_claim(user, world)
Пример #2
0
def yourworld(request, namespace):
    """Check permissions and route request."""
    world, _ = World.get_or_create(namespace)
    if not permissions.can_read(request.user, world):
        return HttpResponseRedirect('/accounts/private/')
    if 'fetch' in request.GET:
        return fetch_updates(request, world)
    can_write = permissions.can_write(request.user, world)
    if request.method == 'POST':
        if not can_write:
            return response_403()
        return send_edits(request, world)
    state = {
        'canWrite': can_write,
        'canAdmin': permissions.can_admin(request.user, world),
        'worldName': world.name,
        'features': permissions.get_available_features(request.user, world),
    }
    if 'MSIE' in request.META.get('HTTP_USER_AGENT', ''):
        state[
            'announce'] = "Sorry, your World of Text doesn't work well with Internet Explorer."
    return req_render_to_response(request, 'yourworld.html', {
        'settings': settings,
        'state': simplejson.dumps(state),
    })
Пример #3
0
def claim(user, worldname):
    # TODO: write tests for this
    if not re.match('\w+$', worldname):
        raise ClaimException, "Invalid world name."
    world, new = World.get_or_create(worldname)
    if new:
        return do_claim(user, world)
    if world.owner:
        raise ClaimException, "That world already has an owner."
    editors = set(world.edit_set.all().values_list('user', flat=True))
    if not editors:
        return do_claim(user, world)
    if len(editors) > 2:
        raise ClaimException, "Too many people have edited that world."
    if len(editors) == 2:
        if editors == set([user, None]):
            return do_claim(user, world)
        else:
            raise ClaimException, "Too many people have edited that world."
    assert len(editors) == 1
    obj = editors.pop()
    if obj == user:
        return do_claim(user, world)
    if obj is not None:
        raise ClaimException, "Too many people have edited that world."
    if world.created_at > datetime.datetime.now() - datetime.timedelta(minutes=5):
        raise ClaimException, "That world has been around too long to claim."
    return do_claim(user, world)
Пример #4
0
def yourworld(request, namespace):
    """Check permissions and route request."""
    world, _ = World.get_or_create(namespace)
    if not permissions.can_read(request.user, world):
        return HttpResponseRedirect('/accounts/private/')
    if 'fetch' in request.GET:
        return fetch_updates(request, world)
    can_write = permissions.can_write(request.user, world)
    if request.method == 'POST':
        if not can_write:
            return response_403()
        return send_edits(request, world)
    state = {
        'canWrite': can_write,
        'canAdmin': permissions.can_admin(request.user, world),
        'worldName': world.name,
        'features': permissions.get_available_features(request.user, world),
    }
    if 'MSIE' in request.META.get('HTTP_USER_AGENT', ''):
        state['announce'] = "Sorry, your World of Text doesn't work well with Internet Explorer."
    return req_render_to_response(request, 'yourworld.html', {
        'settings': settings,
        'state': simplejson.dumps(state),
    })