Allow setting game to Finished when creating PlayEvent
This commit is contained in:
parent
ad0641f95b
commit
7cf2180192
@ -1,4 +1,5 @@
|
|||||||
from django import forms
|
from django import forms
|
||||||
|
from django.db import transaction
|
||||||
from django.urls import reverse
|
from django.urls import reverse
|
||||||
|
|
||||||
from common.utils import safe_getattr
|
from common.utils import safe_getattr
|
||||||
@ -227,19 +228,30 @@ class PlayEventForm(forms.ModelForm):
|
|||||||
widget=forms.Select(attrs={"autofocus": "autofocus"}),
|
widget=forms.Select(attrs={"autofocus": "autofocus"}),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
mark_as_finished = forms.BooleanField(
|
||||||
|
required=False,
|
||||||
|
initial={"mark_as_finished": True},
|
||||||
|
label="Set game status to Finished",
|
||||||
|
)
|
||||||
|
|
||||||
class Meta:
|
class Meta:
|
||||||
model = PlayEvent
|
model = PlayEvent
|
||||||
fields = [
|
fields = ["game", "started", "ended", "note", "mark_as_finished"]
|
||||||
"game",
|
|
||||||
"started",
|
|
||||||
"ended",
|
|
||||||
"note",
|
|
||||||
]
|
|
||||||
widgets = {
|
widgets = {
|
||||||
"started": custom_date_widget,
|
"started": custom_date_widget,
|
||||||
"ended": custom_date_widget,
|
"ended": custom_date_widget,
|
||||||
}
|
}
|
||||||
|
|
||||||
|
def save(self, commit=True):
|
||||||
|
with transaction.atomic():
|
||||||
|
session = super().save(commit=False)
|
||||||
|
if self.cleaned_data.get("mark_as_finished"):
|
||||||
|
game_instance = session.game
|
||||||
|
game_instance.status = "f"
|
||||||
|
game_instance.save()
|
||||||
|
session.save()
|
||||||
|
return session
|
||||||
|
|
||||||
|
|
||||||
class GameStatusChangeForm(forms.ModelForm):
|
class GameStatusChangeForm(forms.ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
|
Loading…
x
Reference in New Issue
Block a user