* add flake8 to pre-commit config, and fixup many things to make flake8 happy * add isort and sort all imports, add to pre-commit and requirements
55 lines
2 KiB
Python
55 lines
2 KiB
Python
# -*- coding: utf-8 -*-
|
|
# Generated by Django 1.10.5 on 2018-03-25 13:45
|
|
from __future__ import unicode_literals
|
|
|
|
from django.db import migrations
|
|
|
|
|
|
def add_team_camp(apps, schema_editor):
|
|
Team = apps.get_model("teams", "Team")
|
|
|
|
for team in Team.objects.all():
|
|
print("camp processing team %s..." % team.name)
|
|
team.camp = team.area.camp
|
|
team.save()
|
|
print("set camp %s for team %s" % (team.camp.slug, team.name))
|
|
|
|
|
|
def add_missing_team_responsibles(apps, schema_editor):
|
|
Team = apps.get_model("teams", "Team")
|
|
TeamMember = apps.get_model("teams", "TeamMember")
|
|
|
|
for team in Team.objects.all():
|
|
print("responsible processing team %s..." % team.name)
|
|
responsibles = TeamMember.objects.filter(team=team, responsible=True)
|
|
if not responsibles:
|
|
# get the area responsibles instead
|
|
responsibles = team.area.responsible.all()
|
|
for responsible in responsibles:
|
|
if isinstance(responsible, TeamMember):
|
|
# we need User objects instead of TeamMember objects
|
|
responsible = responsible.user
|
|
try:
|
|
membership = TeamMember.objects.get(team=team, user=responsible)
|
|
if not membership.responsible:
|
|
# already a member of the team, but not responsible
|
|
membership.responsible = True
|
|
membership.save()
|
|
print("%s is now marked as responsible" % membership.user.username)
|
|
except TeamMember.DoesNotExist:
|
|
# add the responsible as a member of the team
|
|
membership = TeamMember.objects.create(
|
|
team=team, user=responsible, responsible=True, approved=True
|
|
)
|
|
print("new membership has been created for team %s" % team.name)
|
|
|
|
|
|
class Migration(migrations.Migration):
|
|
|
|
dependencies = [("teams", "0026_team_camp")]
|
|
|
|
operations = [
|
|
migrations.RunPython(add_team_camp),
|
|
migrations.RunPython(add_missing_team_responsibles),
|
|
]
|