Skip to content

Commit

Permalink
Enable inline editing for Notifications form
Browse files Browse the repository at this point in the history
  • Loading branch information
robertknight committed Aug 30, 2016
1 parent 3bd5518 commit 3bc6931
Showing 1 changed file with 11 additions and 10 deletions.
21 changes: 11 additions & 10 deletions h/accounts/views.py
Expand Up @@ -590,7 +590,7 @@ def __init__(self, request):
self.request = request
self.schema = schemas.NotificationsSchema().bind(request=self.request)
self.form = request.create_form(self.schema,
buttons=(_('Save changes'),))
buttons=(_('Save'),))

@view_config(request_method='GET')
def get(self):
Expand All @@ -600,23 +600,24 @@ def get(self):
for n in self._user_notifications()
if n.active)
})
return {'form': self.form.render()}
return self._template_data()

@view_config(request_method='POST')
def post(self):
"""Process notifications POST data."""
try:
appstruct = self.form.validate(self.request.POST.items())
except deform.ValidationFailure:
return {'form': self.form.render()}
return form.handle_form_submission(
self.request,
self.form,
on_success=self._update_notifications,
on_failure=self._template_data,
inline_editing=True)

def _update_notifications(self, appstruct):
for n in self._user_notifications():
n.active = n.type in appstruct['notifications']

self.request.session.flash(_("Success. We've saved your changes."),
'success')
return httpexceptions.HTTPFound(
location=self.request.route_url('account_notifications'))
def _template_data(self):
return {'form': self.form.render(inline_editing=True)}

def _user_notifications(self):
"""Fetch the notifications/subscriptions for the logged-in user."""
Expand Down

0 comments on commit 3bc6931

Please sign in to comment.