Fixed some stuff for ya' @tykling

This commit is contained in:
Víðir Valberg Guðmundsson 2017-11-24 22:19:17 +01:00
parent f725a5c941
commit c20771da8a
2 changed files with 13 additions and 6 deletions

View File

@ -14,7 +14,7 @@ Create Task for {{ task.team.name }} Team
<button type="submit" class="btn btn-primary">
</form>
</div>
<div class="panel-footer"><i>This task belongs to the <a href="{% url 'teams:detail' slug=team.slug camp_slug=team.camp.slug %}">{{ team.name }} Team</a></i></div>
<div class="panel-footer"><i>This task belongs to the <a href="{% url 'teams:detail' team_slug=team.slug camp_slug=team.camp.slug %}">{{ team.name }} Team</a></i></div>
</div>
{% endblock %}

View File

@ -17,11 +17,12 @@ import logging
logger = logging.getLogger("bornhack.%s" % __name__)
class EnsureTeamResponsibleMixin(SingleObjectMixin):
class EnsureTeamResponsibleMixin(object):
def dispatch(self, request, *args, **kwargs):
if request.user not in self.get_object().responsible.all():
self.team = Team.objects.get(slug=kwargs['team_slug'], camp=self.camp)
if request.user not in self.team.responsible.all():
messages.error(request, 'No thanks')
return redirect('teams:detail', camp_slug=self.camp.slug, team_slug=self.get_object().slug)
return redirect('teams:detail', camp_slug=self.camp.slug, team_slug=self.team.slug)
return super().dispatch(
request, *args, **kwargs
@ -161,10 +162,16 @@ class TaskCreateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMix
def get_context_data(self, *args, **kwargs):
context = super().get_context_data(**kwargs)
self.team = Team.objects.get(slug=kwargs['team_slug'], camp=self.camp)
context['team'] = self.team
return context
def get_success_url(self):
return reverse_lazy('task_detail', kwargs={'camp_slug': self.camp.slug, 'team_slug': self.team.slug, 'slug': self.get_object().slug})
return reverse_lazy(
'task_detail',
kwargs={
'camp_slug': self.camp.slug,
'team_slug': self.team.slug,
'slug': self.get_object().slug
}
)