示例#1
0
文件: pages.py 项目: Freso/website
def edit_installer(request, slug):
    installer = get_object_or_404(Installer, slug=slug)
    if installer.user != request.user and not request.user.is_staff:
        raise Http404
    form = InstallerForm(request.POST or None, instance=installer)
    if request.method == 'POST' and form.is_valid():
        form.save()
        return redirect("installer_complete", slug=installer.game.slug)
    return render(request, 'games/installer-form.html',
                  {'form': form, 'game': installer.game, 'new': False})
示例#2
0
文件: pages.py 项目: Turupawn/website
def edit_installer(request, slug):
    installer = get_object_or_404(Installer, slug=slug)
    if 'delete' in request.POST:
        return redirect(
            reverse('delete_installer', kwargs={'slug': installer.slug}))
    if 'revision' in request.GET:
        try:
            revision_id = int(request.GET['revision'])
        except ValueError:
            revision_id = None
    else:
        revision_id = None
    versions = Version.objects.get_for_object(installer)
    initial_data = None
    for version in versions:
        if revision_id:
            if version.id == revision_id:
                initial_data = version.field_dict
                break
        else:
            if (version.revision.user == request.user
                    and version.revision.date_created > installer.updated_at):
                initial_data = version.field_dict
                revision_id = version.id
                break

    if initial_data:
        messages.info(
            request, "You are viewing a draft of the installer which does not "
            "reflect the currently available installer. Changes will be "
            "published once it goes through moderation.")
        if 'runner_id' in initial_data:
            initial_data['runner'] = initial_data['runner_id']

    form = InstallerForm(request.POST or None,
                         instance=installer,
                         initial=initial_data)
    if request.method == 'POST' and form.is_valid():
        with reversion.create_revision():
            installer = form.save(commit=False)
            reversion.set_user(request.user)
            reversion.set_comment("[{}] {} by {} on {}".format(
                'draft' if installer.draft else 'submission', slug,
                request.user.username, timezone.now()))
            reversion.add_to_revision(installer)
        return redirect("installer_complete", slug=installer.game.slug)
    return render(
        request, 'installers/form.html', {
            'form': form,
            'game': installer.game,
            'new': False,
            'installer': installer,
            'versions': versions,
            'revision_id': revision_id
        })
示例#3
0
文件: pages.py 项目: Freso/website
def new_installer(request, slug):
    game = get_object_or_404(models.Game, slug=slug)
    installer = Installer(game=game)
    installer.set_default_installer()
    form = InstallerForm(request.POST or None, instance=installer)
    if request.method == 'POST' and form.is_valid():
        installer = form.save(commit=False)
        installer.game_id = game.id
        installer.user = request.user
        installer.save()
        return redirect("installer_complete", slug=game.slug)
    return render(request, 'games/installer-form.html',
                  {'form': form, 'game': game, 'new': True})
示例#4
0
文件: pages.py 项目: djibux/website
def new_installer(request, slug):
    game = get_object_or_404(models.Game, slug=slug)
    installer = Installer(game=game)
    installer.set_default_installer()
    form = InstallerForm(request.POST or None, instance=installer)
    if request.method == "POST" and form.is_valid():
        installer = form.save(commit=False)
        installer.game_id = game.id
        installer.user = request.user
        installer.save()
        notify_installer(installer)
        return redirect("installer_complete", slug=game.slug)
    return render(
        request, "installers/form.html", {"form": form, "game": game, "new": True}
    )
示例#5
0
文件: pages.py 项目: lutris/website
def new_installer(request, slug):
    game = get_object_or_404(models.Game, slug=slug)
    installer = Installer(game=game)
    installer.set_default_installer()
    form = InstallerForm(request.POST or None, instance=installer)
    if request.method == "POST" and form.is_valid():
        installer = form.save(commit=False)
        installer.game_id = game.id
        installer.user = request.user
        installer.save()
        notify_installer(installer)
        return redirect("installer_complete", slug=game.slug)
    return render(
        request, "installers/form.html", {"form": form, "game": game, "new": True}
    )
示例#6
0
文件: pages.py 项目: retiform/website
def new_installer(request, slug):
    game = get_object_or_404(models.Game, slug=slug)
    installer = Installer(game=game)
    installer.set_default_installer()
    form = InstallerForm(request.POST or None, instance=installer)
    if request.method == 'POST' and form.is_valid():
        installer = form.save(commit=False)
        installer.game_id = game.id
        installer.user = request.user
        installer.save()
        return redirect("installer_complete", slug=game.slug)
    return render(request, 'installers/form.html', {
        'form': form,
        'game': game,
        'new': True
    })