diff --git a/src/bornhack/urls.py b/src/bornhack/urls.py index 07757e43..7c7d6125 100644 --- a/src/bornhack/urls.py +++ b/src/bornhack/urls.py @@ -257,8 +257,8 @@ urlpatterns = [ r'^$', VillageListView.as_view(), name='village_list' - ), - url( + ), + url( r'create/$', VillageCreateView.as_view(), name='village_create' @@ -288,6 +288,17 @@ urlpatterns = [ TeamListView.as_view(), name='team_list' ), + url( + r'(?P[-_\w+]+)/join/$', + TeamJoinView.as_view(), + name='team_join' + ), + url( + r'(?P[-_\w+]+)/leave/$', + TeamLeaveView.as_view(), + name='team_leave' + ), + # this has to be the last url in the list url( r'(?P[-_\w+]+)/$', TeamDetailView.as_view(), diff --git a/src/program/templates/speaker_list.html b/src/program/templates/speaker_list.html index fd3c6d87..c4f6c2b0 100644 --- a/src/program/templates/speaker_list.html +++ b/src/program/templates/speaker_list.html @@ -4,7 +4,7 @@ {% if speaker_list %}

An alphabetical list of all speakers, workshop hosts and other - event anchors at BornHack 2016. + event anchors at {{ camp.title }}.

"Call for Speakers" for {{ camp.title }} diff --git a/src/teams/admin.py b/src/teams/admin.py index 674e74ef..ee7cc271 100644 --- a/src/teams/admin.py +++ b/src/teams/admin.py @@ -1,6 +1,8 @@ from django.contrib import admin -from .models import Team, TeamMember +from .models import Team, TeamArea, TeamMember admin.site.register(Team) +admin.site.register(TeamArea) admin.site.register(TeamMember) + diff --git a/src/teams/migrations/0005_auto_20170402_1331.py b/src/teams/migrations/0005_auto_20170402_1331.py new file mode 100644 index 00000000..bd98f781 --- /dev/null +++ b/src/teams/migrations/0005_auto_20170402_1331.py @@ -0,0 +1,70 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-02 11:31 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('camps', '0020_camp_read_only'), + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('teams', '0004_team_sub_team_of'), + ] + + operations = [ + migrations.CreateModel( + name='TeamArea', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('created', models.DateTimeField(auto_now_add=True)), + ('updated', models.DateTimeField(auto_now=True)), + ('name', models.CharField(max_length=255)), + ('camp', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='camps.Camp')), + ('responsible', models.ManyToManyField(related_name='responsible_team_areas', to=settings.AUTH_USER_MODEL)), + ], + options={ + 'ordering': ['name'], + }, + ), + migrations.RemoveField( + model_name='teammember', + name='team', + ), + migrations.RemoveField( + model_name='teammember', + name='user', + ), + migrations.AddField( + model_name='team', + name='membersnew', + field=models.ManyToManyField(related_name='teams', to=settings.AUTH_USER_MODEL), + ), + migrations.RemoveField( + model_name='team', + name='members', + ), + migrations.RemoveField( + model_name='team', + name='sub_team_of', + ), + migrations.AddField( + model_name='team', + name='area', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.PROTECT, related_name='teams', to='teams.TeamArea'), + ), + migrations.AlterUniqueTogether( + name='team', + unique_together=set([('name', 'camp'), ('slug', 'camp')]), + ), + migrations.DeleteModel( + name='TeamMember', + ), + migrations.AlterUniqueTogether( + name='teamarea', + unique_together=set([('name', 'camp')]), + ), + ] diff --git a/src/teams/migrations/0006_auto_20170402_1331.py b/src/teams/migrations/0006_auto_20170402_1331.py new file mode 100644 index 00000000..eb67736b --- /dev/null +++ b/src/teams/migrations/0006_auto_20170402_1331.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-02 11:31 +from __future__ import unicode_literals + +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0005_auto_20170402_1331'), + ] + + operations = [ + migrations.RenameField( + model_name='team', + old_name='membersnew', + new_name='members', + ), + migrations.AlterField( + model_name='team', + name='area', + field=models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, related_name='teams', to='teams.TeamArea'), + ), + ] diff --git a/src/teams/migrations/0007_teamarea_description.py b/src/teams/migrations/0007_teamarea_description.py new file mode 100644 index 00000000..23e90d79 --- /dev/null +++ b/src/teams/migrations/0007_teamarea_description.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-02 12:15 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0006_auto_20170402_1331'), + ] + + operations = [ + migrations.AddField( + model_name='teamarea', + name='description', + field=models.TextField(default=''), + ), + ] diff --git a/src/teams/migrations/0008_team_needs_members.py b/src/teams/migrations/0008_team_needs_members.py new file mode 100644 index 00000000..ff612d66 --- /dev/null +++ b/src/teams/migrations/0008_team_needs_members.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-02 13:57 +from __future__ import unicode_literals + +from django.db import migrations, models + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0007_teamarea_description'), + ] + + operations = [ + migrations.AddField( + model_name='team', + name='needs_members', + field=models.BooleanField(default=True), + ), + ] diff --git a/src/teams/migrations/0009_auto_20170402_1607.py b/src/teams/migrations/0009_auto_20170402_1607.py new file mode 100644 index 00000000..54677ca3 --- /dev/null +++ b/src/teams/migrations/0009_auto_20170402_1607.py @@ -0,0 +1,45 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-02 14:07 +from __future__ import unicode_literals + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('teams', '0008_team_needs_members'), + ] + + operations = [ + migrations.CreateModel( + name='TeamMember', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('approved', models.BooleanField(default=False)), + ], + ), + migrations.AlterField( + model_name='team', + name='members', + field=models.ManyToManyField(related_name='teamsold', to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='teammember', + name='team', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='teams.Team'), + ), + migrations.AddField( + model_name='teammember', + name='user', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to=settings.AUTH_USER_MODEL), + ), + migrations.AddField( + model_name='team', + name='membersnew', + field=models.ManyToManyField(related_name='teams', through='teams.TeamMember', to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/src/teams/migrations/0010_remove_team_members.py b/src/teams/migrations/0010_remove_team_members.py new file mode 100644 index 00000000..334848b4 --- /dev/null +++ b/src/teams/migrations/0010_remove_team_members.py @@ -0,0 +1,19 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-02 14:07 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0009_auto_20170402_1607'), + ] + + operations = [ + migrations.RemoveField( + model_name='team', + name='members', + ), + ] diff --git a/src/teams/migrations/0011_auto_20170402_1608.py b/src/teams/migrations/0011_auto_20170402_1608.py new file mode 100644 index 00000000..b2ffaf34 --- /dev/null +++ b/src/teams/migrations/0011_auto_20170402_1608.py @@ -0,0 +1,20 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.5 on 2017-04-02 14:08 +from __future__ import unicode_literals + +from django.db import migrations + + +class Migration(migrations.Migration): + + dependencies = [ + ('teams', '0010_remove_team_members'), + ] + + operations = [ + migrations.RenameField( + model_name='team', + old_name='membersnew', + new_name='members', + ), + ] diff --git a/src/teams/models.py b/src/teams/models.py index 57b47c3c..e580129e 100644 --- a/src/teams/models.py +++ b/src/teams/models.py @@ -1,21 +1,35 @@ from django.db import models from django.utils.text import slugify - from utils.models import CampRelatedModel +from django.core.exceptions import ValidationError + + +class TeamArea(CampRelatedModel): + class Meta: + ordering = ['name'] + unique_together = ('name', 'camp') + + name = models.CharField(max_length=255) + description = models.TextField(default='') + camp = models.ForeignKey('camps.Camp') + responsible = models.ManyToManyField('auth.User', related_name='responsible_team_areas') + + def __str__(self): + return '{} ({})'.format(self.name, self.camp) class Team(CampRelatedModel): - class Meta: ordering = ['name'] - unique_together = ('slug', 'camp') + unique_together = (('name', 'camp'), ('slug', 'camp')) name = models.CharField(max_length=255) slug = models.SlugField(max_length=255, blank=True) camp = models.ForeignKey('camps.Camp') + area = models.ForeignKey('teams.TeamArea', related_name='teams', on_delete=models.PROTECT) description = models.TextField() - members = models.ManyToManyField('auth.User', through='teams.TeamMember') - sub_team_of = models.ForeignKey('self', null=True, blank=True, related_name="sub_teams") + needs_members = models.BooleanField(default=True) + members = models.ManyToManyField('auth.User', related_name='teams', through='teams.TeamMember') def __str__(self): return '{} ({})'.format(self.name, self.camp) @@ -30,10 +44,25 @@ class Team(CampRelatedModel): super().save(**kwargs) + def clean(self): + if self.camp != self.area.camp: + raise ValidationError({'camp': 'camp is different from area.camp'}) + + def memberstatus(self, member): + if member not in self.members.all(): + return "Not member" + else: + if TeamMember.objects.get(team=self, user=member).approved: + return "Member" + else: + return "Membership Pending" + + class TeamMember(models.Model): user = models.ForeignKey('auth.User') team = models.ForeignKey('teams.Team') - responsible = models.BooleanField(default=False) + approved = models.BooleanField(default=False) def __str__(self): - return '{} ({})'.format(self.user, self.team) + return '{} is {} member of team {}'.format(self.user, '' if self.approved else 'an unapproved', self.team) + diff --git a/src/teams/templates/team_join.html b/src/teams/templates/team_join.html new file mode 100644 index 00000000..467536af --- /dev/null +++ b/src/teams/templates/team_join.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% load commonmark %} + +{% block title %} +Join Team: {{ team.name }} | {{ block.super }} +{% endblock %} + +{% block content %} + +

