test writing (initial set) complete
might need to add permissions for viewin
This commit is contained in:
@@ -349,6 +349,15 @@ class Team(models.Model):
|
||||
raise ValidationError(
|
||||
"Basic user cannot be team manager"
|
||||
)
|
||||
|
||||
if manager.rower.rowerplan in ['plan','pro']:
|
||||
otherteams = Team.objects.filter(manager=manager)
|
||||
if len(otherteams) >= 1:
|
||||
raise ValidationError(
|
||||
"Pro and Self-Coach users cannot have more than one team"
|
||||
)
|
||||
|
||||
super(Team, self).save(*args,**kwargs)
|
||||
|
||||
|
||||
class TeamForm(ModelForm):
|
||||
@@ -844,6 +853,7 @@ class Rower(models.Model):
|
||||
def clean_email(self):
|
||||
return self.user.email.lower()
|
||||
|
||||
|
||||
class DeactivateUserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
@@ -856,13 +866,31 @@ class DeleteUserForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = User
|
||||
fields = []
|
||||
|
||||
|
||||
from django.db.models.signals import m2m_changed
|
||||
|
||||
@receiver(models.signals.post_save,sender=Rower)
|
||||
def auto_delete_teams_on_change(sender, instance, **kwargs):
|
||||
if instance.rowerplan != 'coach':
|
||||
teams = Team.objects.filter(manager=instance.user)
|
||||
for team in teams:
|
||||
team.delete()
|
||||
def check_teams_on_change(sender, **kwargs):
|
||||
instance = kwargs.pop('instance', None)
|
||||
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"
|
||||
)
|
||||
|
||||
m2m_changed.connect(check_teams_on_change, sender=Rower.team.through)
|
||||
|
||||
|
||||
#@receiver(models.signals.post_save,sender=Rower)
|
||||
#def auto_delete_teams_on_change(sender, instance, **kwargs):
|
||||
# if instance.rowerplan != 'coach':
|
||||
# teams = Team.objects.filter(manager=instance.user)
|
||||
# for team in teams:
|
||||
# team.delete()
|
||||
|
||||
from rowers.metrics import axlabels
|
||||
favchartlabelsx = axlabels.copy()
|
||||
@@ -1149,6 +1177,12 @@ class TrainingPlan(models.Model):
|
||||
return stri
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
manager = self.manager
|
||||
if manager.rowerplan in ['basic','pro']:
|
||||
raise ValidationError(
|
||||
"Basic user cannot have a training plan"
|
||||
)
|
||||
|
||||
if self.enddate < self.startdate:
|
||||
startdate = self.startdate
|
||||
enddate = self.enddate
|
||||
@@ -1194,6 +1228,7 @@ class TrainingPlan(models.Model):
|
||||
else:
|
||||
createmacrofillers(self)
|
||||
|
||||
|
||||
class TrainingPlanForm(ModelForm):
|
||||
class Meta:
|
||||
model = TrainingPlan
|
||||
@@ -1563,6 +1598,8 @@ class TrainingMacroCycle(models.Model):
|
||||
meso.save()
|
||||
else:
|
||||
createmesofillers(self)
|
||||
|
||||
|
||||
|
||||
class TrainingMacroCycleForm(ModelForm):
|
||||
class Meta:
|
||||
@@ -1649,6 +1686,7 @@ class TrainingMesoCycle(models.Model):
|
||||
else:
|
||||
createmicrofillers(self)
|
||||
|
||||
|
||||
class TrainingMicroCycle(models.Model):
|
||||
plan = models.ForeignKey(TrainingMesoCycle)
|
||||
name = models.CharField(max_length=150,blank=True)
|
||||
@@ -1863,6 +1901,14 @@ class PlannedSession(models.Model):
|
||||
def save(self, *args, **kwargs):
|
||||
if self.sessionvalue <= 0:
|
||||
self.sessionvalue = 1
|
||||
|
||||
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"
|
||||
)
|
||||
|
||||
|
||||
# sort units
|
||||
if self.sessionmode == 'distance':
|
||||
|
||||
Reference in New Issue
Block a user