def view(request, game_id, slug=None): """View one game. It must be approved or yours.""" user = request.user if request.user.is_authenticated() else None game = get_object_or_404(Game, Q(is_approved=True) | Q(creator=user), id=game_id) return render(request, 'games/view.html', {'game': game})
def screenshots(request, game_id): """View/edit screenshots for a game.""" game = get_object_or_404(Game, id=game_id, creator=request.user) room_for_more = game.screenshot_set.count() < settings.SCREENSHOTS_MAX form = ScreenshotForm() game = get_object_or_404(Game, creator=request.user, pk=game_id) form = GameForm(instance=game) room_for_more = game.screenshot_set.count() < settings.SCREENSHOTS_MAX screenshot_form = ScreenshotForm() if request.POST and room_for_more: screenshot_form = ScreenshotForm(request.POST, request.FILES) if screenshot_form.is_valid(): new_screenshot = screenshot_form.save(commit=False) new_screenshot.game = game new_screenshot.save() messages.success(request, "Your screenshot has been uploaded!") return HttpResponseRedirect(reverse('games.edit', args=[game.id])) c = {'game': game, 'form': form, 'room_for_more': room_for_more, 'screenshot_form': screenshot_form, } return render(request, 'games/edit.html', c)
def screenshots(request, game_id): """View/edit screenshots for a game.""" game = get_object_or_404(Game, id=game_id, creator=request.user) room_for_more = game.screenshot_set.count() < settings.SCREENSHOTS_MAX form = ScreenshotForm() game = get_object_or_404(Game, creator=request.user, pk=game_id) form = GameForm(instance=game) room_for_more = game.screenshot_set.count() < settings.SCREENSHOTS_MAX screenshot_form = ScreenshotForm() if request.POST and room_for_more: screenshot_form = ScreenshotForm(request.POST, request.FILES) if screenshot_form.is_valid(): new_screenshot = screenshot_form.save(commit=False) new_screenshot.game = game new_screenshot.save() messages.success(request, "Your screenshot has been uploaded!") return HttpResponseRedirect(reverse('games.edit', args=[game.id])) c = { 'game': game, 'form': form, 'room_for_more': room_for_more, 'screenshot_form': screenshot_form, } return render(request, 'games/edit.html', c)
def view(request, game_id, slug=None): """View one game. It must be approved or yours.""" filters = [] user = request.user if request.user.is_authenticated() else None if user and not user.is_superuser: filters.append(Q(creator=user)) if not user or not user.is_superuser: filters.append(Q(is_approved=True)) game = get_object_or_404(Game, reduce(or_, filters, Q()), id=game_id) return render(request, 'games/view.html', {'game': game})
def view(request, game_id, slug=None): """View one game. It must be approved or yours.""" filters = [] user = request.user if request.user.is_authenticated() else None if user and not user.is_superuser: filters.append(Q(creator=user)) if not user or not user.is_superuser: filters.append(Q(is_approved=True)) game = get_object_or_404(Game, reduce(or_, filters, Q()), id=game_id) return render(request, "games/view.html", {"game": game})
def view_list(request): """View a list of games.""" # TODO: Paginate. filters = [] user = request.user if request.user.is_authenticated() else None if user and not user.is_superuser: filters.append(Q(creator=user)) if not user or not user.is_superuser: filters.append(Q(is_approved=True)) games = Game.objects.filter(reduce(or_, filters, Q())).order_by('name') return render(request, 'games/list.html', {'games': games})
def view_list(request): """View a list of games.""" # TODO: Paginate. filters = [] user = request.user if request.user.is_authenticated() else None if user and not user.is_superuser: filters.append(Q(creator=user)) if not user or not user.is_superuser: filters.append(Q(is_approved=True)) games = Game.objects.filter(reduce(or_, filters, Q())).order_by("name") return render(request, "games/list.html", {"games": games})
def delete(request, game_id): """Delete an existing game.""" game = get_object_or_404(Game, id=game_id, creator=request.user) if request.POST: msg = 'You have deleted the game "%s".' % game.name game.delete() messages.success(request, msg) return HttpResponseRedirect(reverse('games.view_list')) return render(request, 'games/delete.html', {'game': game})
def screenshot_delete(request, game_id, screenshot_id): """Delete a screenshot.""" game = get_object_or_404(Game, id=game_id, creator=request.user) screenshot = get_object_or_404(Screenshot, id=screenshot_id, game=game) if request.POST: msg = "You have deleted the screenshot %s!" % screenshot screenshot.delete() messages.success(request, msg) return HttpResponseRedirect(reverse("games.screenshots", args=[game.id])) c = {"game": game, "screenshot": screenshot} return render(request, "games/screenshot_delete.html", c)
def screenshot_delete(request, game_id, screenshot_id): """Delete a screenshot.""" game = get_object_or_404(Game, id=game_id, creator=request.user) screenshot = get_object_or_404(Screenshot, id=screenshot_id, game=game) if request.POST: msg = 'You have deleted the screenshot %s!' % screenshot screenshot.delete() messages.success(request, msg) return HttpResponseRedirect( reverse('games.screenshots', args=[game.id])) c = {'game': game, 'screenshot': screenshot} return render(request, 'games/screenshot_delete.html', c)
def create(request): """Create a new game.""" form = GameForm() if request.POST: form = GameForm(request.POST) if form.is_valid(): new_game = form.save(commit=False) new_game.creator = request.user new_game.save() messages.success(request, "Your game was successfully saved!") return HttpResponseRedirect(new_game.get_absolute_url()) return render(request, 'games/create.html', {'form': form})
def edit(request, game_id): """Edit an existing game.""" game = get_object_or_404(Game, creator=request.user, pk=game_id) form = GameForm(instance=game) room_for_more = game.screenshot_set.count() < settings.SCREENSHOTS_MAX screenshot_form = ScreenshotForm() c = {"game": game, "form": form, "room_for_more": room_for_more, "screenshot_form": screenshot_form} if request.POST: form = GameForm(request.POST, instance=game) c.update({"form": form}) if form.is_valid(): form.save() messages.success(request, "Your changes were saved!") return HttpResponseRedirect(game.get_absolute_url()) return render(request, "games/edit.html", c)
def edit(request, game_id): """Edit an existing game.""" game = get_object_or_404(Game, creator=request.user, pk=game_id) form = GameForm(instance=game) room_for_more = game.screenshot_set.count() < settings.SCREENSHOTS_MAX screenshot_form = ScreenshotForm() c = { 'game': game, 'form': form, 'room_for_more': room_for_more, 'screenshot_form': screenshot_form, } if request.POST: form = GameForm(request.POST, instance=game) c.update({'form': form}) if form.is_valid(): form.save() messages.success(request, "Your changes were saved!") return HttpResponseRedirect(game.get_absolute_url()) return render(request, 'games/edit.html', c)
def mine(request): """View your own games.""" games = request.user.game_set.all() return render(request, 'games/mine.html', {'games': games})
def view_list(request): """View a list of games.""" # TODO(james) Paginate games = Game.objects.filter(is_approved=True) return render(request, 'games/list.html', {'games': games})
def winners(request): """View the list of winners.""" return render(request, "games/winners.html")
def party(request, party_name): """Show a static page for a party""" try: return render(request, 'static/parties/%s.html' % party_name) except template.TemplateDoesNotExist: raise Http404
def ballot(request): """Display the list of games this user can vote on.""" ballot = Ballot.get_or_create(request.user) return render(request, 'vote/ballot.html', {'ballot': ballot})
def finalists(request): """View the list of finalists.""" games = (Game.objects.filter( id__in=settings.FINALIST_LIST).order_by('name')) return render(request, 'games/finalists.html', {'games': games})
def finalists(request): """View the list of finalists.""" games = Game.objects.filter(id__in=settings.FINALIST_LIST).order_by("name") return render(request, "games/finalists.html", {"games": games})
def winners(request): """View the list of winners.""" return render(request, 'games/winners.html')
def hello(request, name=None): return render('index.html', {})
def finalists(request): """View the list of finalists.""" games = (Game.objects.filter(id__in=settings.FINALIST_LIST) .order_by('name')) return render(request, 'games/finalists.html', {'games': games})