Views can have an indirect relation to a team.

This commit is contained in:
Víðir Valberg Guðmundsson 2018-08-04 13:27:05 +02:00
parent 02977acd5e
commit d08c299e8d
2 changed files with 11 additions and 1 deletions

View file

@ -37,7 +37,11 @@ class EnsureTeamMemberResponsibleMixin(SingleObjectMixin):
class TeamViewMixin: class TeamViewMixin:
def get_team(self):
return self.get_object().team
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)
context['team'] = self.get_object().team context['team'] = self.get_team()
return context return context

View file

@ -25,6 +25,12 @@ class TaskCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTea
template_name = "task_form.html" template_name = "task_form.html"
fields = ['name', 'description'] fields = ['name', 'description']
def get_team(self):
return Team.objects.get(
camp__slug=self.kwargs['camp_slug'],
slug=self.kwargs['team_slug']
)
def form_valid(self, form): def form_valid(self, form):
task = form.save(commit=False) task = form.save(commit=False)
task.team = self.team task.team = self.team