def testCurrentIssue(self): self.assertEqual(Issue.current_issue(), self.issue_2) self.issue_2.published = False self.issue_2.save() self.assertEqual(Issue.current_issue(), self.issue_1) self.issue_2.published = True self.issue_2.save()
def new_issue_view(request): if request.method == "POST": form = IssueForm(request.POST) if form.is_valid(): new_issue = Issue(title=form.cleaned_data["title"]) new_issue.save() new_issue_contributor = Issue_Contributor(issue=new_issue, contributor=request.user) new_issue_contributor.save() return HttpResponseRedirect("/dashboard/") else: form = IssueForm() context = {} context.update(csrf(request)) context["form"] = form return render(request, "dashboard/new_issue_view.html", context)
def new_issue_view(request): if request.method == 'POST': form = IssueForm(request.POST) if form.is_valid(): new_issue = Issue(title=form.cleaned_data['title']) new_issue.save() new_issue_contributor = Issue_Contributor(issue=new_issue, contributor=request.user) new_issue_contributor.save() return HttpResponseRedirect('/dashboard/') else: form = IssueForm() context = {} context.update(csrf(request)) context['form'] = form return render(request, 'dashboard/new_issue_view.html', context)
def index(request): latest_issue = Issue.current_issue() articles = Article.objects.filter(issue=latest_issue) context = {'latest_issue': latest_issue, 'articles': articles} return render (request, 'magazine/index.html', context)
def get_current_issue(self): if not hasattr(self, 'current_issue'): self.current_issue = Issue.current_issue() return self.current_issue
def testLiveIssues(self): self.assertEqual(Issue.current_issue(), None)