diff --git a/src/teams/migrations/0047_taskcomment.py b/src/teams/migrations/0047_taskcomment.py new file mode 100644 index 00000000..3dc0eada --- /dev/null +++ b/src/teams/migrations/0047_taskcomment.py @@ -0,0 +1,29 @@ +# Generated by Django 2.1 on 2018-08-14 17:42 + +from django.db import migrations, models +import django.db.models.deletion +import uuid + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0046_auto_20180808_2154'), + ] + + operations = [ + migrations.CreateModel( + name='TaskComment', + fields=[ + ('uuid', models.UUIDField(default=uuid.uuid4, editable=False, primary_key=True, serialize=False)), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('content', models.TextField()), + ('author', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to='teams.TeamMember')), + ('task', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='comments', to='teams.TeamTask')), + ], + options={ + 'abstract': False, + }, + ), + ] diff --git a/src/teams/migrations/0048_auto_20180814_1950.py b/src/teams/migrations/0048_auto_20180814_1950.py new file mode 100644 index 00000000..c59f9f8c --- /dev/null +++ b/src/teams/migrations/0048_auto_20180814_1950.py @@ -0,0 +1,18 @@ +# Generated by Django 2.1 on 2018-08-14 17:50 + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0047_taskcomment'), + ] + + operations = [ + migrations.RenameField( + model_name='taskcomment', + old_name='content', + new_name='comment', + ), + ] diff --git a/src/teams/models.py b/src/teams/models.py index f78aba71..f0664dc2 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -9,7 +9,7 @@ from django.urls import reverse_lazy from django.conf import settings from django.contrib.postgres.fields import DateTimeRangeField -from utils.models import CampRelatedModel +from utils.models import CampRelatedModel, CreatedUpdatedModel, UUIDModel logger = logging.getLogger("bornhack.%s" % __name__) @@ -320,6 +320,12 @@ class TeamTask(CampRelatedModel): super().save(**kwargs) +class TaskComment(UUIDModel, CreatedUpdatedModel): + task = models.ForeignKey('teams.TeamTask', on_delete=models.PROTECT, related_name="comments") + author = models.ForeignKey('teams.TeamMember', on_delete=models.PROTECT) + comment = models.TextField() + + class TeamShift(CampRelatedModel): class Meta: diff --git a/src/teams/templates/task_detail.html b/src/teams/templates/task_detail.html index 6e346877..c650ebb3 100644 --- a/src/teams/templates/task_detail.html +++ b/src/teams/templates/task_detail.html @@ -1,5 +1,6 @@ {% extends 'team_base.html' %} {% load commonmark %} +{% load bootstrap3 %} {% block title %} {{ task.name }} @@ -16,7 +17,31 @@
  • Finish: {{ task.when.upper|default:"N/A" }}
    - + {% if user in task.team.members.all %} + +
    + +
    +
    + {% csrf_token %} + {% bootstrap_form comment_form %} + + +
    +
    + {% endif %} diff --git a/src/teams/views/tasks.py b/src/teams/views/tasks.py index aaaed31b..da21f7bd 100644 --- a/src/teams/views/tasks.py +++ b/src/teams/views/tasks.py @@ -1,10 +1,12 @@ +from django.contrib import messages from django.contrib.auth.mixins import LoginRequiredMixin -from django.http import HttpResponseRedirect +from django.http import HttpResponseRedirect, HttpResponseNotAllowed from django.views.generic import DetailView, CreateView, UpdateView from django import forms +from django.views.generic.edit import ProcessFormView from camps.mixins import CampViewMixin -from ..models import Team, TeamTask +from ..models import Team, TeamTask, TaskComment, TeamMember from .mixins import EnsureTeamResponsibleMixin, TeamViewMixin @@ -16,12 +18,39 @@ class TeamTasksView(CampViewMixin, DetailView): active_menu = 'tasks' +class TaskCommentForm(forms.ModelForm): + class Meta: + model = TaskComment + fields = ['comment'] + + class TaskDetailView(CampViewMixin, TeamViewMixin, DetailView): template_name = "task_detail.html" context_object_name = "task" model = TeamTask active_menu = 'tasks' + def get_context_data(self, *args, **kwargs): + context = super().get_context_data(*args, **kwargs) + context['comment_form'] = TaskCommentForm() + return context + + def post(self, request, **kwargs): + task = self.get_object() + if request.user not in task.team.members.all(): + return HttpResponseNotAllowed('Nope') + + form = TaskCommentForm(request.POST) + if form.is_valid(): + comment = form.save(commit=False) + comment.author = TeamMember.objects.get(user=request.user, team=task.team) + comment.task = task + comment.save() + else: + messages.error(request, "Something went wrong.") + + return HttpResponseRedirect(task.get_absolute_url()) + class TaskForm(forms.ModelForm): class Meta: