Пример #1
0
 def post(self, request, *args, **kwargs):
     issue_form = IssueForm(request.POST)
     if issue_form.is_valid():
         issue = issue_form.save(commit=False)
         issue.project = Project.objects.all().get(pk=int(kwargs["pk"]))
         issue_form.save()
         return render(request, "projects/detail.html", {"project": issue.project})
     else:
         project_id = Project.objects.all().get(pk=kwargs["pk"]).id
         # Redisplay the create issue form
         return render(
             request,
             "projects/issue_form.html",
             {"form": IssueForm, "project_id": project_id, "error_message": "All the fields are required"},
         )
Пример #2
0
def save(request, project_id, issue_id=False):
    """
    Shows latest activity and other usefull info
    """
    t = 'projects/issue/form.html'
    response_vars = {}
    project = Project.objects.get(id=project_id)

    task = None

    if issue_id:
        issue = Issue.objects.get(id=issue_id)
        form = IssueForm(instance=issue)
    else:
        issue = Issue()
        form = IssueForm()

    if request.method == 'POST':

        form = IssueForm(request.POST)

        if form.is_valid():
            if issue_id:
                form = IssueForm(request.POST, instance=Issue.objects.get(id=issue_id))
                issue = form.save(commit=False)
            else:
                issue = form.save(commit=False)
                issue.project = project

            issue.person = request.user
            issue.save()

            if task:
                return HttpResponseRedirect(reverse('task_detail', args=[project.id, task.id]))

            return HttpResponseRedirect(reverse('projects.views.issue.index', args=[project.id]))


    response = { }
    response_vars['request']      = request
    response_vars['project']      = project
    response_vars['form']         = form
    response_vars['issue']         = issue
    response_vars['task']         = task

    return render_project(request, project_id, t, response_vars)