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 screenshot_add(request, slug): game = get_object_or_404(Game, slug=slug) form = ScreenshotForm(request.POST or None, request.FILES or None, game_id=game.id) if form.is_valid(): form.instance.uploaded_by = request.user form.save() return redirect(reverse("game_detail", kwargs={"slug": slug})) return render(request, "games/screenshot/add.html", {"form": form})
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 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)