From 9b9138f08c082c086267564c809322bdef312609 Mon Sep 17 00:00:00 2001 From: Benjamin Bach Date: Sat, 25 Nov 2017 22:35:48 +0100 Subject: [PATCH 1/3] Adding team guides (markdown text) --- src/static_src/css/bornhack.css | 14 +++++++++- src/teams/admin.py | 5 ++++ src/teams/migrations/0019_team_guide.py | 20 +++++++++++++++ src/teams/models.py | 31 +++++++++++++++++++++++ src/teams/templates/team_detail.html | 8 +++++- src/teams/templates/team_guide.html | 25 ++++++++++++++++++ src/teams/templates/team_guide_print.html | 10 ++++++++ src/teams/templatetags/teams_tags.py | 5 ++++ src/teams/urls.py | 10 ++++++++ src/teams/views.py | 27 +++++++++++++++++++- 10 files changed, 152 insertions(+), 3 deletions(-) create mode 100644 src/teams/migrations/0019_team_guide.py create mode 100644 src/teams/templates/team_guide.html create mode 100644 src/teams/templates/team_guide_print.html diff --git a/src/static_src/css/bornhack.css b/src/static_src/css/bornhack.css index a5797eaa..08dcb11c 100644 --- a/src/static_src/css/bornhack.css +++ b/src/static_src/css/bornhack.css @@ -304,4 +304,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; +} \ No newline at end of file diff --git a/src/teams/admin.py b/src/teams/admin.py index c56d48de..38e03f0d 100644 --- a/src/teams/admin.py +++ b/src/teams/admin.py @@ -13,6 +13,10 @@ class TeamTaskAdmin(admin.ModelAdmin): ] +class TeamMemberInline(admin.TabularInline): + model = TeamMember + + @admin.register(Team) class TeamAdmin(admin.ModelAdmin): def get_responsible(self, obj): @@ -30,6 +34,7 @@ class TeamAdmin(admin.ModelAdmin): 'camp', 'needs_members', ] + inlines = [TeamMemberInline] @admin.register(TeamMember) diff --git a/src/teams/migrations/0019_team_guide.py b/src/teams/migrations/0019_team_guide.py new file mode 100644 index 00000000..b1bc29af --- /dev/null +++ b/src/teams/migrations/0019_team_guide.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-11-25 21:32 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0018_auto_20171122_2204'), + ] + + 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)'), + ), + ] diff --git a/src/teams/models.py b/src/teams/models.py index bbfc14b3..ed708fd3 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -11,6 +11,30 @@ import logging 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 TeamArea(CampRelatedModel): class Meta: ordering = ['name'] @@ -50,6 +74,13 @@ class Team(CampRelatedModel): ) mailing_list = models.EmailField(blank=True) + 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) diff --git a/src/teams/templates/team_detail.html b/src/teams/templates/team_detail.html index 1273043d..d6e86830 100644 --- a/src/teams/templates/team_detail.html +++ b/src/teams/templates/team_detail.html @@ -12,9 +12,15 @@ Team: {{ team.name }} | {{ block.super }}

{{ team.name }} Team

+ + {{ team.description|unsafecommonmark }} + + {% if request.user|is_team_member:team %} + Team guide + {% endif %} {% if request.user in team.responsible.all %} - Manage Team + Manage team {% endif %}
diff --git a/src/teams/templates/team_guide.html b/src/teams/templates/team_guide.html new file mode 100644 index 00000000..706c7ba5 --- /dev/null +++ b/src/teams/templates/team_guide.html @@ -0,0 +1,25 @@ +{% extends 'base.html' %} +{% load commonmark %} + +{% block title %} +Guide for: {{ team.name }} | {{ block.super }} +{% endblock %} + +{% block content %} + +

Guide / Howto for {{ team.name }}

+ +

+Print +{% if request.user in team.responsible.all %} + Edit +{% endif %} +

