Пример #1
0
def battle(request, battle_id):
    battle = get_object_or_404(Battle, id=battle_id)
    battle_json = battle.to_json()
    my_nickname = request.session[SESSION_NICKNAME];
    presets = algorithms.ALGORITHM_CLASSES.keys()

    return rtr('wars/battle.html')
Пример #2
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')
Пример #3
0
def new_preset(request):
    if request.method == 'POST':
        form = WebViewPresetForm(request.POST)
        result = __save_preset(form)
        if result:
            return result
    else:
        form = WebViewPresetForm()
    return rtr('administration/edit_preset.html')
Пример #4
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')
Пример #5
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')
Пример #6
0
def new_preset(request):
    if request.method == 'POST':
        form = WebViewPresetForm(request.POST)
        result = __save_preset(form)
        if result:
            return result
    else:
        form = WebViewPresetForm()
    return rtr('administration/edit_preset.html')
Пример #7
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')
Пример #8
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')
Пример #9
0
def edit_preset(request, name):
    preset = WebViewPreset.objects.get(name=name)
    if request.method == 'POST':
        form = WebViewPresetForm(request.POST)
        result = __save_preset(form)
        if result:
            return result
    else:
        urls = json.loads(preset.urls)
        urls_d = {}
        for i in range(len(urls)):
            urls_d['url_%s' % (i+1)] = urls[i]
        form = WebViewPresetForm(initial=dict({'name': preset.name,
                                               'views': preset.views}.items() +
                                              urls_d.items()))
    return rtr('administration/edit_preset.html')
Пример #10
0
def edit_preset(request, name):
    preset = WebViewPreset.objects.get(name=name)
    if request.method == 'POST':
        form = WebViewPresetForm(request.POST)
        result = __save_preset(form)
        if result:
            return result
    else:
        urls = json.loads(preset.urls)
        urls_d = {}
        for i in range(len(urls)):
            urls_d['url_%s' % (i + 1)] = urls[i]
        form = WebViewPresetForm(initial=dict({
            'name': preset.name,
            'views': preset.views
        }.items() + urls_d.items()))
    return rtr('administration/edit_preset.html')
Пример #11
0
def change_screen(request):
    if request.POST:
        form = ChangeScreenForm(request.POST)
        if form.is_valid():
            # turning the screen off
            if form.cleaned_data['on_or_off'] == 'off':
                quit_quatz()
            # turning it on or changing it
            else:
                if form.cleaned_data['on_or_off'] == 'on':
                    open_quatz()
                if form.cleaned_data['quartz_sketch']:
                    quartz_mode(form.cleaned_data['quartz_sketch'])
                elif form.cleaned_data['web_preset']:
                    preset = WebViewPreset.objects.get(name=form.cleaned_data['web_preset'])
                    urls = json.loads(preset.urls)
                    web_mode(preset.views, urls)
    else:
        form = ChangeScreenForm()
    return rtr('administration/change_screen.html')
Пример #12
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')
Пример #13
0
def change_screen(request):
    if request.POST:
        form = ChangeScreenForm(request.POST)
        if form.is_valid():
            # turning the screen off
            if form.cleaned_data['on_or_off'] == 'off':
                quit_quatz()
            # turning it on or changing it
            else:
                if form.cleaned_data['on_or_off'] == 'on':
                    open_quatz()
                if form.cleaned_data['quartz_sketch']:
                    quartz_mode(form.cleaned_data['quartz_sketch'])
                elif form.cleaned_data['web_preset']:
                    preset = WebViewPreset.objects.get(
                        name=form.cleaned_data['web_preset'])
                    urls = json.loads(preset.urls)
                    web_mode(preset.views, urls)
    else:
        form = ChangeScreenForm()
    return rtr('administration/change_screen.html')
Пример #14
0
def view_quartz_sketch(request, sketch):
    sketch = get_object_or_404(QuartzSketch, name=sketch)
    return rtr('quartz/sketch.html')
Пример #15
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')
Пример #16
0
def battle_result(request, battle_id):
    battle = get_object_or_404(Battle, id=battle_id)
    battle_json = battle.to_json()
    scores = calculate_final_scores(battle)
    return rtr('wars/battle_result.html')
Пример #17
0
def list_sketches(request):
    sketches = ProcessingSketch.objects.all()
    return rtr('processing/sketches.html')
Пример #18
0
def view_preset(request, name):
    preset = WebViewPreset.objects.get(name=name)
    urls = json.loads(preset.urls)
    return rtr('administration/view_preset.html')
Пример #19
0
def view_sketch(request, sketch):
    sketch = get_object_or_404(ProcessingSketch, name=sketch)
    return rtr('processing/sketch.html')
Пример #20
0
def view_sketch_random(request):
    sketch = ProcessingSketch.objects.order_by('?')[0]
    urls = json.loads(sketch.urls)
    return rtr('processing/sketch.html')
Пример #21
0
def list_presets(request):
    presets = WebViewPreset.objects.all()
    return rtr('administration/presets.html')
Пример #22
0
def list_sketches(request):
    sketches = QuartzSketch.objects.all()
    return rtr('quartz/sketches.html')
Пример #23
0
def list_presets(request):
    presets = WebViewPreset.objects.all()
    return rtr('administration/presets.html')
Пример #24
0
def view_preset(request, name):
    preset = WebViewPreset.objects.get(name=name)
    urls = json.loads(preset.urls)
    return rtr('administration/view_preset.html')
Пример #25
0
def view_sketch(request, sketch):
    sketch = get_object_or_404(ProcessingSketch, name=sketch)
    return rtr('processing/sketch.html')
Пример #26
0
def view_sketch_random(request):
    sketch = ProcessingSketch.objects.order_by('?')[0]
    urls = json.loads(sketch.urls)
    return rtr('processing/sketch.html')
Пример #27
0
def list_sketches(request):
    sketches = ProcessingSketch.objects.all()
    return rtr('processing/sketches.html')