{{ team.name }} Team

+

Really join the {{ team.name }} team? You will receive a message when your membership has been approved.

+

+{% csrf_token %} +{{ form }} + + Cancel +
+{% endblock %} diff --git a/src/teams/templates/team_leave.html b/src/teams/templates/team_leave.html new file mode 100644 index 00000000..61db8e4e --- /dev/null +++ b/src/teams/templates/team_leave.html @@ -0,0 +1,18 @@ +{% extends 'base.html' %} +{% load commonmark %} + +{% block title %} +Join Team: {{ team.name }} | {{ block.super }} +{% endblock %} + +{% block content %} + +

Leave {{ team.name }} Team

+

Really leave the {{ team.name }} team?

+

+{% csrf_token %} +{{ form }} + + Cancel +
+{% endblock %} diff --git a/src/teams/templates/team_list.html b/src/teams/templates/team_list.html index 596423a4..e78f3448 100644 --- a/src/teams/templates/team_list.html +++ b/src/teams/templates/team_list.html @@ -13,6 +13,11 @@ Teams | {{ block.super }} Name Description + Area + {% if request.user.is_authenticated %} + Membership + Action + {% endif %} @@ -24,28 +29,27 @@ Teams | {{ block.super }} - {% if team.sub_teams.exists %} -
- {% endif %} {{ team.description|unsafecommonmark|truncatewords:50 }} - - {% if team.sub_teams.exists %} -
- Subteams: -
    - {% for sub_team in team.sub_teams.all %} -
  • {{ sub_team.name }}
  • - {% endfor %} -
