Fix timer add form to include user.

This commit is contained in:
Christopher Charbonneau Wells 2017-09-10 09:50:16 -04:00
parent 32da7873fa
commit 115ef15c48
2 changed files with 7 additions and 4 deletions

View File

@ -137,13 +137,11 @@ class TimerForm(forms.ModelForm):
fields = ['name'] fields = ['name']
def __init__(self, *args, **kwargs): def __init__(self, *args, **kwargs):
if 'user' in kwargs:
self.user = kwargs.pop('user') self.user = kwargs.pop('user')
super(TimerForm, self).__init__(*args, **kwargs) super(TimerForm, self).__init__(*args, **kwargs)
def save(self, commit=True): def save(self, commit=True):
instance = super(TimerForm, self).save(commit=False) instance = super(TimerForm, self).save(commit=False)
if 'user' in self:
instance.user = self.user instance.user = self.user
instance.save() instance.save()
return instance return instance

View File

@ -179,6 +179,11 @@ class TimerUpdate(PermissionRequiredMixin, UpdateView):
form_class = TimerForm form_class = TimerForm
success_url = '/timers' success_url = '/timers'
def get_form_kwargs(self):
kwargs = super(TimerUpdate, self).get_form_kwargs()
kwargs.update({'user': self.request.user})
return kwargs
def get_success_url(self): def get_success_url(self):
instance = self.get_object() instance = self.get_object()
return '/timer/{}/'.format(instance.id) return '/timer/{}/'.format(instance.id)