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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
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')
def view_quartz_sketch(request, sketch): sketch = get_object_or_404(QuartzSketch, name=sketch) return rtr('quartz/sketch.html')
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')
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')
def list_sketches(request): sketches = ProcessingSketch.objects.all() return rtr('processing/sketches.html')
def view_preset(request, name): preset = WebViewPreset.objects.get(name=name) urls = json.loads(preset.urls) return rtr('administration/view_preset.html')
def view_sketch(request, sketch): sketch = get_object_or_404(ProcessingSketch, name=sketch) return rtr('processing/sketch.html')
def view_sketch_random(request): sketch = ProcessingSketch.objects.order_by('?')[0] urls = json.loads(sketch.urls) return rtr('processing/sketch.html')
def list_presets(request): presets = WebViewPreset.objects.all() return rtr('administration/presets.html')
def list_sketches(request): sketches = QuartzSketch.objects.all() return rtr('quartz/sketches.html')