Update last_updated when users edit their profile
+import datetime
+
from crispy_forms.helper import FormHelper
from crispy_forms.layout import Submit
@@ -21,7 +23,6 @@ from TWLight.view_mixins import CoordinatorOrSelf, SelfOnly, coordinators
from .forms import EditorUpdateForm, SetLanguageForm, TermsForm, EmailChangeForm
from .models import Editor, UserProfile
-
def _is_real_url(url):
"""
Users might have altered the URL parameters. Let's not just blindly
@@ -43,6 +44,12 @@ def _redirect_to_next_param(request):
return reverse_lazy('users:home')
+def _update_last_updated(editor):
+ # When users update their data, make sure to update last_updated
+ editor.last_updated = datetime.date.today()
+ editor.save()
+
+
class UserDetailView(SelfOnly, TemplateView):
template_name = 'users/user_detail.html'
@@ -157,6 +164,14 @@ class EditorUpdateView(SelfOnly, UpdateView):
form_class = EditorUpdateForm
+ def form_valid(self, form):
+ editor = self.request.user.editor
+
+ _update_last_updated(editor)
+
+ return HttpResponseRedirect(self.get_success_url())
+
+
class PIIUpdateView(SelfOnly, UpdateView):
"""
@@ -202,6 +217,14 @@ class PIIUpdateView(SelfOnly, UpdateView):
return form
+ def form_valid(self, form):
+ editor = self.request.user.editor
+
+ _update_last_updated(editor)
+
+ return HttpResponseRedirect(self.get_success_url())
+
+
def get_success_url(self):
"""
Define get_success_url so that we can add a success message.
@@ -232,6 +255,8 @@ class EmailChangeView(SelfOnly, FormView):
user.userprofile.use_wp_email = form.cleaned_data['use_wp_email']
user.userprofile.save()
+ _update_last_updated(user.editor)
+
return HttpResponseRedirect(self.get_success_url())
