示例#1
0
def submit_game(request):
    form = GameForm(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        game = form.save()
        submission = GameSubmission(user=request.user, game=game)
        submission.save()

        # Notify managers a game has been submitted
        admin_url = "https://lutris.net" + reverse("admin:games_game_change",
                                                   args=(game.id, ))
        context = {
            "game_name": game.name,
            "username": request.user.username,
            "admin_link": admin_url,
        }
        subject = "New game submitted: {}".format(game.name)
        send_email("new_game", context, subject, settings.MANAGERS[0][1])

        redirect_url = request.build_absolute_uri(reverse("game-submitted"))

        # Enforce https
        if not settings.DEBUG:
            redirect_url = redirect_url.replace("http:", "https:")

        LOGGER.info("Game submitted, redirecting to %s", redirect_url)
        return redirect(redirect_url)
    return render(request, "games/submit.html", {"form": form})
示例#2
0
文件: pages.py 项目: Freso/website
def submit_game(request):
    form = GameForm(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        game = form.save()
        submission = GameSubmission(user=request.user, game=game)
        submission.save()

        # Notify managers a game has been submitted
        subject = u"New game submitted: {0}".format(game.name)
        admin_url = reverse("admin:games_game_change", args=(game.id, ))
        body = u"""
        The game {0} has been added by {1}.

        It can be modified and published at https://lutris.net{2}
        """.format(game.name, request.user, admin_url)
        mail_managers(subject, body)
        redirect_url = request.build_absolute_uri(reverse("game-submitted"))

        # Enforce https
        if not settings.DEBUG:
            redirect_url = redirect_url.replace('http:', 'https:')

        LOGGER.info('Game submitted, redirecting to %s', redirect_url)
        return redirect(redirect_url)
    return render(request, 'games/submit.html', {'form': form})
示例#3
0
文件: pages.py 项目: retiform/website
def submit_game(request):
    form = GameForm(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        game = form.save()
        submission = GameSubmission(user=request.user, game=game)
        submission.save()

        # Notify managers a game has been submitted
        subject = u"New game submitted: {0}".format(game.name)
        admin_url = reverse("admin:games_game_change", args=(game.id, ))
        body = u"""
        The game {0} has been added by {1}.

        It can be modified and published at https://lutris.net{2}
        """.format(game.name, request.user, admin_url)
        mail_managers(subject, body)
        redirect_url = request.build_absolute_uri(reverse("game-submitted"))

        # Enforce https
        if not settings.DEBUG:
            redirect_url = redirect_url.replace('http:', 'https:')

        LOGGER.info('Game submitted, redirecting to %s', redirect_url)
        return redirect(redirect_url)
    return render(request, 'games/submit.html', {'form': form})
示例#4
0
文件: pages.py 项目: djibux/website
def edit_game(request, slug):
    """Lets the user suggest changes to a game for a moderator to verify"""

    # Load game object and get changeable fields and their defaults
    game = get_object_or_404(Game, slug=slug)
    change_model = game.get_change_model()

    # Workaround: Assigning change_model to initial in the form
    # directly will display the error immediately that changes must be made
    initial = change_model if request.method == "POST" else None

    # Sanity check: Disallow change-suggestions for changes
    if game.change_for:
        return HttpResponseBadRequest("You can only apply changes to a game")

    # Initialise form with rejected values or with the working copy
    form = GameEditForm(request.POST or change_model, request.FILES, initial=initial)

    # If form was submitted and is valid, persist suggestion for moderation
    if request.method == "POST" and form.is_valid():
        # Save the game
        change_suggestion = form.save(commit=False)
        change_suggestion.change_for = game
        change_suggestion.save()
        form.save_m2m()

        # Save metadata (author + reason)
        change_suggestion_meta = GameSubmission(
            user=request.user, game=change_suggestion, reason=request.POST["reason"]
        )
        change_suggestion_meta.save()
        return redirect(reverse("game-submitted-changes", kwargs={"slug": slug}))

    # Render template
    return render(request, "games/submit.html", {"form": form, "game": game})
示例#5
0
文件: pages.py 项目: lutris/website
def edit_game(request, slug):
    """Lets the user suggest changes to a game for a moderator to verify"""

    # Load game object and get changeable fields and their defaults
    game = get_object_or_404(Game, slug=slug)
    change_model = game.get_change_model()

    # Workaround: Assigning change_model to initial in the form
    # directly will display the error immediately that changes must be made
    initial = change_model if request.method == "POST" else None

    # Sanity check: Disallow change-suggestions for changes
    if game.change_for:
        return HttpResponseBadRequest("You can only apply changes to a game")

    # Initialise form with rejected values or with the working copy
    form = GameEditForm(request.POST or change_model, request.FILES, initial=initial)

    # If form was submitted and is valid, persist suggestion for moderation
    if request.method == "POST" and form.is_valid():
        # Save the game
        change_suggestion = form.save(commit=False)
        change_suggestion.change_for = game
        change_suggestion.save()
        form.save_m2m()

        # Save metadata (author + reason)
        change_suggestion_meta = GameSubmission(
            user=request.user, game=change_suggestion, reason=request.POST["reason"]
        )
        change_suggestion_meta.save()
        return redirect(reverse("game-submitted-changes", kwargs={"slug": slug}))

    # Render template
    return render(request, "games/submit.html", {"form": form, "game": game})
示例#6
0
文件: pages.py 项目: lutris/website
def submit_game(request):
    form = GameForm(request.POST or None, request.FILES or None)
    if request.method == "POST" and form.is_valid():
        game = form.save()
        submission = GameSubmission(user=request.user, game=game)
        submission.save()

        # Notify managers a game has been submitted
        admin_url = "https://lutris.net" + reverse(
            "admin:games_game_change", args=(game.id,)
        )
        context = {
            "game_name": game.name,
            "username": request.user.username,
            "admin_link": admin_url,
        }
        subject = "New game submitted: {}".format(game.name)
        send_email("new_game", context, subject, settings.MANAGERS[0][1])

        redirect_url = request.build_absolute_uri(reverse("game-submitted"))

        # Enforce https
        if not settings.DEBUG:
            redirect_url = redirect_url.replace("http:", "https:")

        LOGGER.info("Game submitted, redirecting to %s", redirect_url)
        return redirect(redirect_url)
    return render(request, "games/submit.html", {"form": form})
示例#7
0
文件: pages.py 项目: retiform/website
def edit_game(request, slug):
    """Lets the user suggest changes to a game for a moderator to verify"""

    # Load game object and get changeable fields and their defaults
    game = get_object_or_404(Game, slug=slug)
    change_model = game.get_change_model()

    # Workaround: Assigning change_model to initial in the form
    # directly will display the error immediately that changes must be made
    initial = change_model if request.method == 'POST' else None

    # Sanity check: Disallow change-suggestions for changes
    if game.change_for:
        return HttpResponseBadRequest('You can only apply changes to a game')

    # Initialise form with rejected values or with the working copy
    form = GameEditForm(request.POST or change_model,
                        request.FILES or None,
                        initial=initial)

    # If form was submitted and is valid, persist suggestion for moderation
    if request.method == 'POST' and form.is_valid():
        # Save the game
        change_suggestion = form.save(commit=False)
        change_suggestion.change_for = game
        change_suggestion.save()
        form.save_m2m()

        # Save metadata (author + reason)
        change_suggestion_meta = GameSubmission(user=request.user,
                                                game=change_suggestion,
                                                reason=request.POST['reason'])
        change_suggestion_meta.save()

        redirect_url = request.build_absolute_uri(
            reverse('game-submitted-changes'))

        # Enforce https
        if not settings.DEBUG:
            redirect_url = redirect_url.replace('http:', 'https:')

        LOGGER.info('Change-suggestions for game submitted, redirecting to %s',
                    redirect_url)
        return redirect(redirect_url)

    # Render template
    return render(request, 'games/submit.html', {'form': form, 'game': game})