示例#1
0
def pick_sounds(request, battle_id):
    battle = get_object_or_404(Battle, id=battle_id)
    # prevent simultaneous invite responses
    if not request.uuid == battle.player1_uuid and not request.uuid == battle.player2_uuid:
        return HttpResponseRedirect(rurl('wars:wait-on-player', battle.id))
    form = PickSoundsForm()
    return rtr('wars/pick_sounds.html')
示例#2
0
def upload_sketch(request):
    if request.method == 'POST':
        form = UploadSketchForm(request.POST, request.FILES)
        if form.is_valid():
            sketch_name = __handle_uploaded_file(request.FILES['file'])
            return HttpResponseRedirect(rurl('view_sketch_code', sketch_name))
    else:
        form = UploadSketchForm()
    return rtr('processing/upload.html')
示例#3
0
def upload_sketch(request):
    if request.method == 'POST':
        form = UploadSketchForm(request.POST, request.FILES)
        if form.is_valid():
            sketch_name = __handle_uploaded_file(request.FILES['file'])
            return HttpResponseRedirect(rurl('view_sketch_code', sketch_name))
    else:
        form = UploadSketchForm()
    return rtr('processing/upload.html')
示例#4
0
def frontpage(request):
    form = PickNameForm()
    if request.method == 'POST':
        form = PickNameForm(request.POST)
        if form.is_valid():
            nickname = form.cleaned_data['nickname']
            request.session[SESSION_NICKNAME] = nickname
            battle = Battle()
            battle.player1_uuid = request.uuid
            battle.player1 = nickname
            battle.save()
            return HttpResponseRedirect(rurl('wars:wait-on-player', battle.id))
    return rtr('wars/frontpage.html')
示例#5
0
        def authed_func(request, *args, **kargs):

            nickname = request.session.get(SESSION_NICKNAME, False)
            pl_uuid = request.session.get(SESSION_UUID, str(uuid.uuid4()))

            request.session[SESSION_UUID] = pl_uuid

            if self.check_nickname and not nickname:
                return HttpResponseRedirect(rurl('wars:frontpage'))

            request.user = nickname
            request.uuid = pl_uuid
            return f(request, *args, **kargs)
示例#6
0
def upload_sketch(request):
    if request.method == 'POST':
        form = UploadSketchForm(request.POST, request.FILES)
        if form.is_valid():
            sketch_name = request.FILES['file'].name
            sketch, _ = QuartzSketch.objects.get_or_create(name=sketch_name)
            sketch.name = sketch_name
            sketch.file = request.FILES['file']
            sketch.save()
            return HttpResponseRedirect(rurl('view_quartz_sketch',
                                             sketch.name))
    else:
        form = UploadSketchForm()
    return rtr('quartz/upload.html')
示例#7
0
def __save_preset(form):
    if form.is_valid():
        urls = []
        for i in range(8):
            if form.cleaned_data['url_%s' % (i+1)]:
                urls.append(form.cleaned_data['url_%s' % (i+1)])

        try:
            preset = WebViewPreset.objects.get(name=form.cleaned_data['name'])
        except WebViewPreset.DoesNotExist:
            preset = WebViewPreset()
        preset.name=form.cleaned_data['name']
        preset.views = form.cleaned_data['views']
        preset.urls = json.dumps(urls)
        preset.save()
        return HttpResponseRedirect(rurl('view_web_preset', preset.name))
    else:
        return False
示例#8
0
def __save_preset(form):
    if form.is_valid():
        urls = []
        for i in range(8):
            if form.cleaned_data['url_%s' % (i + 1)]:
                urls.append(form.cleaned_data['url_%s' % (i + 1)])

        try:
            preset = WebViewPreset.objects.get(name=form.cleaned_data['name'])
        except WebViewPreset.DoesNotExist:
            preset = WebViewPreset()
        preset.name = form.cleaned_data['name']
        preset.views = form.cleaned_data['views']
        preset.urls = json.dumps(urls)
        preset.save()
        return HttpResponseRedirect(rurl('view_web_preset', preset.name))
    else:
        return False
示例#9
0
def wait_on_player(request, battle_id):
    battle = get_object_or_404(Battle, id=battle_id)
    player_is_creator = battle.player1_uuid == request.uuid
    player_is_invited = battle.player2_uuid == request.uuid

    if request.method == 'POST' and \
       not player_is_invited and \
       not battle.player2_uuid:
        form = PickNameForm(request.POST)
        if form.is_valid():
            # N.B. TODO: prevent people from stealing the game by checking if player2 is already set.
            nickname = form.cleaned_data['nickname']
            request.session[SESSION_NICKNAME] = nickname
            battle.player2_uuid = request.uuid
            battle.player2 = nickname
            battle.save()
            return HttpResponseRedirect(rurl('wars:pick-sounds', battle.id))

    form = PickNameForm()
    return rtr('wars/wait_on_player.html')
示例#10
0
def wait_on_sounds(request, battle_id):
    battle = get_object_or_404(Battle, id=battle_id)
    if battle.status_sounds():
        return HttpResponseRedirect(rurl('wars:battle', battle.id))
    return rtr('wars/wait_on_sounds.html')