Commit 178a4af1 authored by Sli's avatar Sli
Browse files

Add lazy way to make an user property editable once only

parent 579c25d6
Pipeline #294 failed with stage
in 2 minutes and 31 seconds
......@@ -318,25 +318,23 @@ class UserUpdateProfileView(UserTabsMixin, CanEditMixin, UpdateView):
template_name = "core/user_edit.jinja"
form_class = UserProfileForm
current_tab = "edit"
edit_once = ['profile_pict', 'date_of_birth', 'first_name', 'last_name']
def remove_once_edited_fields(self, request):
for i in self.edit_once:
if getattr(self.form.instance, i) and not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop(i, None)
def get(self, request, *args, **kwargs):
self.object = self.get_object()
self.form = self.get_form()
if self.form.instance.profile_pict and not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop('profile_pict', None)
if self.form.instance.date_of_birth and not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop('date_of_birth')
if self.form.instance.first_name and not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop('first_name')
if self.form.instance.last_name and not (request.user.is_board_member or request.user.is_root):
self.form.fields.pop('last_name')
self.remove_once_edited_fields(request)
return self.render_to_response(self.get_context_data(form=self.form))
def post(self, request, *args, **kwargs):
self.object = self.get_object()
self.form = self.get_form()
if self.form.instance.profile_pict and not request.user.is_in_group(settings.SITH_MAIN_BOARD_GROUP):
self.form.fields.pop('profile_pict', None)
self.remove_once_edited_fields(request)
files = request.FILES.items()
self.form.process(files)
if request.user.is_authenticated() and request.user.can_edit(self.object) and self.form.is_valid():
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment