Final touches - I think.

This commit is contained in:
Víðir Valberg Guðmundsson 2018-08-04 13:45:52 +02:00
parent d08c299e8d
commit da75660f0d
10 changed files with 114 additions and 42 deletions

View file

@ -16,19 +16,13 @@ Team: {{ team.name }} | {{ block.super }}
<div class="row"> <div class="row">
<div class="col-md-2"> <div class="col-md-2">
<ul class="nav nav-pills nav-stacked"> <ul class="nav nav-pills nav-stacked">
<li {% if view.template_name == "team_general.html" %}class="active"{% endif %}> <li {% if view.active_menu == "general" %}class="active"{% endif %}>
<a href="{% url "teams:general" camp_slug=team.camp.slug team_slug=team.slug %}"> <a href="{% url "teams:general" camp_slug=team.camp.slug team_slug=team.slug %}">
General General
</a> </a>
</li> </li>
<li {% if view.template_name == "team_tasks.html" %}class="active"{% endif %}> <li {% if view.active_menu == "members" %}class="active"{% endif %}>
<a href="{% url "teams:tasks" camp_slug=team.camp.slug team_slug=team.slug %}">
Tasks
</a>
</li>
<li {% if view.template_name == "team_members.html" %}class="active"{% endif %}>
<a href="{% url "teams:members" camp_slug=team.camp.slug team_slug=team.slug %}"> <a href="{% url "teams:members" camp_slug=team.camp.slug team_slug=team.slug %}">
Members Members
{% if request.user in team.responsible_members.all and team.unapproved_members %} {% if request.user in team.responsible_members.all and team.unapproved_members %}
@ -37,6 +31,20 @@ Team: {{ team.name }} | {{ block.super }}
</a> </a>
</li> </li>
<li {% if view.active_menu == "tasks" %}class="active"{% endif %}>
<a href="{% url "teams:tasks" camp_slug=team.camp.slug team_slug=team.slug %}">
Tasks
</a>
</li>
{% if request.user in team.responsible_members.all %}
<li {% if view.active_menu == "info_categories" %}class="active"{% endif %}>
<a href="{% url "teams:info_categories" camp_slug=team.camp.slug team_slug=team.slug %}">
Info categories
</a>
</li>
{% endif %}
</ul> </ul>
<hr /> <hr />

View file

