From da75660f0d3648332ae5ec808d48b36650596c64 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Sat, 4 Aug 2018 13:45:52 +0200 Subject: [PATCH] Final touches - I think. --- src/teams/templates/team_base.html | 24 ++++++--- src/teams/templates/team_info_categories.html | 4 -- ...tml => team_info_item_delete_confirm.html} | 4 +- ...tem_form.html => team_info_item_form.html} | 6 ++- src/teams/templates/team_members.html | 16 +++--- src/teams/urls.py | 41 +++++++++------ src/teams/views/base.py | 1 + src/teams/views/info.py | 51 +++++++++++++++++-- src/teams/views/members.py | 5 ++ src/teams/views/tasks.py | 4 ++ 10 files changed, 114 insertions(+), 42 deletions(-) rename src/teams/templates/{info_item_delete_confirm.html => team_info_item_delete_confirm.html} (93%) rename src/teams/templates/{info_item_form.html => team_info_item_form.html} (95%) diff --git a/src/teams/templates/team_base.html b/src/teams/templates/team_base.html index 1a56fa5d..8ef87216 100644 --- a/src/teams/templates/team_base.html +++ b/src/teams/templates/team_base.html @@ -16,19 +16,13 @@ Team: {{ team.name }} | {{ block.super }}

diff --git a/src/teams/templates/team_info_categories.html b/src/teams/templates/team_info_categories.html index 0490b787..15f0900c 100644 --- a/src/teams/templates/team_info_categories.html +++ b/src/teams/templates/team_info_categories.html @@ -6,10 +6,6 @@ {% block team_content %} -{% if request.user in team.responsible_members.all and team.info_categories.exists %} -

SHOULD NOT HAPPEN !!!

-{% endif %} -

Info Categories

diff --git a/src/teams/templates/info_item_delete_confirm.html b/src/teams/templates/team_info_item_delete_confirm.html similarity index 93% rename from src/teams/templates/info_item_delete_confirm.html rename to src/teams/templates/team_info_item_delete_confirm.html index fe9f2403..18e6e28b 100644 --- a/src/teams/templates/info_item_delete_confirm.html +++ b/src/teams/templates/team_info_item_delete_confirm.html @@ -1,4 +1,4 @@ -{% extends 'base.html' %} +{% extends 'team_base.html' %} {% load commonmark %} {% load bootstrap3 %} @@ -11,7 +11,7 @@ Create Info item in {{ form.instance.category.headline }} {% endblock %} -{% block content %} +{% block team_content %}

diff --git a/src/teams/templates/info_item_form.html b/src/teams/templates/team_info_item_form.html similarity index 95% rename from src/teams/templates/info_item_form.html rename to src/teams/templates/team_info_item_form.html index 26327630..e062ae9d 100644 --- a/src/teams/templates/info_item_form.html +++ b/src/teams/templates/team_info_item_form.html @@ -5,10 +5,11 @@ {% block title %} {% if object %} Editing "{{ object.headline }}" +in "{{ form.instance.category.headline }}" {% else %} Create Info item +in "{{ category.headline }}" {% endif %} -in "{{ form.instance.category.headline }}" {% endblock %} {% block team_content %} @@ -17,10 +18,11 @@ in "{{ form.instance.category.headline }}"

{% if object %} Editing "{{ object.headline }}" + in "{{ object.category.headline }}" {% else %} Create Info Item + in "{{ category.headline }}" {% endif %} - in "{{ object.category.headline }}"

