prevent users to use 0 as planned session value
This commit is contained in:
@@ -1764,6 +1764,9 @@ class PlannedSession(models.Model):
|
|||||||
return stri
|
return stri
|
||||||
|
|
||||||
def save(self, *args, **kwargs):
|
def save(self, *args, **kwargs):
|
||||||
|
if self.sessionvalue <= 0:
|
||||||
|
self.sessionvalue = 1
|
||||||
|
|
||||||
# sort units
|
# sort units
|
||||||
if self.sessionmode == 'distance':
|
if self.sessionmode == 'distance':
|
||||||
if self.sessionunit not in ['m','km']:
|
if self.sessionunit not in ['m','km']:
|
||||||
@@ -2005,6 +2008,14 @@ class IndoorVirtualRaceForm(ModelForm):
|
|||||||
cd = self.cleaned_data
|
cd = self.cleaned_data
|
||||||
timezone_str = cd['timezone']
|
timezone_str = cd['timezone']
|
||||||
|
|
||||||
|
value = cd['sessionvalue']
|
||||||
|
if value <= 0:
|
||||||
|
raise forms.ValidationError('The Value must be a positive, non-zero value')
|
||||||
|
|
||||||
|
unit = cd['sessionunit']
|
||||||
|
if unit == 'm' and value < 100:
|
||||||
|
raise forms.ValidationError('Minimum distance is 100m')
|
||||||
|
|
||||||
start_time = cd['start_time']
|
start_time = cd['start_time']
|
||||||
if start_time is None:
|
if start_time is None:
|
||||||
raise forms.ValidationError(
|
raise forms.ValidationError(
|
||||||
|
|||||||
@@ -327,7 +327,10 @@ def is_session_complete_ws(ws,ps):
|
|||||||
if not completiondate and score>=cratiomin*value:
|
if not completiondate and score>=cratiomin*value:
|
||||||
completiondate = w.date
|
completiondate = w.date
|
||||||
|
|
||||||
ratio = score/float(value)
|
try:
|
||||||
|
ratio = score/float(value)
|
||||||
|
except ZeroDivisionError:
|
||||||
|
ratio = 0
|
||||||
|
|
||||||
verdict = 'better than nothing'
|
verdict = 'better than nothing'
|
||||||
|
|
||||||
@@ -581,7 +584,7 @@ def get_sessions(r,startdate=date.today(),
|
|||||||
startdate__lte=enddate,
|
startdate__lte=enddate,
|
||||||
enddate__gte=startdate,
|
enddate__gte=startdate,
|
||||||
).order_by("preferreddate","startdate","enddate").exclude(
|
).order_by("preferreddate","startdate","enddate").exclude(
|
||||||
sessiontype='race')
|
sessiontype='race').exclude(sessiontype='indoorrace')
|
||||||
|
|
||||||
return sps
|
return sps
|
||||||
|
|
||||||
|
|||||||
@@ -15583,6 +15583,9 @@ def plannedsession_edit_view(request,id=0,userid=0):
|
|||||||
|
|
||||||
if ps.manager != request.user:
|
if ps.manager != request.user:
|
||||||
raise PermissionDenied("You are not allowed to edit this planned session")
|
raise PermissionDenied("You are not allowed to edit this planned session")
|
||||||
|
|
||||||
|
if ps.sessiontype in ['race','indoorrace']:
|
||||||
|
raise PermissionDenied("You are not allowed to edit this planned session because it is a race")
|
||||||
|
|
||||||
if ps.team.all() or len(ps.rower.all())>1:
|
if ps.team.all() or len(ps.rower.all())>1:
|
||||||
url = reverse(plannedsession_teamedit_view,
|
url = reverse(plannedsession_teamedit_view,
|
||||||
|
|||||||
Reference in New Issue
Block a user