@ -6,10 +6,6 @@
{% block team_content %} {% block team_content %}
{% if request.user in team.responsible_members.all and team.info_categories.exists %}
<h4> SHOULD NOT HAPPEN !!! </h4>
{% endif %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h4>Info Categories</h4> <h4>Info Categories</h4>

View file

@ -1,4 +1,4 @@
{% extends 'base.html' %} {% extends 'team_base.html' %}
{% load commonmark %} {% load commonmark %}
{% load bootstrap3 %} {% load bootstrap3 %}
@ -11,7 +11,7 @@ Create Info item
in {{ form.instance.category.headline }} in {{ form.instance.category.headline }}
{% endblock %} {% endblock %}
{% block content %} {% block team_content %}
<div class="panel panel-default"> <div class="panel panel-default">
<div class="panel-heading"> <div class="panel-heading">
<h4> <h4>

View file

@ -5,10 +5,11 @@
{% block title %} {% block title %}
{% if object %} {% if object %}
Editing "{{ object.headline }}" Editing "{{ object.headline }}"
in "{{ form.instance.category.headline }}"
{% else %} {% else %}
Create Info item Create Info item
in "{{ category.headline }}"
{% endif %} {% endif %}
in "{{ form.instance.category.headline }}"
{% endblock %} {% endblock %}
{% block team_content %} {% block team_content %}
@ -17,10 +18,11 @@ in "{{ form.instance.category.headline }}"
<h4> <h4>
{% if object %} {% if object %}
Editing "{{ object.headline }}" Editing "{{ object.headline }}"
in "{{ object.category.headline }}"
{% else %} {% else %}
Create Info Item Create Info Item
in "{{ category.headline }}"
{% endif %} {% endif %}
in "{{ object.category.headline }}"
</h4> </h4>
</div> </div>
<div class="panel-body"> <div class="panel-body">

View file

@ -29,25 +29,26 @@
</tr> </tr>
</thead> </thead>
<tbody> <tbody>
{% 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 %}
<tr> <tr>
<td> <td>
{{ 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 %}
</td> </td>
<td> <td>
Team {% if teammember.responsible %}Responsible{% else %}Member{% endif %} Team {% if member.responsible %}Responsible{% else %}Member{% endif %}
{% if not teammember.approved %}(pending approval){% endif %} {% if not member.approved %}(pending approval){% endif %}
</td> </td>
{% if request.user in team.responsible_members.all %} {% if request.user in team.responsible_members.all %}
<td> <td>
<div class="btn-group-vertical"> <div class="btn-group-vertical">
<a class="btn btn-danger" <a class="btn btn-danger"
href="{% url 'teams:teammember_remove' camp_slug=camp.slug team_slug=team.slug pk=teammember.id %}"> href="{% url 'teams:member_remove' camp_slug=camp.slug team_slug=team.slug pk=member.id %}">
<i class="fas fa-trash"></i> Remove <i class="fas fa-trash"></i> Remove
</a> </a>
{% if not teammember.approved %} {% if not member.approved %}
<a class="btn btn-success" <a class="btn btn-success"
href="{% url 'teams:teammember_approve' camp_slug=camp.slug team_slug=team.slug pk=teammember.id %}"> href="{% url 'teams:member_approve' camp_slug=camp.slug team_slug=team.slug pk=member.id %}">
<i class="fas fa-check"></i> Approve <i class="fas fa-check"></i> Approve
</a> </a>
{% endif %} {% endif %}
@ -55,6 +56,7 @@
</td> </td>
{% endif %} {% endif %}
</tr> </tr>
{% endif %}
{% empty %} {% empty %}
<p>No members found!</p> <p>No members found!</p>
{% endfor %} {% endfor %}

View file

@ -16,6 +16,7 @@ from teams.views.members import (
) )
from teams.views.info import ( from teams.views.info import (
InfoCategoriesListView,
InfoItemUpdateView, InfoItemUpdateView,
InfoItemCreateView, InfoItemCreateView,
InfoItemDeleteView, InfoItemDeleteView,
@ -73,12 +74,12 @@ urlpatterns = [
path( path(
'<int:pk>/remove/', '<int:pk>/remove/',
TeamMemberRemoveView.as_view(), TeamMemberRemoveView.as_view(),
name='teammember_remove', name='member_remove',
), ),
path( path(
'<int:pk>/approve/', '<int:pk>/approve/',
TeamMemberApproveView.as_view(), TeamMemberApproveView.as_view(),
name='teammember_approve', name='member_approve',
), ),
]), ]),
), ),
@ -112,26 +113,36 @@ urlpatterns = [
]), ]),
), ),
path( path(
'info/<slug:category_anchor>/', include([ 'info/',
include([
path( path(
'create/', '',
InfoItemCreateView.as_view(), InfoCategoriesListView.as_view(),
name='info_item_create', name='info_categories'
), ),
path( path(
'<slug:item_anchor>/', include([ '<slug:category_anchor>/', include([
path( path(
'update/', 'create/',
InfoItemUpdateView.as_view(), InfoItemCreateView.as_view(),
name='info_item_update', name='info_item_create',
), ),
path( path(
'delete/', '<slug:item_anchor>/', include([
InfoItemDeleteView.as_view(), path(
name='info_item_delete', 'update/',
InfoItemUpdateView.as_view(),
name='info_item_update',
),
path(
'delete/',
InfoItemDeleteView.as_view(),
name='info_item_delete',
),
]),
), ),
]), ])
), )
]) ])
) )
]), ]),

View file

@ -25,6 +25,7 @@ class TeamGeneralView(CampViewMixin, DetailView):
context_object_name = 'team' context_object_name = 'team'
model = Team model = Team
slug_url_kwarg = 'team_slug' slug_url_kwarg = 'team_slug'
active_menu = 'general'
def get_context_data(self, **kwargs): def get_context_data(self, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)

View file

