コード例 #1
0
ファイル: views.py プロジェクト: imclab/worldecho
def configure(request, worldname):
	try:
		world = World.objects.get(name__iexact=worldname, owner=request.user)
	except World.DoesNotExist:
		# TODO: log security?
		return redirect('profile')
	add_member_message = None
	if request.method == 'POST':
		if request.POST['form'] == 'public_perm':
			pp = request.POST['public_perm']
			if pp == 'none':
				world.public_readable = False
				world.public_writable = False
			elif pp == 'read':
				world.public_readable = True
				world.public_writable = False
			else:
				assert pp == 'write'
				world.public_readable = True
				world.public_writable = True
			world.save()
		elif request.POST['form'] == 'add_member':
			add_member_message = try_add_member(world, request.POST['add_member'])
		elif request.POST['form'] == 'remove_member':
			to_remove = [key for key in request.POST.keys() if key.startswith('remove_')]
			assert len(to_remove) == 1
			username_to_remove = to_remove[0].split('_')[1]
			wl = Whitelist.objects.get(world=world, user__username=username_to_remove)
			wl.delete()
		elif request.POST['form'] == 'features':
			# TODO: move this crap into JSONField so I can do world.properties.features.go_to_coordinates = ...
			features = world.properties.get('features', {})
			features['go_to_coord'] = bool(int(request.POST['go_to_coord']))
			features['coordLink'] = bool(int(request.POST['coordLink']))
			features['urlLink'] = bool(int(request.POST['urlLink']))
			world.properties['features'] = features
			world.save()
		else:
			raise ValueError, "Unknown form type"
			
	if world.public_writable:
		public_perm = 'write'
	elif world.public_readable:
		public_perm = 'read'
	else:
		public_perm = 'none'
	return req_render_to_response(request, 'configure.html', {
		'world': world,
		'public_perm': public_perm,
		'members': User.objects.filter(whitelist__world=world).order_by('username'),
		'add_member_message': add_member_message
		})
コード例 #2
0
ファイル: views.py プロジェクト: imclab/worldecho
def yourworld(request, namespace):
    """Check permissions and route request."""
    # world, _ = World.get_or_create(namespace)
    world = get_object_or_404(World, name=namespace)

    # if user is exists and is authenticated
    # send edits should also send it to their world
    # create a world when they create an account

    if 'color' in request.session:
        color = request.session['color']
    else:
        import random
        color = random.randint(0, 9)
        request.session['color'] = color

    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)  #well that's important and conversly put

    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),
            'properties': simplejson.dumps(world.properties),
            'color': color,
            'world': world,
        })
コード例 #3
0
ファイル: views.py プロジェクト: imclab/worldecho
def yourworld(request, namespace):
	"""Check permissions and route request."""
	# world, _ = World.get_or_create(namespace)
	world = get_object_or_404(World, name=namespace)

	# if user is exists and is authenticated
	# send edits should also send it to their world
	# create a world when they create an account

	if 'color' in request.session:
		color = request.session['color']
	else:
		import random
		color = random.randint(0,9)
		request.session['color'] = color

	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) #well that's important and conversly put

	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),
		'properties': simplejson.dumps(world.properties),
		'color': color,
		'world': world,
	})
コード例 #4
0
ファイル: views.py プロジェクト: imclab/worldecho
def private(request):
	return req_render_to_response(request, 'private.html')
コード例 #5
0
ファイル: views.py プロジェクト: imclab/worldecho
def home(request):
	"""The main front-page other than a world."""
	return req_render_to_response(request, 'home.html')
コード例 #6
0
ファイル: views.py プロジェクト: imclab/worldecho
@login_required
def profile(request):
	worlds_owned = World.objects.filter(owner=request.user)
	memberships = World.objects.filter(whitelist__user=request.user)
	context = {'worlds_owned': worlds_owned, 'memberships': memberships}
	if request.method == 'POST':
		worldname = request.POST['worldname']
		try:
			claim(request.user, worldname)
			context['claimed'] = True
			context['message'] = 'World "%s" successfully claimed.' % worldname
		except ClaimException, msg:
			context['claimed'] = False
			context['message'] = msg
	return req_render_to_response(request, 'profile.html', context)

