mirror of https://github.com/snachodog/mybuddy.git
Fix timer add form to include user.
This commit is contained in:
parent
32da7873fa
commit
115ef15c48
|
@ -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
|
||||||
|
|
|
@ -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)
|
||||||
|
|
Loading…
Reference in New Issue