コード例 #1
0
def edit_entry(request, slug, template='submissions/edit.html'):
    entry = Entry.objects.get(slug=slug)
    if not entry.editable_by(request.user):
        return action_unavailable_response(request, case='no_edit_rights')
    if not request.challenge.is_open():
        return action_unavailable_response(request, case='challenge_closed')
    if request.method == 'POST':
        form = EntryForm(request.POST, instance=entry)
        if form.is_valid():
            entry = form.save(commit=False)
            entry.slug = slugify(entry.title)
            form.save()
            if entry.to_market == True:
                return HttpResponseRedirect(settings.MARKETPLACE_URL)
            else:
                return HttpResponseRedirect(
                    reverse('submissions.entry_list',
                            kwargs={'category': 'all'}))
        else:
            data = {
                'categories': Category.objects.all(),
                'form': form,
            }
    else:
        data = {
            'categories': Category.objects.all(),
            'form': EntryForm(instance=entry),
        }
    return render(request, template, data)
コード例 #2
0
ファイル: views.py プロジェクト: mozilla/gameon
def edit_entry(request, slug, template='submissions/edit.html'):
    entry = Entry.objects.get(slug=slug)
    if not entry.editable_by(request.user):
        return action_unavailable_response(request, case='no_edit_rights')
    if not request.challenge.is_open():
        return action_unavailable_response(request, case='challenge_closed')
    if request.method == 'POST':
        form = EntryForm(request.POST, request.FILES, instance=entry)
        if form.is_valid():
            entry = form.save(commit=False)
            entry.slug = slugify(entry.title)
            form.save()
            if entry.to_market == True:
                return HttpResponseRedirect(settings.MARKETPLACE_URL)
            else:
                messages.success(request, _('<strong>Game edited!</strong>'))
                return HttpResponseRedirect(reverse('submissions.entry_single',
                    kwargs={'slug': slugify(entry.title)}))
        else:
            data = {
                'categories': Category.objects.all(),
                'form': form,
                'mode': 'edit',
            }
    else:
        data = {
            'categories': Category.objects.all(),
            'form': EntryForm(instance=entry),
            'mode': 'edit',
        }
    return render(request, template, data)
コード例 #3
0
ファイル: views.py プロジェクト: toolness/gameon
def edit_entry(request, slug, template='submissions/edit.html'):
    entry = Entry.objects.get(slug=slug)
    if not entry.editable_by(request.user):
        return action_unavailable_response(request, case='no_edit_rights')
    if request.method == 'POST':
        form = EntryForm(request.POST, instance=entry)
        if form.is_valid():
            entry = form.save(commit=False)
            entry.slug = slugify(entry.title)
            form.save()
            if entry.to_market == True:
                return HttpResponseRedirect(settings.MARKETPLACE_URL)
            else:
                return HttpResponseRedirect(reverse('submissions.entry_list',
                    kwargs={'category': 'all'}))
        else:
            data = {
                'categories': Category.objects.all(),
                'form': form,
            }
    else:
        data = {
            'categories': Category.objects.all(),
            'form': EntryForm(instance=entry),
        }
    return render(request, template, data)
コード例 #4
0
ファイル: views.py プロジェクト: toolness/gameon
def create(request, template='submissions/create.html'):
    if request.method == 'POST':
        form = EntryForm(request.POST)
        if form.is_valid():
            entry = form.save(commit=False)
            entry.created_by = request.user.get_profile()
            entry.slug = slugify(entry.title)
            form.save()
            if entry.to_market == True:
                return HttpResponseRedirect(settings.MARKETPLACE_URL)
            else:
                return HttpResponseRedirect(
                    reverse('submissions.entry_list',
                            kwargs={'category': 'all'}))
        else:
            data = {'categories': Category.objects.all(), 'form': form}
    else:
        data = {'categories': Category.objects.all(), 'form': EntryForm()}
    return render(request, template, data)
コード例 #5
0
ファイル: views.py プロジェクト: chloeatplay/gameon
def edit_entry(request, slug, template="submissions/edit.html"):
    entry = Entry.objects.get(slug=slug)
    if not entry.editable_by(request.user):
        return action_unavailable_response(request, case="no_edit_rights")
    if not request.challenge.is_open():
        return action_unavailable_response(request, case="challenge_closed")
    if request.method == "POST":
        form = EntryForm(request.POST, request.FILES, instance=entry)
        if form.is_valid():
            entry = form.save(commit=False)
            entry.slug = slugify(entry.title)
            form.save()
            if entry.to_market == True:
                return HttpResponseRedirect(settings.MARKETPLACE_URL)
            else:
                messages.success(request, _("<strong>Game edited!</strong>"))
                return HttpResponseRedirect(reverse("submissions.entry_single", kwargs={"slug": slugify(entry.title)}))
        else:
            data = {"categories": Category.objects.all(), "form": form, "mode": "edit"}
    else:
        data = {"categories": Category.objects.all(), "form": EntryForm(instance=entry), "mode": "edit"}
    return render(request, template, data)
コード例 #6
0
ファイル: views.py プロジェクト: toolness/gameon
def create(request, template='submissions/create.html'):
    if request.method == 'POST':
        form = EntryForm(request.POST)
        if form.is_valid():
            entry = form.save(commit=False)
            entry.created_by = request.user.get_profile()
            entry.slug = slugify(entry.title)
            form.save()
            if entry.to_market == True:
                return HttpResponseRedirect(settings.MARKETPLACE_URL)
            else:
                return HttpResponseRedirect(reverse('submissions.entry_list',
                    kwargs={'category': 'all'}))
        else:
            data = {
                'categories': Category.objects.all(),
                'form': form
            }
    else:
        data = {
            'categories': Category.objects.all(),
            'form': EntryForm()
        }
    return render(request, template, data)