passing tests - teams can be created
This commit is contained in:
@@ -346,8 +346,9 @@ class Team(models.Model):
|
||||
def save(self, *args, **kwargs):
|
||||
manager = self.manager
|
||||
if manager.rower.rowerplan == 'basic':
|
||||
raise ValidationError(
|
||||
"Basic user cannot be team manager"
|
||||
if manager.rower.protrialexpires < datetime.date.today() and manager.rower.plantrialexpires < datetime.date.today():
|
||||
raise ValidationError(
|
||||
"Basic user cannot be team manager"
|
||||
)
|
||||
|
||||
if manager.rower.rowerplan in ['plan','pro']:
|
||||
@@ -695,8 +696,8 @@ class Rower(models.Model):
|
||||
planexpires = models.DateField(default=current_day)
|
||||
teamplanexpires = models.DateField(default=current_day)
|
||||
clubsize = models.IntegerField(default=0)
|
||||
protrialexpires = models.DateField(blank=True,null=True)
|
||||
plantrialexpires = models.DateField(blank=True,null=True)
|
||||
protrialexpires = models.DateField(default=datetime.date(1970,1,1))
|
||||
plantrialexpires = models.DateField(default=datetime.date(1970,1,1))
|
||||
|
||||
|
||||
# Privacy Data
|
||||
@@ -875,11 +876,12 @@ def check_teams_on_change(sender, **kwargs):
|
||||
action = kwargs.pop('action', None)
|
||||
pk_set = kwargs.pop('pk_set',None)
|
||||
if action == 'pre_add' and instance.rowerplan=='basic':
|
||||
for id in pk_set:
|
||||
team = Team.objects.get(id=id)
|
||||
if team.manager.rower.rowerplan not in ['coach']:
|
||||
raise ValidationError(
|
||||
"You cannot join a team led by a Pro or Self-Coach user"
|
||||
if instance.protrialexpires < datetime.date.today() and instance.plantrialexpires < datetime.date.today():
|
||||
for id in pk_set:
|
||||
team = Team.objects.get(id=id)
|
||||
if team.manager.rower.rowerplan not in ['coach']:
|
||||
raise ValidationError(
|
||||
"You cannot join a team led by a Pro or Self-Coach user"
|
||||
)
|
||||
|
||||
m2m_changed.connect(check_teams_on_change, sender=Rower.team.through)
|
||||
@@ -1905,9 +1907,10 @@ class PlannedSession(models.Model):
|
||||
manager = self.manager
|
||||
if self.sessiontype not in ['race','indoorrace']:
|
||||
if manager.rower.rowerplan in ['basic','pro']:
|
||||
raise ValidationError(
|
||||
"Basic user cannot be team manager"
|
||||
)
|
||||
if manager.rower.plantrialexpires < timezone.now().date():
|
||||
raise ValidationError(
|
||||
"You must be a Self-Coach user or higher to create a planned session"
|
||||
)
|
||||
|
||||
|
||||
# sort units
|
||||
|
||||
Reference in New Issue
Block a user