Merge pull request #291 from bornhack/feature/team-guides
Feature/team guides
This commit is contained in:
commit
ad9c9de600
|
@ -317,4 +317,16 @@ body.bar-menu {
|
|||
width: 300px;
|
||||
}
|
||||
|
||||
|
||||
.team-guide-markdown
|
||||
{
|
||||
background-color: #f9f9f9;
|
||||
padding: 10px 20px;
|
||||
}
|
||||
.team-guide-markdown h1,
|
||||
.team-guide-markdown h2,
|
||||
.team-guide-markdown h3,
|
||||
.team-guide-markdown h4,
|
||||
{
|
||||
font-size: 80%;
|
||||
font-weight: bold;
|
||||
}
|
|
@ -14,6 +14,10 @@ class TeamTaskAdmin(admin.ModelAdmin):
|
|||
]
|
||||
|
||||
|
||||
class TeamMemberInline(admin.TabularInline):
|
||||
model = TeamMember
|
||||
|
||||
|
||||
@admin.register(Team)
|
||||
class TeamAdmin(admin.ModelAdmin):
|
||||
def get_responsible(self, obj):
|
||||
|
@ -41,6 +45,7 @@ class TeamAdmin(admin.ModelAdmin):
|
|||
'private_irc_channel_bot',
|
||||
'private_irc_channel_managed',
|
||||
]
|
||||
inlines = [TeamMemberInline]
|
||||
|
||||
|
||||
@admin.register(TeamMember)
|
||||
|
|
18
src/teams/migrations/0050_team_guide.py
Normal file
18
src/teams/migrations/0050_team_guide.py
Normal file
|
@ -0,0 +1,18 @@
|
|||
# Generated by Django 2.1.5 on 2019-03-12 10:00
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('teams', '0049_auto_20180815_1119'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='team',
|
||||
name='guide',
|
||||
field=models.TextField(blank=True, default='\n# Preparations\n\n...\n\n# Camp setup\n\n...\n\n# During camp\n\n...\n\n# Takedown\n\n...\n\n# Notes for next year\n\n 1. Remember to take notes\n 1. ...\n', help_text='HowTo guide for this year (and next year)', verbose_name='team guide (Markdown)'),
|
||||
),
|
||||
]
|
|
@ -14,6 +14,30 @@ from utils.models import CampRelatedModel, CreatedUpdatedModel, UUIDModel
|
|||
logger = logging.getLogger("bornhack.%s" % __name__)
|
||||
|
||||
|
||||
TEAM_GUIDE_TEMPLATE="""
|
||||
## Preparations
|
||||
|
||||
...
|
||||
|
||||
## Camp setup
|
||||
|
||||
...
|
||||
|
||||
## During camp
|
||||
|
||||
...
|
||||
|
||||
## Takedown
|
||||
|
||||
...
|
||||
|
||||
## Notes for next year
|
||||
|
||||
1. Remember to take notes
|
||||
1. ...
|
||||
"""
|
||||
|
||||
|
||||
class Team(CampRelatedModel):
|
||||
camp = models.ForeignKey(
|
||||
'camps.Camp',
|
||||
|
@ -114,6 +138,13 @@ class Team(CampRelatedModel):
|
|||
ordering = ['name']
|
||||
unique_together = (('name', 'camp'), ('slug', 'camp'))
|
||||
|
||||
guide = models.TextField(
|
||||
blank=True,
|
||||
help_text="HowTo guide for this year (and next year)",
|
||||
verbose_name="team guide (Markdown)",
|
||||
default=TEAM_GUIDE_TEMPLATE,
|
||||
)
|
||||
|
||||
def __str__(self):
|
||||
return '{} ({})'.format(self.name, self.camp)
|
||||
|
||||
|
|
|
@ -53,6 +53,12 @@ Team: {{ team.name }} | {{ block.super }}
|
|||
</li>
|
||||
{% endif %}
|
||||
|
||||
<li {% if view.active_menu == "guide" %}class="active"{% endif %}>
|
||||
<a href="{% url "teams:guide" camp_slug=team.camp.slug team_slug=team.slug %}">
|
||||
Team guide
|
||||
</a>
|
||||
</li>
|
||||
|
||||
</ul>
|
||||
|
||||
<hr />
|
||||
|
|
39
src/teams/templates/team_guide.html
Normal file
39
src/teams/templates/team_guide.html
Normal file
|
@ -0,0 +1,39 @@
|
|||
{% extends 'team_base.html' %}
|
||||
{% load commonmark %}
|
||||
|
||||
{% block title %}
|
||||
Guide for: {{ team.name }} | {{ block.super }}
|
||||
{% endblock %}
|
||||
|
||||
{% block team_content %}
|
||||
|
||||
<div class="panel panel-default">
|
||||
<div class="panel-heading">
|
||||
<div class="btn-group pull-right">
|
||||
<a href="{% url 'teams:guide_print' camp_slug=camp.slug team_slug=team.slug %}"
|
||||
class="btn btn-default"
|
||||
target="_blank">
|
||||
Print
|
||||
</a>
|
||||
{% if request.user in team.responsible_members.all %}
|
||||
<a href="{% url 'teams:manage' camp_slug=camp.slug team_slug=team.slug %}" class="btn btn-warning">Edit</a>
|
||||
{% endif %}
|
||||
</div>
|
||||
<h4>
|
||||
Guide / Howto for {{ team.name }}
|
||||
</h4>
|
||||
</div>
|
||||
<div class="panel-body">
|
||||
<p>
|
||||
</p>
|
||||
|
||||
<div class="team-guide-markdown">
|
||||
{{ team.guide|untrustedcommonmark }}
|
||||
</div>
|
||||
</div>
|
||||
</div>
|
||||
|
||||
|
||||
|
||||
{% endblock %}
|
||||
|
11
src/teams/templates/team_guide_print.html
Normal file
11
src/teams/templates/team_guide_print.html
Normal file
|
@ -0,0 +1,11 @@
|
|||
{% load commonmark %}
|
||||
<html>
|
||||
<head>
|
||||
<title>{{ team.name }}</title>
|
||||
</head>
|
||||
<body onload="window.print()">
|
||||
|
||||
{{ team.guide|untrustedcommonmark }}
|
||||
|
||||
</body>
|
||||
</html>
|
|
@ -1,7 +1,16 @@
|
|||
from django import template
|
||||
from teams.models import TeamMember
|
||||
from django.utils.safestring import mark_safe
|
||||
register = template.Library()
|
||||
|
||||
|
||||
@register.filter
|
||||
def is_team_member(user, team):
|
||||
return TeamMember.objects.filter(
|
||||
team=team, user=user, approved=True
|
||||
).exists()
|
||||
|
||||
|
||||
@register.simple_tag
|
||||
def membershipstatus(user, team, showicon=False):
|
||||
if user in team.responsible_members.all():
|
||||
|
@ -21,4 +30,3 @@ def membershipstatus(user, team, showicon=False):
|
|||
return mark_safe("<i class='fa %s' title='%s'></i>" % (icon, text))
|
||||
else:
|
||||
return text
|
||||
|
||||
|
|
|
@ -40,6 +40,11 @@ from teams.views.shifts import (
|
|||
UserShifts,
|
||||
)
|
||||
|
||||
from teams.views.guide import (
|
||||
TeamGuideView,
|
||||
TeamGuidePrintView
|
||||
)
|
||||
|
||||
app_name = 'teams'
|
||||
|
||||
urlpatterns = [
|
||||
|
@ -75,6 +80,16 @@ urlpatterns = [
|
|||
TeamManageView.as_view(),
|
||||
name='manage'
|
||||
),
|
||||
path(
|
||||
'guide/',
|
||||
TeamGuideView.as_view(),
|
||||
name='guide'
|
||||
),
|
||||
path(
|
||||
'guide/print/',
|
||||
TeamGuidePrintView.as_view(),
|
||||
name='guide_print'
|
||||
),
|
||||
path(
|
||||
'fix_irc_acl/',
|
||||
FixIrcAclView.as_view(),
|
||||
|
|
|
@ -46,7 +46,7 @@ class TeamManageView(CampViewMixin, EnsureTeamResponsibleMixin, UpdateView):
|
|||
fields = ['description', 'needs_members', 'public_irc_channel_name',
|
||||
'public_irc_channel_bot', 'public_irc_channel_managed',
|
||||
'private_irc_channel_name', 'private_irc_channel_bot',
|
||||
'private_irc_channel_managed']
|
||||
'private_irc_channel_managed', 'guide']
|
||||
slug_url_kwarg = 'team_slug'
|
||||
|
||||
def get_success_url(self):
|
||||
|
|
28
src/teams/views/guide.py
Normal file
28
src/teams/views/guide.py
Normal file
|
@ -0,0 +1,28 @@
|
|||
from django.contrib.auth.mixins import LoginRequiredMixin
|
||||
from django.views.generic import ListView, DetailView
|
||||
|
||||
from camps.mixins import CampViewMixin
|
||||
|
||||
from ..models import Team
|
||||
|
||||
|
||||
class TeamGuideView(LoginRequiredMixin, CampViewMixin, DetailView):
|
||||
template_name = "team_guide.html"
|
||||
context_object_name = 'team'
|
||||
model = Team
|
||||
slug_url_kwarg = 'team_slug'
|
||||
active_menu = 'guide'
|
||||
|
||||
def get_queryset(self):
|
||||
qs = CampViewMixin.get_queryset(self)
|
||||
qs.filter(
|
||||
teammember__approved=True,
|
||||
teammember__user=self.request.user,
|
||||
)
|
||||
return qs
|
||||
|
||||
|
||||
class TeamGuidePrintView(TeamGuideView):
|
||||
template_name = "team_guide_print.html"
|
||||
|
||||
|
Loading…
Reference in a new issue