update some preferences views
This commit is contained in:
@@ -5,7 +5,7 @@ from django.views.generic.edit import FormView
|
|||||||
from teamsnap.views import get_teamsnap_client
|
from teamsnap.views import get_teamsnap_client
|
||||||
|
|
||||||
from .forms import AccountForm, PlayerFormSet, PreferencesForm
|
from .forms import AccountForm, PlayerFormSet, PreferencesForm
|
||||||
from .models import Player
|
from .models import Account, Player, Preferences
|
||||||
from .utils import gamechanger
|
from .utils import gamechanger
|
||||||
|
|
||||||
|
|
||||||
@@ -32,6 +32,19 @@ class PreferencesFormView(FormView):
|
|||||||
|
|
||||||
return initial
|
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):
|
class AccountFormView(FormView):
|
||||||
template_name = "gamechanger/form.html"
|
template_name = "gamechanger/form.html"
|
||||||
@@ -56,6 +69,19 @@ class AccountFormView(FormView):
|
|||||||
|
|
||||||
return initial
|
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):
|
def roster_import(request):
|
||||||
if request.method == "GET":
|
if request.method == "GET":
|
||||||
|
|||||||
Reference in New Issue
Block a user