@ -1,18 +1,39 @@
from django.contrib.auth.mixins import LoginRequiredMixin from django.contrib.auth.mixins import LoginRequiredMixin
from django.http import HttpResponseRedirect 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 reversion.views import RevisionMixin
from camps.mixins import CampViewMixin from camps.mixins import CampViewMixin
from info.models import InfoItem, InfoCategory from info.models import InfoItem, InfoCategory
from ..models import Team
from .mixins import EnsureTeamResponsibleMixin, TeamViewMixin 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): class InfoItemCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, CreateView):
model = InfoItem model = InfoItem
template_name = "info_item_form.html" template_name = "team_info_item_form.html"
fields = ['headline', 'body', 'anchor', 'weight'] fields = ['headline', 'body', 'anchor', 'weight']
slug_field = 'anchor' 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): def form_valid(self, form):
info_item = form.save(commit=False) info_item = form.save(commit=False)
@ -24,13 +45,28 @@ class InfoItemCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, Ensur
def get_success_url(self): def get_success_url(self):
return self.team.get_absolute_url() 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): class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, UpdateView):
model = InfoItem model = InfoItem
template_name = "info_item_form.html" template_name = "team_info_item_form.html"
fields = ['headline', 'body', 'anchor', 'weight'] fields = ['headline', 'body', 'anchor', 'weight']
slug_field = 'anchor' slug_field = 'anchor'
slug_url_kwarg = 'item_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): def get_success_url(self):
next = self.request.GET.get('next') next = self.request.GET.get('next')
@ -41,9 +77,16 @@ class InfoItemUpdateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, Ensur
class InfoItemDeleteView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, DeleteView): class InfoItemDeleteView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, RevisionMixin, DeleteView):
model = InfoItem model = InfoItem
template_name = "info_item_delete_confirm.html" template_name = "team_info_item_delete_confirm.html"
slug_field = 'anchor' slug_field = 'anchor'
slug_url_kwarg = 'item_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): def get_success_url(self):
next = self.request.GET.get('next') next = self.request.GET.get('next')

View file

@ -20,6 +20,7 @@ class TeamMembersView(CampViewMixin, DetailView):
context_object_name = 'team' context_object_name = 'team'
model = Team model = Team
slug_url_kwarg = 'team_slug' slug_url_kwarg = 'team_slug'
active_menu = 'members'
class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView): class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView):
@ -27,6 +28,7 @@ class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView):
model = Team model = Team
fields = [] fields = []
slug_url_kwarg = 'team_slug' slug_url_kwarg = 'team_slug'
active_menu = 'members'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if not Profile.objects.get(user=request.user).description: if not Profile.objects.get(user=request.user).description:
@ -57,6 +59,7 @@ class TeamLeaveView(LoginRequiredMixin, CampViewMixin, UpdateView):
model = Team model = Team
fields = [] fields = []
slug_url_kwarg = 'team_slug' slug_url_kwarg = 'team_slug'
active_menu = 'members'
def get(self, request, *args, **kwargs): def get(self, request, *args, **kwargs):
if request.user not in self.get_object().members.all(): 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" template_name = "teammember_remove.html"
model = TeamMember model = TeamMember
fields = [] fields = []
active_menu = 'members'
def form_valid(self, form): def form_valid(self, form):
form.instance.delete() form.instance.delete()
@ -92,6 +96,7 @@ class TeamMemberApproveView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, En
template_name = "teammember_approve.html" template_name = "teammember_approve.html"
model = TeamMember model = TeamMember
fields = [] fields = []
active_menu = 'members'
def form_valid(self, form): def form_valid(self, form):
form.instance.approved = True form.instance.approved = True

View file

@ -12,18 +12,21 @@ class TeamTasksView(CampViewMixin, DetailView):
context_object_name = 'team' context_object_name = 'team'
model = Team model = Team
slug_url_kwarg = 'team_slug' slug_url_kwarg = 'team_slug'
active_menu = 'tasks'
class TaskDetailView(CampViewMixin, TeamViewMixin, DetailView): class TaskDetailView(CampViewMixin, TeamViewMixin, DetailView):
template_name = "task_detail.html" template_name = "task_detail.html"
context_object_name = "task" context_object_name = "task"
model = TeamTask model = TeamTask
active_menu = 'tasks'
class TaskCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, CreateView): class TaskCreateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTeamResponsibleMixin, CreateView):
model = TeamTask model = TeamTask
template_name = "task_form.html" template_name = "task_form.html"
fields = ['name', 'description'] fields = ['name', 'description']
active_menu = 'tasks'
def get_team(self): def get_team(self):
return Team.objects.get( return Team.objects.get(
@ -47,6 +50,7 @@ class TaskUpdateView(LoginRequiredMixin, CampViewMixin, TeamViewMixin, EnsureTea
model = TeamTask model = TeamTask
template_name = "task_form.html" template_name = "task_form.html"
fields = ['name', 'description'] fields = ['name', 'description']
active_menu = 'tasks'
def get_context_data(self, *args, **kwargs): def get_context_data(self, *args, **kwargs):
context = super().get_context_data(**kwargs) context = super().get_context_data(**kwargs)