def project(request): """Enable a team leader to Update (or create) their team's project.""" if request.method == 'POST': def _get_project(participant): if participant.team.project: return participant.team.project else: project = Project.objects.create(name='A Project', pitch='') participant.team.project = project participant.team.save() return project form = ProjectForm(request.POST, instance=_get_project(request.user.participant)) if form.is_valid(): form.save() context = get_base_context() context["form"] = form return render(request, 'ilwhack/project.html', context) else: form = ProjectForm(instance=request.user.participant.team.project) context = get_base_context() context["form"] = form return render(request, 'ilwhack/project.html', context)
def myteam(request): if request.method == 'POST': if not request.user.participant.team.project: request.user.participant.team.project = Project.objects.create( name='' + request.user.participant.team.name + "'s Project" ) request.user.participant.team.save() form = ProjectForm(request.POST, instance=request.user.participant.team.project) form.save() context = get_base_context() context['form'] = form return render(request, 'ilwhack/myteam.html', context) else: context = get_base_context() context['form'] = ProjectForm() return render(request, 'ilwhack/myteam.html', context)