This repository has been archived on 2019-11-11. You can view files and clone it, but cannot push or open issues or pull requests.
tofu/issues/views.py

34 lines
835 B
Python

from django.http import HttpResponseRedirect
from django.shortcuts import get_object_or_404, render
from .forms import IssueForm
from .models import Issue
def index(request):
issue_list = Issue.objects.order_by('create_date')
return render(request, 'issues/index.html', {
'issue_list': issue_list,
})
def detail(request, issue_id):
issue = get_object_or_404(Issue, pk=issue_id)
return render(request, 'issues/detail.html', {
'issue': issue,
})
def new(request):
if request.method == 'POST':
form = IssueForm(request.POST)
if form.is_valid():
new_issue = form.save()
return HttpResponseRedirect('/issues/{}'.format(new_issue.id))
else:
form = IssueForm()
return render(request, 'issues/new.html', {
'form': form,
})