create and edit tasks
This commit is contained in:
parent
c20771da8a
commit
4dab2c1a4f
|
@ -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
|
||||
|
|
|
@ -1,20 +0,0 @@
|
|||
{% extends 'base.html' %}
|
||||
{% load commonmark %}
|
||||
|
||||
{% block title %}
|
||||
Create Task for {{ task.team.name }} Team
|
||||
{% endblock %}
|
||||
|
||||
{% block content %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading"><h4>Create Task</h4></div>
|
||||
<div class="panel-body">
|
||||
<form method="POST">
|
||||
{{ form }}
|
||||
<button type="submit" class="btn btn-primary">
|
||||
</form>
|
||||
</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 %}
|
||||
|
36
src/teams/templates/task_form.html
Normal file
36
src/teams/templates/task_form.html
Normal file
|
@ -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 %}
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<h4>
|
||||
{% if form.instance.id %}
|
||||
Edit Task: {{ form.instance.name }}
|
||||
{% else %}
|
||||
Create Task
|
||||
{% endif %}
|
||||
for {{ team.name }} Team
|
||||
</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<form method="POST">
|
||||
{% csrf_token %}
|
||||
{% bootstrap_form form %}
|
||||
<button type="submit" class="btn btn-primary">{% if form.instance.id %}Save{% else %}Create{% endif %}</button>
|
||||
</form>
|
||||
</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 %}
|
||||
|
|
@ -14,7 +14,7 @@ Team: {{ team.name }} | {{ block.super }}
|
|||
<div class="panel-body">
|
||||
{{ team.description|unsafecommonmark }}
|
||||
{% if request.user in team.responsible.all %}
|
||||
<a href="{% url 'teams:manage' camp_slug=camp.slug team_slug=team.slug %}" class="btn btn-success">Manage Team</a>
|
||||
<a href="{% url 'teams:manage' camp_slug=camp.slug team_slug=team.slug %}" class="btn btn-primary">Manage Team</a>
|
||||
{% endif %}
|
||||
|
||||
<hr>
|
||||
|
@ -71,6 +71,7 @@ Team: {{ team.name }} | {{ block.super }}
|
|||
<tr>
|
||||
<th>Name</th>
|
||||
<th>Description</th>
|
||||
<th>Action</th>
|
||||
</tr>
|
||||
</thead>
|
||||
<tbody>
|
||||
|
@ -78,11 +79,17 @@ Team: {{ team.name }} | {{ block.super }}
|
|||
<tr>
|
||||
<td><a href="{% url 'teams:task_detail' slug=task.slug camp_slug=camp.slug team_slug=team.slug %}">{{ task.name }}</a></td>
|
||||
<td>{{ task.description }}</td>
|
||||
<td>
|
||||
<a href="{% url 'teams:task_detail' camp_slug=camp.slug team_slug=team.slug slug=task.slug %}" class="btn btn-primary btn-sm">Details</a>
|
||||
<a href="{% url 'teams:task_update' camp_slug=camp.slug team_slug=team.slug slug=task.slug %}" class="btn btn-primary btn-sm">Edit Task</a>
|
||||
</td>
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if request.user in team.responsible.all %}
|
||||
<a href="{% url 'teams:task_create' camp_slug=camp.slug team_slug=team.slug %}" class="btn btn-primary">Create Task</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
|
|
@ -51,10 +51,20 @@ urlpatterns = [
|
|||
name='task_create',
|
||||
),
|
||||
url(
|
||||
r'^(?P<slug>[-_\w+]+)/$',
|
||||
r'^(?P<slug>[-_\w+]+)/', include([
|
||||
url(
|
||||
r'^$',
|
||||
TaskDetailView.as_view(),
|
||||
name='task_detail',
|
||||
),
|
||||
url(
|
||||
r'^update/$',
|
||||
TaskUpdateView.as_view(),
|
||||
name='task_update',
|
||||
),
|
||||
]),
|
||||
),
|
||||
|
||||
]),
|
||||
),
|
||||
]),
|
||||
|
|
|
@ -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()
|
||||
|
||||
|
|
Loading…
Reference in a new issue