From f725a5c941ac36a6f6d83cc51b9de0df5e4add22 Mon Sep 17 00:00:00 2001 From: Thomas Steen Rasmussen Date: Fri, 24 Nov 2017 22:06:23 +0100 Subject: [PATCH] more work on tasks --- src/teams/models.py | 4 + src/teams/templates/task_create.html | 20 +++++ src/teams/templates/task_detail.html | 2 +- src/teams/templates/team_detail.html | 6 +- src/teams/templates/team_list.html | 8 +- src/teams/templates/teammember_approve.html | 2 +- src/teams/templates/teammember_remove.html | 2 +- src/teams/urls.py | 82 ++++++++++++--------- src/teams/views.py | 33 +++++++-- 9 files changed, 108 insertions(+), 51 deletions(-) create mode 100644 src/teams/templates/task_create.html diff --git a/src/teams/models.py b/src/teams/models.py index 5b30a123..843c7f0e 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -150,3 +150,7 @@ class TeamTask(CampRelatedModel): self.slug = slug super().save(**kwargs) + @property + def responsible(self): + return team.responsible.all() + diff --git a/src/teams/templates/task_create.html b/src/teams/templates/task_create.html new file mode 100644 index 00000000..7fde553d --- /dev/null +++ b/src/teams/templates/task_create.html @@ -0,0 +1,20 @@ +{% extends 'base.html' %} +{% load commonmark %} + +{% block title %} +Create Task for {{ task.team.name }} Team +{% endblock %} + +{% block content %} +
+

Create Task

+
+
+ {{ form }} +
+ +
+{% endblock %} + diff --git a/src/teams/templates/task_detail.html b/src/teams/templates/task_detail.html index 4de2715a..5ac2b2b7 100644 --- a/src/teams/templates/task_detail.html +++ b/src/teams/templates/task_detail.html @@ -9,7 +9,7 @@

Task: {{ task.name }}

{{ task.description|commonmark }}
- +
diff --git a/src/teams/templates/team_detail.html b/src/teams/templates/team_detail.html index 60f4b711..492b499c 100644 --- a/src/teams/templates/team_detail.html +++ b/src/teams/templates/team_detail.html @@ -14,7 +14,7 @@ Team: {{ team.name }} | {{ block.super }}
{{ team.description|unsafecommonmark }} {% if request.user in team.responsible.all %} - Manage Team + Manage Team {% endif %}
@@ -55,10 +55,10 @@ Team: {{ team.name }} | {{ block.super }} {% endif %} {% if request.user in team.members.all %} - Leave Team + Leave Team {% else %} {% if team.needs_members %} - This team is looking for members! Join Team + This team is looking for members! Join Team {% endif %} {% endif %} diff --git a/src/teams/templates/team_list.html b/src/teams/templates/team_list.html index a0ade942..c72df85d 100644 --- a/src/teams/templates/team_list.html +++ b/src/teams/templates/team_list.html @@ -33,7 +33,7 @@ Teams | {{ block.super }} {% for team in teams %} - + {{ team.name }} Team @@ -72,15 +72,15 @@ Teams | {{ block.super }} {% if request.user in team.members.all %} - Leave + Leave {% else %} {% if team.needs_members %} - Join + Join {% endif %} {% endif %} {% if request.user in team.responsible.all %} - Manage + Manage {% endif %} {% endif %} diff --git a/src/teams/templates/teammember_approve.html b/src/teams/templates/teammember_approve.html index c25b0ff6..b74afedc 100644 --- a/src/teams/templates/teammember_approve.html +++ b/src/teams/templates/teammember_approve.html @@ -13,6 +13,6 @@ Approve team member {{ teammember.user.profile.name }} for the {{ teammember.tea {% csrf_token %} {{ form }} - Cancel + Cancel {% endblock %} diff --git a/src/teams/templates/teammember_remove.html b/src/teams/templates/teammember_remove.html index d0288437..82b7dd4c 100644 --- a/src/teams/templates/teammember_remove.html +++ b/src/teams/templates/teammember_remove.html @@ -13,6 +13,6 @@ Remove member {{ teammember.user.profile.name }} from the {{ teammember.team.nam {% csrf_token %} {{ form }} - Cancel + Cancel {% endblock %} diff --git a/src/teams/urls.py b/src/teams/urls.py index 3c479bca..2ee14a34 100644 --- a/src/teams/urls.py +++ b/src/teams/urls.py @@ -1,4 +1,4 @@ -from django.conf.urls import url +from django.conf.urls import url, include from .views import * urlpatterns = [ @@ -8,40 +8,56 @@ urlpatterns = [ name='list' ), url( - r'^members/(?P[0-9]+)/remove/$', - TeamMemberRemoveView.as_view(), - name='teammember_remove', + r'^members/', include([ + url( + r'^(?P[0-9]+)/remove/$', + TeamMemberRemoveView.as_view(), + name='teammember_remove', + ), + url( + r'^(?P[0-9]+)/approve/$', + TeamMemberApproveView.as_view(), + name='teammember_approve', + ), + ]), ), url( - r'^members/(?P[0-9]+)/approve/$', - TeamMemberApproveView.as_view(), - name='teammember_approve', - ), - url( - r'(?P[-_\w+]+)/tasks/(?P[-_\w+]+)/$', - TaskDetailView.as_view(), - name='task_detail', - ), - url( - r'(?P[-_\w+]+)/join/$', - TeamJoinView.as_view(), - name='join' - ), - url( - r'(?P[-_\w+]+)/leave/$', - TeamLeaveView.as_view(), - name='leave' - ), - url( - r'(?P[-_\w+]+)/manage/$', - TeamManageView.as_view(), - name='manage' - ), - # this has to be the last url in the list - url( - r'(?P[-_\w+]+)/$', - TeamDetailView.as_view(), - name='detail' + r'^(?P[-_\w+]+)/', include([ + url( + r'^$', + TeamDetailView.as_view(), + name='detail' + ), + url( + r'^join/$', + TeamJoinView.as_view(), + name='join' + ), + url( + r'^leave/$', + TeamLeaveView.as_view(), + name='leave' + ), + url( + r'^manage/$', + TeamManageView.as_view(), + name='manage' + ), + url( + r'^tasks/', include([ + url( + r'^create/$', + TaskCreateView.as_view(), + name='task_create', + ), + url( + r'^(?P[-_\w+]+)/$', + TaskDetailView.as_view(), + name='task_detail', + ), + ]), + ), + ]), ), ] diff --git a/src/teams/views.py b/src/teams/views.py index 96be4e33..a856d71c 100644 --- a/src/teams/views.py +++ b/src/teams/views.py @@ -1,5 +1,5 @@ from django.views.generic import ListView, DetailView -from django.views.generic.edit import UpdateView, FormView +from django.views.generic.edit import CreateView, UpdateView, FormView from camps.mixins import CampViewMixin from .models import Team, TeamMember, TeamTask from .forms import ManageTeamForm @@ -18,12 +18,10 @@ logger = logging.getLogger("bornhack.%s" % __name__) class EnsureTeamResponsibleMixin(SingleObjectMixin): - model = Team - def dispatch(self, request, *args, **kwargs): if request.user not in self.get_object().responsible.all(): messages.error(request, 'No thanks') - return redirect('team_detail', camp_slug=self.camp.slug, slug=self.get_object().slug) + return redirect('teams:detail', camp_slug=self.camp.slug, team_slug=self.get_object().slug) return super().dispatch( request, *args, **kwargs @@ -40,21 +38,24 @@ class TeamDetailView(CampViewMixin, DetailView): template_name = "team_detail.html" context_object_name = 'team' model = Team + slug_url_kwarg = 'team_slug' class TeamManageView(CampViewMixin, EnsureTeamResponsibleMixin, UpdateView): model = Team template_name = "team_manage.html" fields = ['description', 'needs_members'] + slug_url_kwarg = 'team_slug' def get_success_url(self): - return reverse_lazy('team_detail', kwargs={'camp_slug': self.camp.slug, 'slug': self.get_object().slug}) + return reverse_lazy('teams:detail', kwargs={'camp_slug': self.camp.slug, 'slug': self.get_object().slug}) class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView): template_name = "team_join.html" model = Team fields = [] + slug_url_kwarg = 'team_slug' def get(self, request, *args, **kwargs): if not Profile.objects.get(user=request.user).description: @@ -84,6 +85,7 @@ class TeamLeaveView(LoginRequiredMixin, CampViewMixin, UpdateView): template_name = "team_leave.html" model = Team fields = [] + slug_url_kwarg = 'team_slug' def get(self, request, *args, **kwargs): if request.user not in self.get_object().members.all(): @@ -104,7 +106,7 @@ class EnsureTeamMemberResponsibleMixin(SingleObjectMixin): def dispatch(self, request, *args, **kwargs): if request.user not in self.get_object().team.responsible.all(): messages.error(request, 'No thanks') - return redirect('team_detail', camp_slug=self.get_object().team.camp.slug, slug=self.get_object().team.slug) + return redirect('teams:detail', camp_slug=self.get_object().team.camp.slug, team_slug=self.get_object().team.slug) return super().dispatch( request, *args, **kwargs @@ -125,7 +127,7 @@ class TeamMemberRemoveView(LoginRequiredMixin, CampViewMixin, EnsureTeamMemberRe logger.error( 'Unable to add removed email to outgoing queue for teammember: {}'.format(form.instance) ) - return redirect('team_detail', camp_slug=self.camp.slug, slug=form.instance.team.slug) + return redirect('teams:detail', camp_slug=self.camp.slug, team_slug=form.instance.team.slug) class TeamMemberApproveView(LoginRequiredMixin, CampViewMixin, EnsureTeamMemberResponsibleMixin, UpdateView): @@ -143,7 +145,7 @@ class TeamMemberApproveView(LoginRequiredMixin, CampViewMixin, EnsureTeamMemberR logger.error( 'Unable to add approved email to outgoing queue for teammember: {}'.format(form.instance) ) - return redirect('team_detail', camp_slug=self.camp.slug, slug=form.instance.team.slug) + return redirect('teams:detail', camp_slug=self.camp.slug, team_slug=form.instance.team.slug) class TaskDetailView(CampViewMixin, DetailView): @@ -151,3 +153,18 @@ class TaskDetailView(CampViewMixin, DetailView): context_object_name = "task" model = TeamTask + +class TaskCreateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMixin, CreateView): + model = TeamTask + template_name = "task_create.html" + fields = ['name', 'description'] + + 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}) +