bornhack-website/src/teams/models.py

264 lines
7.9 KiB
Python
Raw Normal View History

from django.db import models
from django.db.models.signals import post_save
from django.dispatch import receiver
from django.utils.text import slugify
from utils.models import CampRelatedModel
2017-04-02 16:04:57 +00:00
from django.core.exceptions import ValidationError
from django.contrib.auth.models import User
2017-11-25 12:02:32 +00:00
from django.core.urlresolvers import reverse_lazy
import logging
logger = logging.getLogger("bornhack.%s" % __name__)
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
class Team(CampRelatedModel):
camp = models.ForeignKey(
'camps.Camp',
related_name="teams",
on_delete=models.PROTECT,
)
2017-04-02 16:04:57 +00:00
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
name = models.CharField(
max_length=255,
help_text='The team name',
)
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
slug = models.SlugField(
max_length=255,
blank=True,
help_text='Url slug for this team. Leave blank to generate based on team name',
)
2017-04-02 16:04:57 +00:00
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
shortslug = models.SlugField(
help_text='Abbreviated version of the slug. Used in places like IRC channel names where space is limited',
)
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
description = models.TextField()
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
needs_members = models.BooleanField(
default=True,
help_text='Check to indicate that this team needs more members',
)
members = models.ManyToManyField(
'auth.User',
related_name='teams',
through='teams.TeamMember'
)
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
# mailing list related fields
mailing_list = models.EmailField(
blank=True
)
mailing_list_archive_public = models.BooleanField(
default=False,
help_text='Check if the mailing list archive is public'
)
mailing_list_nonmember_posts = models.BooleanField(
default=False,
help_text='Check if the mailinglist allows non-list-members to post'
)
# IRC related fields
irc_channel = models.BooleanField(
default=False,
help_text='Check to make the IRC bot join the team IRC channel. Leave unchecked to disable IRC bot functionality for this team entirely.',
)
irc_channel_name = models.TextField(
default='',
blank=True,
help_text='Team IRC channel. Leave blank to generate channel name automatically, based on camp shortslug and team shortslug.',
)
irc_channel_managed = models.BooleanField(
default=True,
help_text='Check to make the bot manage the team IRC channel. The bot will register the channel with ChanServ if possible, and manage ACLs as needed.',
)
irc_channel_private = models.BooleanField(
default=True,
help_text='Check to make the IRC channel secret and +i (private for team members only using an ACL). Leave unchecked to make the IRC channel public and open for everyone.'
)
class Meta:
ordering = ['name']
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
unique_together = (('name', 'camp'), ('slug', 'camp'))
def __str__(self):
return '{} ({})'.format(self.name, self.camp)
def save(self, **kwargs):
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
# generate slug if needed
if not self.pk or not self.slug:
slug = slugify(self.name)
self.slug = slug
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
if not self.shortslug:
self.shortslug = self.slug
# generate IRC channel name if needed
if self.irc_channel and not self.irc_channel_name:
self.irc_channel_name = "#%s-%s" % (self.camp.shortslug, self.shortslug)
super().save(**kwargs)
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
def clean(self):
# make sure the irc channel name is prefixed with a # if it is set
if self.irc_channel_name and self.irc_channel_name[0] != "#":
self.irc_channel_name = "#%s" % self.irc_channel_name
if self.irc_channel_name:
if Team.objects.filter(irc_channel_name=self.irc_channel_name).exclude(pk=self.pk).exists():
raise ValidationError("This IRC channel name is already in use")
2017-04-02 16:04:57 +00:00
@property
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
def memberships(self):
"""
Returns all TeamMember objects for this team.
Use self.members.all() to get User objects for all members,
or use self.memberships.all() to get TeamMember objects for all members.
"""
return TeamMember.objects.filter(
team=self
)
@property
def approved_members(self):
"""
Returns only approved members (returns User objects, not TeamMember objects)
"""
return self.members.filter(
teammember__approved=True
)
@property
def unapproved_members(self):
"""
Returns only unapproved members (returns User objects, not TeamMember objects)
"""
return self.members.filter(
teammember__approved=False
)
2017-07-11 20:50:31 +00:00
@property
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
def responsible_members(self):
"""
Return only approved and responsible members
Used to handle permissions for team management
"""
return self.members.filter(
teammember__approved=True,
teammember__responsible=True
)
2017-07-11 20:50:31 +00:00
@property
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
def regular_members(self):
"""
Return only approved and not responsible members with
an approved public_credit_name.
Used on the people pages.
"""
return self.members.filter(
teammember__approved=True,
teammember__responsible=False,
)
@property
def unnamed_members(self):
"""
Returns only approved and not responsible members,
without an approved public_credit_name.
"""
return self.members.filter(
teammember__approved=True,
teammember__responsible=False,
profile__public_credit_name_approved=False
)
2017-07-11 20:50:31 +00:00
2017-04-02 16:04:57 +00:00
2017-05-23 19:21:47 +00:00
class TeamMember(CampRelatedModel):
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
user = models.ForeignKey(
'auth.User',
on_delete=models.PROTECT,
help_text="The User object this team membership relates to",
)
team = models.ForeignKey(
'teams.Team',
on_delete=models.PROTECT,
help_text="The Team this membership relates to"
)
approved = models.BooleanField(
default=False,
help_text="True if this membership is approved. False if not."
)
responsible = models.BooleanField(
default=False,
help_text="True if this teammember is responsible for this Team. False if not."
)
irc_channel_acl_ok = models.BooleanField(
default=False,
help_text="Maintained by the IRC bot, do not edit manually. True if the teammembers NickServ username has been added to the Team IRC channels ACL.",
)
class Meta:
ordering = ['-responsible', '-approved']
def __str__(self):
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
return '{} is {} {} member of team {}'.format(
self.user,
'' if self.approved else 'an unapproved',
'' if not self.responsible else 'a responsible',
self.team
)
2017-04-02 16:04:57 +00:00
2017-05-23 19:21:47 +00:00
@property
def camp(self):
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
""" All CampRelatedModels must have a camp FK or a camp property """
2017-05-23 19:21:47 +00:00
return self.team.camp
2017-11-23 22:09:14 +00:00
class TeamTask(CampRelatedModel):
team = models.ForeignKey(
'teams.Team',
related_name='tasks',
2018-03-04 15:26:35 +00:00
on_delete=models.PROTECT,
2017-11-23 22:09:14 +00:00
help_text='The team this task belongs to',
)
name = models.CharField(
max_length=100,
help_text='Short name of this task',
)
slug = models.SlugField(
max_length=255,
blank=True,
help_text='url slug, leave blank to autogenerate',
)
description = models.TextField(
help_text='Description of the task. Markdown is supported.'
)
class Meta:
ordering = ['name']
unique_together = (('name', 'team'), ('slug', 'team'))
2017-11-25 12:02:32 +00:00
def get_absolute_url(self):
return reverse_lazy('teams:task_detail', kwargs={'camp_slug': self.team.camp.slug, 'team_slug': self.team.slug, 'slug': self.slug})
2017-11-23 22:09:14 +00:00
@property
def camp(self):
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
""" All CampRelatedModels must have a camp FK or a camp property """
2017-11-23 22:09:14 +00:00
return self.team.camp
def save(self, **kwargs):
Merge teamcomms branch. Refactor team app and add events app. * Primary commit towards improved team communications. Add new events app to handle team notifications when various events happen, with a Type model which contain event types and a Routing model which controls routing of events to teams. Add shortslug for Camp and Team models. events.handler.py contains the code for sending irc and email notifications for teams. The first two eventtypes have been added in datamigrations, 'ticket_created' and 'public_credit_name_changed', and the tickets and profile apps have been adjusted accordingly. Team IRC channels can be marked as managed and if so the IRC bot will register the team channel with ChanServ if possible. Team IRC channels can be marked as private and the bot will set invite only and maintain an ACL with team members. Users can set their NickServ username in their profile to get on the ACL. Rework all team views and templates. Remove TeamArea model and make Team have an FK to Camp directly. Add docstrings a whole bunch of places. Move signal handlers to apps.py and signal_handlers.py in a few apps. Add basic team mailing list handling, more work to be done. Update bootstrap-devsite script to add more teammembers and add some team event routing for the two eventtypes we have. * default to the console backend for email unless we specifically ask for realworld email * fix signal for public_credit_name approval irc message * fix name display on /people/ page * fix the text on people pages when all non-responsible team members are anonymous * handle cases where we fallback to the area responsible properly * readd removed property, it is used in team_detail view * make it possible to filter profiles by public_credit_name_approved * add method for sending IRC messages in ircbot.utils.add_irc_message(), extend periodic bot method to do more than check for outgoing messages so rename it, refactor chanserv and nickserv handling code, create methods to check and join/part IRC channels as needed, maintain channel ACLs for private channels, do not autojoin any channels when instatiating the bot instead rely on the new check_irc_channels() method to join them, rename profile presave signal, add checking for changed nickserv usernames for acl handling, add teammember.irc_channel_acl_ok boolean to track ACL state, add missing help_text properties to TeamMember fields, rename teammember postsave signal, add teammember deleted signal, readd wrongly deleted EnsureTeamMemberResponsibleMixin * add a few missing early returns
2018-04-09 21:11:05 +00:00
# generate slug if needed
2017-11-23 22:09:14 +00:00
if not self.slug:
2017-11-25 12:02:32 +00:00
self.slug = slugify(self.name)
2017-11-23 22:09:14 +00:00
super().save(**kwargs)