diff --git a/src/teams/templates/team_members.html b/src/teams/templates/team_members.html index 49a1e25a..b3fef15a 100644 --- a/src/teams/templates/team_members.html +++ b/src/teams/templates/team_members.html @@ -29,25 +29,26 @@ - {% for teammember in team.memberships.all %} + {% for member in team.memberships.all %} + {% if member.approved or not member.approved and request.user in team.responsible_members.all %} - {{ teammember.user.profile.get_public_credit_name }} {% if teammember.user == request.user %}(this is you!){% endif %} + {{ member.user.profile.get_public_credit_name }} {% if member.user == request.user %}(this is you!){% endif %} - Team {% if teammember.responsible %}Responsible{% else %}Member{% endif %} - {% if not teammember.approved %}(pending approval){% endif %} + Team {% if member.responsible %}Responsible{% else %}Member{% endif %} + {% if not member.approved %}(pending approval){% endif %} {% if request.user in team.responsible_members.all %}
+ href="{% url 'teams:member_remove' camp_slug=camp.slug team_slug=team.slug pk=member.id %}"> Remove - {% if not teammember.approved %} + {% if not member.approved %} + href="{% url 'teams:member_approve' camp_slug=camp.slug team_slug=team.slug pk=member.id %}"> Approve {% endif %} @@ -55,6 +56,7 @@ {% endif %} + {% endif %} {% empty %}

No members found!

