diff --git a/src/teams/models.py b/src/teams/models.py index 843c7f0e..bbfc14b3 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -6,6 +6,7 @@ from utils.models import CampRelatedModel from .email import add_new_membership_email from django.core.exceptions import ValidationError from django.contrib.auth.models import User +from django.core.urlresolvers import reverse_lazy import logging logger = logging.getLogger("bornhack.%s" % __name__) @@ -140,14 +141,16 @@ class TeamTask(CampRelatedModel): ordering = ['name'] unique_together = (('name', 'team'), ('slug', 'team')) + def get_absolute_url(self): + return reverse_lazy('teams:task_detail', kwargs={'camp_slug': self.team.camp.slug, 'team_slug': self.team.slug, 'slug': self.slug}) + @property def camp(self): return self.team.camp def save(self, **kwargs): if not self.slug: - slug = slugify(self.name) - self.slug = slug + self.slug = slugify(self.name) super().save(**kwargs) @property diff --git a/src/teams/templates/task_create.html b/src/teams/templates/task_create.html deleted file mode 100644 index 536eec60..00000000 --- a/src/teams/templates/task_create.html +++ /dev/null @@ -1,20 +0,0 @@ -{% 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_form.html b/src/teams/templates/task_form.html new file mode 100644 index 00000000..c03e64c6 --- /dev/null +++ b/src/teams/templates/task_form.html @@ -0,0 +1,36 @@ +{% extends 'base.html' %} +{% load commonmark %} +{% load bootstrap3 %} + +{% block title %} +{% if form.instance.id %} +Edit Task: {{ form.instance.name }} +{% else %} +Create Task +{% endif %} +for {{ team.name }} Team +{% endblock %} + +{% block content %} +
+
+

+ {% if form.instance.id %} + Edit Task: {{ form.instance.name }} + {% else %} + Create Task + {% endif %} + for {{ team.name }} Team +

+
+
+
+ {% csrf_token %} + {% bootstrap_form form %} + +
+
+ +
+{% endblock %} + diff --git a/src/teams/templates/team_detail.html b/src/teams/templates/team_detail.html index 492b499c..1273043d 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 %}
@@ -71,18 +71,25 @@ Team: {{ team.name }} | {{ block.super }} Name Description + Action {% for task in team.tasks.all %} {{ task.name }} - {{ task.description }} + {{ task.description }} + + Details + Edit Task + {% endfor %} - + {% if request.user in team.responsible.all %} + Create Task + {% endif %}
diff --git a/src/teams/urls.py b/src/teams/urls.py index 2ee14a34..28072dbe 100644 --- a/src/teams/urls.py +++ b/src/teams/urls.py @@ -51,10 +51,20 @@ urlpatterns = [ name='task_create', ), url( - r'^(?P[-_\w+]+)/$', - TaskDetailView.as_view(), - name='task_detail', + r'^(?P[-_\w+]+)/', include([ + url( + r'^$', + TaskDetailView.as_view(), + name='task_detail', + ), + url( + r'^update/$', + TaskUpdateView.as_view(), + name='task_update', + ), + ]), ), + ]), ), ]), diff --git a/src/teams/views.py b/src/teams/views.py index 17152a2d..d5937e00 100644 --- a/src/teams/views.py +++ b/src/teams/views.py @@ -157,7 +157,7 @@ class TaskDetailView(CampViewMixin, DetailView): class TaskCreateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMixin, CreateView): model = TeamTask - template_name = "task_create.html" + template_name = "task_form.html" fields = ['name', 'description'] def get_context_data(self, *args, **kwargs): @@ -165,13 +165,36 @@ class TaskCreateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMix 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 - } - ) + def form_valid(self, form): + task = form.save(commit=False) + task.team = self.team + if not task.name: + task.name = "noname" + task.save() + return HttpResponseRedirect(task.get_absolute_url()) + + def get_success_url(self): + return self.get_object().get_absolute_url() + + +class TaskUpdateView(LoginRequiredMixin, CampViewMixin, EnsureTeamResponsibleMixin, UpdateView): + model = TeamTask + template_name = "task_form.html" + fields = ['name', 'description'] + + def get_context_data(self, *args, **kwargs): + context = super().get_context_data(**kwargs) + context['team'] = self.team + return context + + def form_valid(self, form): + task = form.save(commit=False) + task.team = self.team + if not task.name: + task.name = "noname" + task.save() + return HttpResponseRedirect(task.get_absolute_url()) + + def get_success_url(self): + return self.get_object().get_absolute_url()