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), })
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 })
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), })
def private(request): return req_render_to_response(request, 'private.html')
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 })
def home(request): """The main front-page other than a world.""" return req_render_to_response(request, 'home.html')
@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
@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