{% endfor %} diff --git a/src/teams/urls.py b/src/teams/urls.py index 6c5adfd5..b4def544 100644 --- a/src/teams/urls.py +++ b/src/teams/urls.py @@ -16,6 +16,7 @@ from teams.views.members import ( ) from teams.views.info import ( + InfoCategoriesListView, InfoItemUpdateView, InfoItemCreateView, InfoItemDeleteView, @@ -73,12 +74,12 @@ urlpatterns = [ path( '/remove/', TeamMemberRemoveView.as_view(), - name='teammember_remove', + name='member_remove', ), path( '/approve/', TeamMemberApproveView.as_view(), - name='teammember_approve', + name='member_approve', ), ]), ), @@ -112,26 +113,36 @@ urlpatterns = [ ]), ), path( - 'info//', include([ + 'info/', + include([ path( - 'create/', - InfoItemCreateView.as_view(), - name='info_item_create', + '', + InfoCategoriesListView.as_view(), + name='info_categories' ), path( - '/', include([ + '/', include([ path( - 'update/', - InfoItemUpdateView.as_view(), - name='info_item_update', + 'create/', + InfoItemCreateView.as_view(), + name='info_item_create', ), path( - 'delete/', - InfoItemDeleteView.as_view(), - name='info_item_delete', + '/', include([ + path( + 'update/', + InfoItemUpdateView.as_view(), + name='info_item_update', + ), + path( + 'delete/', + InfoItemDeleteView.as_view(), + name='info_item_delete', + ), + ]), ), - ]), - ), + ]) + ) ]) ) ]), diff --git a/src/teams/views/base.py b/src/teams/views/base.py index 06c928e1..cce95e70 100644 --- a/src/teams/views/base.py +++ b/src/teams/views/base.py @@ -25,6 +25,7 @@ class TeamGeneralView(CampViewMixin, DetailView): context_object_name = 'team' model = Team slug_url_kwarg = 'team_slug' + active_menu = 'general' def get_context_data(self, **kwargs): context = super().get_context_data(**kwargs) diff --git a/src/teams/views/info.py b/src/teams/views/info.py index f2da0bcb..0d49162d 100644 --- a/src/teams/views/info.py +++ b/src/teams/views/info.py @@ -1,18 +1,39 @@ from django.contrib.auth.mixins import LoginRequiredMixin from django.http import HttpResponseRedirect -from django.views.generic import CreateView, UpdateView, DeleteView +from django.views.generic import CreateView, UpdateView, DeleteView, ListView from reversion.views import RevisionMixin from camps.mixins import CampViewMixin from info.models import InfoItem, InfoCategory +from ..models import Team from .mixins import EnsureTeamResponsibleMixin, TeamViewMixin +class InfoCategoriesListView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, ListView): + model = InfoCategory + template_name = "team_info_categories.html" + slug_field = 'anchor' + active_menu = 'info_categories' + + def get_team(self): + return Team.objects.get( + camp__slug=self.kwargs['camp_slug'], + slug=self.kwargs['team_slug'] + ) + + class InfoItemCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, CreateView): model = InfoItem - template_name = "info_item_form.html" + template_name = "team_info_item_form.html" fields = ['headline', 'body', 'anchor', 'weight'] slug_field = 'anchor' + active_menu = 'info_categories' + + def get_team(self): + return Team.objects.get( + camp__slug=self.kwargs['camp_slug'], + slug=self.kwargs['team_slug'] + ) def form_valid(self, form): info_item = form.save(commit=False) @@ -24,13 +45,28 @@ class InfoItemCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, Ensur def get_success_url(self): return self.team.get_absolute_url() + def get_context_data(self, **kwargs): + context = super().get_context_data(**kwargs) + context['category'] = InfoCategory.objects.get( + team__camp__slug=self.kwargs['camp_slug'], + anchor=self.kwargs['category_anchor'] + ) + return context + class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, UpdateView): model = InfoItem - template_name = "info_item_form.html" + template_name = "team_info_item_form.html" fields = ['headline', 'body', 'anchor', 'weight'] slug_field = 'anchor' slug_url_kwarg = 'item_anchor' + active_menu = 'info_categories' + + def get_team(self): + return Team.objects.get( + camp__slug=self.kwargs['camp_slug'], + slug=self.kwargs['team_slug'] + ) def get_success_url(self): next = self.request.GET.get('next') @@ -41,9 +77,16 @@ class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, Ensur class InfoItemDeleteView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, DeleteView): model = InfoItem - template_name = "info_item_delete_confirm.html" + template_name = "team_info_item_delete_confirm.html" slug_field = 'anchor' slug_url_kwarg = 'item_anchor' + active_menu = 'info_categories' + + def get_team(self): + return Team.objects.get( + camp__slug=self.kwargs['camp_slug'], + slug=self.kwargs['team_slug'] + ) def get_success_url(self): next = self.request.GET.get('next') diff --git a/src/teams/views/members.py b/src/teams/views/members.py index cbd03e00..8d050504 100644 --- a/src/teams/views/members.py +++ b/src/teams/views/members.py @@ -20,6 +20,7 @@ class TeamMembersView(CampViewMixin, DetailView): context_object_name = 'team' model = Team slug_url_kwarg = 'team_slug' + active_menu = 'members' class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView): @@ -27,6 +28,7 @@ class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView): model = Team fields = [] slug_url_kwarg = 'team_slug' + active_menu = 'members' def get(self, request, *args, **kwargs): if not Profile.objects.get(user=request.user).description: @@ -57,6 +59,7 @@ class TeamLeaveView(LoginRequiredMixin, CampViewMixin, UpdateView): model = Team fields = [] slug_url_kwarg = 'team_slug' + active_menu = 'members' def get(self, request, *args, **kwargs): if request.user not in self.get_object().members.all(): @@ -75,6 +78,7 @@ class TeamMemberRemoveView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, Ens template_name = "teammember_remove.html" model = TeamMember fields = [] + active_menu = 'members' def form_valid(self, form): form.instance.delete() @@ -92,6 +96,7 @@ class TeamMemberApproveView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, En template_name = "teammember_approve.html" model = TeamMember fields = [] + active_menu = 'members' def form_valid(self, form): form.instance.approved = True diff --git a/src/teams/views/tasks.py b/src/teams/views/tasks.py index d18c2465..02b5ba29 100644 --- a/src/teams/views/tasks.py +++ b/src/teams/views/tasks.py @@ -12,18 +12,21 @@ class TeamTasksView(CampViewMixin, DetailView): context_object_name = 'team' model = Team slug_url_kwarg = 'team_slug' + active_menu = 'tasks' class TaskDetailView(CampViewMixin, TeamViewMixin, DetailView): template_name = "task_detail.html" context_object_name = "task" model = TeamTask + active_menu = 'tasks' class TaskCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, CreateView): model = TeamTask template_name = "task_form.html" fields = ['name', 'description'] + active_menu = 'tasks' def get_team(self): return Team.objects.get( @@ -47,6 +50,7 @@ class TaskUpdateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTea model = TeamTask template_name = "task_form.html" fields = ['name', 'description'] + active_menu = 'tasks' def get_context_data(self, *args, **kwargs): context = super().get_context_data(**kwargs)