Example #1
0
def urllink(request):
    # TODO: factor out w/above
    world = World.objects.get(name=request.POST['namespace'])
    if not permissions.can_urllink(request.user, world):
        return response_403()
    tileY, tileX = int(request.POST['tileY']), int(request.POST['tileX'])
    tile, _ = Tile.objects.get_or_create(world=world, tileY=tileY, tileX=tileX)
    if tile.properties.get('protected'):
        if not permissions.can_admin(request.user, world):
            # TODO: log?
            return HttpResponse('')
    # Must convert to str because that's how JsonField reads the existing keys
    charY = int(request.POST['charY'])
    charX = int(request.POST['charX'])
    assert charY < Tile.ROWS
    assert charX < Tile.COLS
    charY, charX = str(charY), str(charX)
    url = request.POST['url'].strip()
    if not urlparse.urlparse(url)[0]:  # no scheme
        url = 'http://' + url
    if 'cell_props' not in tile.properties:
        tile.properties['cell_props'] = {}
    if charY not in tile.properties['cell_props']:
        tile.properties['cell_props'][charY] = {}
    if charX not in tile.properties['cell_props'][charY]:
        tile.properties['cell_props'][charY][charX] = {}
    tile.properties['cell_props'][charY][charX]['link'] = {
        'type': 'url',
        'url': url,
    }
    tile.save()
    log.info('ACTION:URLLINK %s %s %s %s %s %s' %
             (world.id, tileY, tileX, charY, charX, url))
    return HttpResponse('')
Example #2
0
def coordlink(request):
    world = World.objects.get(name=request.POST['namespace'])
    if not permissions.can_coordlink(request.user, world):
        return response_403()
    tileY, tileX = int(request.POST['tileY']), int(request.POST['tileX'])
    tile, _ = Tile.objects.get_or_create(world=world, tileY=tileY, tileX=tileX)
    if tile.properties.get('protected'):
        if not permissions.can_admin(request.user, world):
            # TODO: log?
            return HttpResponse('')
    # Must convert to str because that's how JsonField reads the existing keys
    charY = int(request.POST['charY'])
    charX = int(request.POST['charX'])
    assert charY < Tile.ROWS
    assert charX < Tile.COLS
    charY, charX = str(charY), str(charX)
    link_tileY = str(int(request.POST['link_tileY']))
    link_tileX = str(int(request.POST['link_tileX']))
    if 'cell_props' not in tile.properties:
        tile.properties['cell_props'] = {}
    if charY not in tile.properties['cell_props']:
        tile.properties['cell_props'][charY] = {}
    if charX not in tile.properties['cell_props'][charY]:
        tile.properties['cell_props'][charY][charX] = {}
    tile.properties['cell_props'][charY][charX]['link'] = {
        'type': 'coord',
        'link_tileY': link_tileY,
        'link_tileX': link_tileX,
    }
    tile.save()
    log.info('ACTION:COORDLINK %s %s %s %s %s %s %s' %
             (world.id, tileY, tileX, charY, charX, link_tileY, link_tileX))
    return HttpResponse('')
Example #3
0
def urllink(request):
    # TODO: factor out w/above
    world = World.objects.get(name=request.POST['namespace'])
    if not permissions.can_urllink(request.user, world):
        return response_403()
    tileY, tileX = int(request.POST['tileY']), int(request.POST['tileX'])
    tile, _ = Tile.objects.get_or_create(world=world, tileY=tileY, tileX=tileX)
    if tile.properties.get('protected'):
        if not permissions.can_admin(request.user, world):
            # TODO: log?
            return HttpResponse('')
    # Must convert to str because that's how JsonField reads the existing keys
    charY = int(request.POST['charY'])
    charX = int(request.POST['charX'])
    assert charY < Tile.ROWS
    assert charX < Tile.COLS
    charY, charX = str(charY), str(charX)
    url = request.POST['url'].strip()
    if not urlparse.urlparse(url)[0]: # no scheme
        url = 'http://' + url
    if 'cell_props' not in tile.properties:
        tile.properties['cell_props'] = {}
    if charY not in tile.properties['cell_props']:
        tile.properties['cell_props'][charY] = {}
    if charX not in tile.properties['cell_props'][charY]:
        tile.properties['cell_props'][charY][charX] = {}
    tile.properties['cell_props'][charY][charX]['link'] = {
            'type': 'url',
            'url': url,
            }
    tile.save()
    log.info('ACTION:URLLINK %s %s %s %s %s %s' % (world.id, tileY, tileX, charY, charX, url))
    return HttpResponse('')
Example #4
0
def coordlink(request):
    world = World.objects.get(name=request.POST['namespace'])
    if not permissions.can_coordlink(request.user, world):
        return response_403()
    tileY, tileX = int(request.POST['tileY']), int(request.POST['tileX'])
    tile, _ = Tile.objects.get_or_create(world=world, tileY=tileY, tileX=tileX)
    if tile.properties.get('protected'):
        if not permissions.can_admin(request.user, world):
            # TODO: log?
            return HttpResponse('')
    # Must convert to str because that's how JsonField reads the existing keys
    charY = int(request.POST['charY'])
    charX = int(request.POST['charX'])
    assert charY < Tile.ROWS
    assert charX < Tile.COLS
    charY, charX = str(charY), str(charX)
    link_tileY = str(int(request.POST['link_tileY']))
    link_tileX = str(int(request.POST['link_tileX']))
    if 'cell_props' not in tile.properties:
        tile.properties['cell_props'] = {}
    if charY not in tile.properties['cell_props']:
        tile.properties['cell_props'][charY] = {}
    if charX not in tile.properties['cell_props'][charY]:
        tile.properties['cell_props'][charY][charX] = {}
    tile.properties['cell_props'][charY][charX]['link'] = {
            'type': 'coord',
            'link_tileY': link_tileY,
            'link_tileX': link_tileX,
            }
    tile.save()
    log.info('ACTION:COORDLINK %s %s %s %s %s %s %s' % (world.id, tileY, tileX, charY, charX, link_tileY, link_tileX))
    return HttpResponse('')
Example #5
0
def protect(request):
    world = World.objects.get(name=request.POST['namespace'])
    if not permissions.can_admin(request.user, world):
        return response_403()
    tileY, tileX = request.POST['tileY'], request.POST['tileX']
    # TODO: select for update
    tile, _ = Tile.objects.get_or_create(world=world, tileY=tileY, tileX=tileX)
    tile.properties['protected'] = True
    tile.save()
    log.info('ACTION:PROTECT %s %s %s' % (world.id, tileY, tileX))
    return HttpResponse('')
Example #6
0
def protect(request):
    world = World.objects.get(name=request.POST['namespace'])
    if not permissions.can_admin(request.user, world):
        return response_403()
    tileY, tileX = request.POST['tileY'], request.POST['tileX']
    # TODO: select for update
    tile, _ = Tile.objects.get_or_create(world=world, tileY=tileY, tileX=tileX)
    tile.properties['protected'] = True
    tile.save()
    log.info('ACTION:PROTECT %s %s %s' % (world.id, tileY, tileX))
    return HttpResponse('')