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="col-md-2">
<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 %}">
General
</a>
</li>
<li {% if view.template_name == "team_tasks.html" %}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 %}>
<li {% if view.active_menu == "members" %}class="active"{% endif %}>
<a href="{% url "teams:members" camp_slug=team.camp.slug team_slug=team.slug %}">
Members
{% if request.user in team.responsible_members.all and team.unapproved_members %}
@ -37,6 +31,20 @@ Team: {{ team.name }} | {{ block.super }}
</a>
</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>
<hr />

View file

@ -6,10 +6,6 @@
{% 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-heading">
<h4>Info Categories</h4>

View file

@ -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 %}
<div class="panel panel-default">
<div class="panel-heading">
<h4>

View file

@ -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 }}"
<h4>
{% if object %}
Editing "{{ object.headline }}"
in "{{ object.category.headline }}"
{% else %}
Create Info Item
in "{{ category.headline }}"
{% endif %}
in "{{ object.category.headline }}"
</h4>
</div>
<div class="panel-body">

View file

@ -29,25 +29,26 @@
</tr>
</thead>
<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>
<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>
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 %}
</td>
{% if request.user in team.responsible_members.all %}
<td>
<div class="btn-group-vertical">
<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
</a>
{% if not teammember.approved %}
{% if not member.approved %}
<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
</a>
{% endif %}
@ -55,6 +56,7 @@
</td>
{% endif %}
</tr>
{% endif %}
{% empty %}
<p>No members found!</p>
{% endfor %}

View file

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

View file

@ -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)

View file

@ -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')

View file

@ -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

View file

@ -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)