-
- -
- - + + + {{ team.area.name }} + + {% if request.user.is_authenticated %} + + {% if request.user in team.members.all %} + Member + {% else %} + Not member {% endif %} + + {% if request.user in team.members.all %} + Leave + {% else %} + Join + {% endif %} + + {% endif %} {% endfor %} diff --git a/src/teams/views.py b/src/teams/views.py index a89661d9..ea58fd33 100644 --- a/src/teams/views.py +++ b/src/teams/views.py @@ -1,13 +1,15 @@ from django.views.generic import ListView, DetailView - +from django.views.generic.edit import UpdateView from camps.mixins import CampViewMixin - -from .models import Team +from .models import Team, TeamMember +from django.contrib.auth.mixins import LoginRequiredMixin +from django.shortcuts import redirect +from django.contrib import messages class TeamListView(CampViewMixin, ListView): template_name = "team_list.html" - queryset = Team.objects.filter(sub_team_of=None) + model = Team context_object_name = 'teams' @@ -15,3 +17,44 @@ class TeamDetailView(CampViewMixin, DetailView): template_name = "team_detail.html" model = Team context_object_name = 'team' + + +class TeamJoinView(LoginRequiredMixin, CampViewMixin, UpdateView): + template_name = "team_join.html" + model = Team + fields = [] + + def get(self, request, *args, **kwargs): + if request.user in self.get_object().members.all(): + messages.warning(request, "You are already a member of this team") + return redirect('team_list', camp_slug=self.camp.slug) + + if not self.get_object().needs_members: + messages.warning(request, "This team does not need members right now") + return redirect('team_list', camp_slug=self.get_object().camp.slug) + + return super().get(request, *args, **kwargs) + + def form_valid(self, form): + TeamMember.objects.create(team=self.get_object(), user=self.request.user) + messages.success(self.request, "You request to join the team %s has been registered, thank you." % self.get_object().name) + return redirect('team_list', camp_slug=self.get_object().camp.slug) + + +class TeamLeaveView(LoginRequiredMixin, CampViewMixin, UpdateView): + template_name = "team_leave.html" + model = Team + fields = [] + + def get(self, request, *args, **kwargs): + if request.user not in self.get_object().members.all(): + messages.warning(request, "You are not a member of this team") + return redirect('team_list', camp_slug=self.get_object().camp.slug) + + return super().get(request, *args, **kwargs) + + def form_valid(self, form): + TeamMember.objects.filter(team=self.get_object(), user=self.request.user).delete() + messages.success(self.request, "You are no longer a member of the team %s" % self.get_object().name) + return redirect('team_list', camp_slug=self.get_object().camp.slug) + diff --git a/src/templates/base.html b/src/templates/base.html index c787bf62..0e6e6dbe 100644 --- a/src/templates/base.html +++ b/src/templates/base.html @@ -82,16 +82,16 @@ diff --git a/src/utils/management/commands/bootstrap-devsite.py b/src/utils/management/commands/bootstrap-devsite.py index 94927ed1..601ba8bf 100644 --- a/src/utils/management/commands/bootstrap-devsite.py +++ b/src/utils/management/commands/bootstrap-devsite.py @@ -7,7 +7,7 @@ from shop.models import ProductCategory, Product from info.models import InfoCategory, InfoItem from villages.models import Village from program.models import EventType, Event, EventInstance, Speaker, EventLocation -from teams.models import Team, TeamMember +from teams.models import Team, TeamArea, TeamMember from django.contrib.auth.models import User from allauth.account.models import EmailAddress from django.utils.text import slugify @@ -1243,38 +1243,72 @@ Please note that sleeping in the parking lot is not permitted. If you want to sl description='This village is representing TheCamp.dk, an annual danish tech camp held in July. The official subjects for this event is open source software, network and security. In reality we are interested in anything from computers to illumination soap bubbles and irish coffee' ) + self.output("Creating team areas for {}...".format(year)) + pr_area = TeamArea.objects.create( + name='PR', + description="The Public Relations area covers website, social media and marketing related tasks.", + camp=camp + ) + content_area = TeamArea.objects.create( + name='Content', + description="The Content area handles talks, A/V and photos.", + camp=camp + ) + infrastructure_area = TeamArea.objects.create( + name='Infrastructure', + description="The Infrastructure area covers network/NOC, power, villages, CERT, logistics.", + camp=camp + ) + bar_area = TeamArea.objects.create( + name='Bar', + description="The Bar area covers building and running the IRL bar, DJ booth and related tasks.", + camp=camp + ) + + self.output("Setting teamarea responsibles for {}...".format(year)) + pr_area.responsible.add(user1, user2) + content_area.responsible.add(user2, user3) + infrastructure_area.responsible.add(user3, user4) + bar_area.responsible.add(user4) + self.output("Creating teams for {}...".format(year)) noc_team = Team.objects.create( name="NOC", description="The NOC team is in charge of establishing and running a network onsite.".format(year), - camp=camp + camp=camp, + area=infrastructure_area, ) bar_team = Team.objects.create( name="Bar", description="The Bar team plans, builds and run the IRL bar!", - camp=camp + camp=camp, + area=bar_area ) + self.output("Setting team members for {}...".format(year)) TeamMember.objects.create( - user=user2, - team=bar_team, - responsible=True - ) - TeamMember.objects.create( + team=noc_team, user=user4, - team=noc_team, - responsible=True + approved=True ) TeamMember.objects.create( + team=noc_team, + user=user1 + ) + TeamMember.objects.create( + team=bar_team, user=user1, - team=noc_team, - responsible=True + approved=True ) TeamMember.objects.create( + team=bar_team, user=user3, - team=noc_team, + approved=True + ) + TeamMember.objects.create( + team=bar_team, + user=user2 ) - self.output("marking 2016 as read_only...") camp2016.read_only = True