@@ -58,21 +58,18 @@ def duration_string(duration):
5858 '''Custom duration_string to return HH:MM (no seconds)'''
5959 days = duration .days
6060 seconds = duration .seconds
61- microseconds = duration .microseconds
6261
6362 minutes = seconds // 60
64- seconds = seconds % 60
65-
6663 hours = minutes // 60
6764 minutes = minutes % 60
6865
6966 string = '{:02d}:{:02d}' .format (hours , minutes )
7067 if days :
7168 string = '{} ' .format (days ) + string
72- if microseconds :
73- string += '.{:06d}' .format (microseconds )
7469
7570 return string
71+
72+
7673# -------------------------------------------------
7774# Forms
7875# -------------------------------------------------
@@ -547,7 +544,11 @@ def prepare_value(self, value):
547544 return ''
548545
549546 def to_python (self , value ):
550- return datetime .timedelta (seconds = round (float (value ))) if value not in self .empty_values else None
547+ if value in self .empty_values or (isinstance (value , str ) and not value .isnumeric ()):
548+ return None # treat non-numeric values as empty
549+ else :
550+ # noinspection PyTypeChecker
551+ return datetime .timedelta (seconds = round (float (value )))
551552
552553 def valid_value (self , value ):
553554 return super ().valid_value (self .prepare_value (value ))
@@ -609,11 +610,15 @@ class Meta:
609610
610611 def clean (self ):
611612 super ().clean ()
613+ # Fill in on_agenda. If this is a new instance or we have changed its purpose, then use
614+ # the on_agenda value for the purpose. Otherwise, keep the value of an existing instance (if any)
615+ # or leave it blank.
612616 if 'purpose' in self .cleaned_data and (
613- 'purpose' in self . changed_data or self .instance .pk is None
617+ self .instance .pk is None or ( self . instance . purpose != self . cleaned_data [ 'purpose' ])
614618 ):
615619 self .cleaned_data ['on_agenda' ] = self .cleaned_data ['purpose' ].on_agenda
616-
620+ elif self .instance .pk is not None :
621+ self .cleaned_data ['on_agenda' ] = self .instance .on_agenda
617622 return self .cleaned_data
618623
619624 class Media :
@@ -629,10 +634,9 @@ def __init__(self, instance, *args, **kwargs):
629634 super ().__init__ (instance = instance , group = instance .group , * args , ** kwargs )
630635
631636
632- class SessionDetailsInlineFormset (forms .BaseInlineFormSet ):
637+ class SessionDetailsInlineFormSet (forms .BaseInlineFormSet ):
633638 def __init__ (self , group , meeting , queryset = None , * args , ** kwargs ):
634639 self ._meeting = meeting
635- self .created_instances = []
636640
637641 # Restrict sessions to the meeting and group. The instance
638642 # property handles one of these for free.
@@ -654,12 +658,6 @@ def save_new(self, form, commit=True):
654658 form .instance .meeting = self ._meeting
655659 return super ().save_new (form , commit )
656660
657- def save (self , commit = True ):
658- existing_instances = set (form .instance for form in self .forms if form .instance .pk )
659- saved = super ().save (commit )
660- self .created_instances = [inst for inst in saved if inst not in existing_instances ]
661- return saved
662-
663661 @property
664662 def forms_to_keep (self ):
665663 """Get the not-deleted forms"""
@@ -669,7 +667,7 @@ def sessiondetailsformset_factory(min_num=1, max_num=3):
669667 return forms .inlineformset_factory (
670668 Group ,
671669 Session ,
672- formset = SessionDetailsInlineFormset ,
670+ formset = SessionDetailsInlineFormSet ,
673671 form = SessionDetailsForm ,
674672 can_delete = True ,
675673 can_order = False ,
0 commit comments