@login_required
def configure(request, worldname):
	try:
		world = World.objects.get(name__iexact=worldname, owner=request.user)
	except World.DoesNotExist:
		# TODO: log security?
		return redirect('profile')
	add_member_message = None
	if request.method == 'POST':
		if request.POST['form'] == 'public_perm':
			pp = request.POST['public_perm']
			if pp == 'none':
				world.public_readable = False
				world.public_writable = False
コード例 #7
0
ファイル: views.py プロジェクト: imclab/worldecho
def private(request):
    return req_render_to_response(request, 'private.html')
コード例 #8
0
ファイル: views.py プロジェクト: imclab/worldecho
def configure(request, worldname):
    try:
        world = World.objects.get(name__iexact=worldname, owner=request.user)
    except World.DoesNotExist:
        # TODO: log security?
        return redirect('profile')
    add_member_message = None
    if request.method == 'POST':
        if request.POST['form'] == 'public_perm':
            pp = request.POST['public_perm']
            if pp == 'none':
                world.public_readable = False
                world.public_writable = False
            elif pp == 'read':
                world.public_readable = True
                world.public_writable = False
            else:
                assert pp == 'write'
                world.public_readable = True
                world.public_writable = True
            world.save()
        elif request.POST['form'] == 'add_member':
            add_member_message = try_add_member(world,
                                                request.POST['add_member'])
        elif request.POST['form'] == 'remove_member':
            to_remove = [
                key for key in request.POST.keys() if key.startswith('remove_')
            ]
            assert len(to_remove) == 1
            username_to_remove = to_remove[0].split('_')[1]
            wl = Whitelist.objects.get(world=world,
                                       user__username=username_to_remove)
            wl.delete()
        elif request.POST['form'] == 'features':
            # TODO: move this crap into JSONField so I can do world.properties.features.go_to_coordinates = ...
            features = world.properties.get('features', {})
            features['go_to_coord'] = bool(int(request.POST['go_to_coord']))
            features['coordLink'] = bool(int(request.POST['coordLink']))
            features['urlLink'] = bool(int(request.POST['urlLink']))
            world.properties['features'] = features
            world.save()
        else:
            raise ValueError, "Unknown form type"

    if world.public_writable:
        public_perm = 'write'
    elif world.public_readable:
        public_perm = 'read'
    else:
        public_perm = 'none'
    return req_render_to_response(
        request, 'configure.html', {
            'world':
            world,
            'public_perm':
            public_perm,
            'members':
            User.objects.filter(whitelist__world=world).order_by('username'),
            'add_member_message':
            add_member_message
        })
コード例 #9
0
ファイル: views.py プロジェクト: imclab/worldecho
def home(request):
    """The main front-page other than a world."""
    return req_render_to_response(request, 'home.html')
コード例 #10
0
ファイル: views.py プロジェクト: imclab/worldecho
@login_required
def profile(request):
    worlds_owned = World.objects.filter(owner=request.user)
    memberships = World.objects.filter(whitelist__user=request.user)
    context = {'worlds_owned': worlds_owned, 'memberships': memberships}
    if request.method == 'POST':
        worldname = request.POST['worldname']
        try:
            claim(request.user, worldname)
            context['claimed'] = True
            context['message'] = 'World "%s" successfully claimed.' % worldname
        except ClaimException, msg:
            context['claimed'] = False
            context['message'] = msg
    return req_render_to_response(request, 'profile.html', context)


@login_required
def configure(request, worldname):
    try:
        world = World.objects.get(name__iexact=worldname, owner=request.user)
    except World.DoesNotExist:
        # TODO: log security?
        return redirect('profile')
    add_member_message = None
    if request.method == 'POST':
        if request.POST['form'] == 'public_perm':
            pp = request.POST['public_perm']
            if pp == 'none':
                world.public_readable = False