update some preferences views

This commit is contained in:
2022-06-14 19:33:58 -05:00
parent 1f98127778
commit 49fdf9ab04

View File

@@ -5,7 +5,7 @@ from django.views.generic.edit import FormView
from teamsnap.views import get_teamsnap_client
from .forms import AccountForm, PlayerFormSet, PreferencesForm
from .models import Player
from .models import Account, Player, Preferences
from .utils import gamechanger
@@ -32,6 +32,19 @@ class PreferencesFormView(FormView):
return initial
def get_form(self):
"""
Returns the initial data to use for forms on this view.
"""
try:
contact = Preferences.objects.get(user=self.request.user)
form = PreferencesForm(instance=contact, **self.get_form_kwargs())
except Preferences.DoesNotExist:
form = super().get_form(self.form_class)
return form
class AccountFormView(FormView):
template_name = "gamechanger/form.html"
@@ -56,6 +69,19 @@ class AccountFormView(FormView):
return initial
def get_form(self):
"""
Returns the initial data to use for forms on this view.
"""
try:
contact = Account.objects.get(user=self.request.user)
form = AccountForm(instance=contact, **self.get_form_kwargs())
except Account.DoesNotExist:
form = super().get_form(self.form_class)
return form
def roster_import(request):
if request.method == "GET":