+ +
+{{ team.guide|unsafecommonmark }} +
+ + +{% endblock %} + diff --git a/src/teams/templates/team_guide_print.html b/src/teams/templates/team_guide_print.html new file mode 100644 index 00000000..ad967177 --- /dev/null +++ b/src/teams/templates/team_guide_print.html @@ -0,0 +1,10 @@ +{% load commonmark %} + +{{ team.name }} + + + +{{ team.guide|unsafecommonmark }} + + + diff --git a/src/teams/templatetags/teams_tags.py b/src/teams/templatetags/teams_tags.py index 090d3d66..04b07d57 100644 --- a/src/teams/templatetags/teams_tags.py +++ b/src/teams/templatetags/teams_tags.py @@ -1,4 +1,5 @@ from django import template +from teams.models import TeamMember register = template.Library() @@ -6,3 +7,7 @@ register = template.Library() @register.simple_tag def membershipstatus(user, team): return team.memberstatus(user) + +@register.filter +def is_team_member(user, team): + return TeamMember.objects.filter(team=team, user=user, approved=True).exists() diff --git a/src/teams/urls.py b/src/teams/urls.py index 28072dbe..e0e68822 100644 --- a/src/teams/urls.py +++ b/src/teams/urls.py @@ -43,6 +43,16 @@ urlpatterns = [ TeamManageView.as_view(), name='manage' ), + url( + r'^guide/$', + TeamGuideView.as_view(), + name='guide' + ), + url( + r'^guide/print/$', + TeamGuidePrintView.as_view(), + name='guide_print' + ), url( r'^tasks/', include([ url( diff --git a/src/teams/views.py b/src/teams/views.py index d5937e00..a8aba3f7 100644 --- a/src/teams/views.py +++ b/src/teams/views.py @@ -14,6 +14,8 @@ from django.core.urlresolvers import reverse_lazy from profiles.models import Profile import logging +from django.contrib.auth.decorators import login_required +from django.utils.decorators import method_decorator logger = logging.getLogger("bornhack.%s" % __name__) @@ -45,13 +47,36 @@ class TeamDetailView(CampViewMixin, DetailView): class TeamManageView(CampViewMixin, EnsureTeamResponsibleMixin, UpdateView): model = Team template_name = "team_manage.html" - fields = ['description', 'needs_members'] + fields = ['description', 'guide', 'needs_members'] slug_url_kwarg = 'team_slug' def get_success_url(self): return reverse_lazy('teams:detail', kwargs={'camp_slug': self.camp.slug, 'slug': self.get_object().slug}) +class TeamGuideView(CampViewMixin, DetailView): + template_name = "team_guide.html" + context_object_name = 'team' + model = Team + slug_url_kwarg = 'team_slug' + + @method_decorator(login_required) + def dispatch(self, request, *args, **kwargs): + return CampViewMixin.dispatch(self, request, *args, **kwargs) + + 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" + + class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView): template_name = "team_join.html" model = Team From 0a3c71337e4b93c922d970d035244832fa68c168 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 12 Mar 2019 11:13:13 +0100 Subject: [PATCH 2/3] Merging benjaomings work on team guides. --- ...{0019_team_guide.py => 0050_team_guide.py} | 6 ++-- src/teams/models.py | 10 +++--- src/teams/templates/team_guide.html | 36 ++++++++++++------- src/teams/templates/team_guide_print.html | 5 +-- src/teams/urls.py | 5 +++ src/teams/views/base.py | 2 +- src/teams/views/guide.py | 3 +- 7 files changed, 42 insertions(+), 25 deletions(-) rename src/teams/migrations/{0019_team_guide.py => 0050_team_guide.py} (77%) diff --git a/src/teams/migrations/0019_team_guide.py b/src/teams/migrations/0050_team_guide.py similarity index 77% rename from src/teams/migrations/0019_team_guide.py rename to src/teams/migrations/0050_team_guide.py index b1bc29af..59375bd5 100644 --- a/src/teams/migrations/0019_team_guide.py +++ b/src/teams/migrations/0050_team_guide.py @@ -1,6 +1,4 @@ -# -*- coding: utf-8 -*- -# Generated by Django 1.10.5 on 2017-11-25 21:32 -from __future__ import unicode_literals +# Generated by Django 2.1.5 on 2019-03-12 10:00 from django.db import migrations, models @@ -8,7 +6,7 @@ from django.db import migrations, models class Migration(migrations.Migration): dependencies = [ - ('teams', '0018_auto_20171122_2204'), + ('teams', '0049_auto_20180815_1119'), ] operations = [ diff --git a/src/teams/models.py b/src/teams/models.py index 99b6451e..cd68054d 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -15,23 +15,23 @@ logger = logging.getLogger("bornhack.%s" % __name__) TEAM_GUIDE_TEMPLATE=""" -# Preparations +## Preparations ... -# Camp setup +## Camp setup ... -# During camp +## During camp ... -# Takedown +## Takedown ... -# Notes for next year +## Notes for next year 1. Remember to take notes 1. ... diff --git a/src/teams/templates/team_guide.html b/src/teams/templates/team_guide.html index 706c7ba5..283bcf38 100644 --- a/src/teams/templates/team_guide.html +++ b/src/teams/templates/team_guide.html @@ -1,25 +1,37 @@ -{% extends 'base.html' %} +{% extends 'team_base.html' %} {% load commonmark %} {% block title %} Guide for: {{ team.name }} | {{ block.super }} {% endblock %} -{% block content %} +{% block team_content %} -

Guide / Howto for {{ team.name }}

+
+
+

+ Guide / Howto for {{ team.name }} +

+ + Print + +
+
+

+ {% if request.user in team.responsible.all %} + Edit + {% endif %} +

-

-Print -{% if request.user in team.responsible.all %} - Edit -{% endif %} -

- -
-{{ team.guide|unsafecommonmark }} +
+ {{ team.guide|untrustedcommonmark }} +
+
+ {% endblock %} diff --git a/src/teams/templates/team_guide_print.html b/src/teams/templates/team_guide_print.html index ad967177..8d681d65 100644 --- a/src/teams/templates/team_guide_print.html +++ b/src/teams/templates/team_guide_print.html @@ -1,10 +1,11 @@ -{% load commonmark %} +{% load commonmark %} + {{ team.name }} -{{ team.guide|unsafecommonmark }} +{{ team.guide|untrustedcommonmark }} diff --git a/src/teams/urls.py b/src/teams/urls.py index cf40e0c3..55d13a36 100644 --- a/src/teams/urls.py +++ b/src/teams/urls.py @@ -40,6 +40,11 @@ from teams.views.shifts import ( UserShifts, ) +from teams.views.guide import ( + TeamGuideView, + TeamGuidePrintView +) + app_name = 'teams' urlpatterns = [ diff --git a/src/teams/views/base.py b/src/teams/views/base.py index ee5c7c77..cf52084b 100644 --- a/src/teams/views/base.py +++ b/src/teams/views/base.py @@ -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): diff --git a/src/teams/views/guide.py b/src/teams/views/guide.py index f62124e3..07fdc916 100644 --- a/src/teams/views/guide.py +++ b/src/teams/views/guide.py @@ -3,7 +3,7 @@ from django.views.generic import ListView, DetailView from camps.mixins import CampViewMixin -from .models import Team +from ..models import Team class TeamGuideView(LoginRequiredMixin, CampViewMixin, DetailView): @@ -11,6 +11,7 @@ class TeamGuideView(LoginRequiredMixin, CampViewMixin, DetailView): context_object_name = 'team' model = Team slug_url_kwarg = 'team_slug' + active_menu = 'guide' def get_queryset(self): qs = CampViewMixin.get_queryset(self) From 6b5f610d49ea917c6bafee36ea39145895c29fd5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?V=C3=AD=C3=B0ir=20Valberg=20Gu=C3=B0mundsson?= Date: Tue, 12 Mar 2019 11:18:50 +0100 Subject: [PATCH 3/3] Fixed buttons a bit. --- src/teams/templates/team_guide.html | 22 ++++++++++++---------- 1 file changed, 12 insertions(+), 10 deletions(-) diff --git a/src/teams/templates/team_guide.html b/src/teams/templates/team_guide.html index 283bcf38..e4a5732d 100644 --- a/src/teams/templates/team_guide.html +++ b/src/teams/templates/team_guide.html @@ -8,21 +8,23 @@ Guide for: {{ team.name }} | {{ block.super }} {% block team_content %}
-
-

+
+
+ + Print + + {% if request.user in team.responsible_members.all %} + Edit + {% endif %} +
+

Guide / Howto for {{ team.name }}

- - Print -

- {% if request.user in team.responsible.all %} - Edit - {% endif %}