Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ss 643 make an option to edit account details #235

Draft
wants to merge 13 commits into
base: develop
Choose a base branch
from
44 changes: 43 additions & 1 deletion common/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,8 @@
from common.models import EmailVerificationTable, UserProfile
from studio.utils import get_logger

from django.utils.translation import gettext_lazy as _

logger = get_logger(__name__)


Expand Down Expand Up @@ -370,7 +372,7 @@ class Meta:
def __repr__(self) -> str:
return f"{self.__class__.__name__}({self.data})"

'''
class ProfileEditForm(BootstrapErrorFormMixin, forms.ModelForm):
affiliation = forms.ChoiceField(
widget=forms.Select(attrs={"class": "form-control"}),
Expand Down Expand Up @@ -403,4 +405,44 @@ class Meta:

def __repr__(self):
return f"{self.__class__.__name__}({self.data})"
'''

class ProfileEditForm(ProfileForm):


class Meta(ProfileForm.Meta):

exclude = ["note",
"why_account_needed",]

def __init__(self, *args, **kwargs):
super(ProfileEditForm, self).__init__(*args, **kwargs)
self.fields["affiliation"].disabled=True
#self.fields["affiliation"].required = False
self.fields["affiliation"].help_text="Affiliation can not be changed. Please email [email protected] with any questions."

'''
class UserEditForm(UserForm):


class Meta(UserForm.Meta):

exclude = [
"username",
"password1",
"password2",
]
def __init__(self, *args, **kwargs):
super(UserEditForm, self).__init__(*args, **kwargs)
self.fields["email"].disabled=True
self.fields["email"].help_text="Email address can not be changed. Please email [email protected] with any questions."
del self.fields["password1"]
del self.fields["password2"]
self.fields["email"].required = False
'''






10 changes: 7 additions & 3 deletions common/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -167,7 +167,9 @@ def get(self, request, *args, **kwargs):
profile_edit_form = self.profile_edit_form_class(initial={
"affiliation" : user_profile_data.affiliation,
"department" : user_profile_data.department
})
})


user_edit_form = self.user_edit_form_class(initial={
"email" : user_profile_data.user.email,
"first_name" : user_profile_data.user.first_name,
Expand Down Expand Up @@ -206,7 +208,9 @@ def post(self, request, *args, **kwargs):
# was invalid

#print (form.errors)
logger.error("Edit user error: " + str(user_form_details.errors), exc_info=True)
logger.error("Edit profile error: " + str(profile_form_details.errors), exc_info=True)
if user_form_details.is_valid()==False:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if user_form_details.is_valid()==False:
if not user_form_details.is_valid():

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrote it.

logger.error("Edit user error: " + str(user_form_details.errors), exc_info=True)
if profile_form_details.is_valid()==False:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Suggested change
if profile_form_details.is_valid()==False:
if not profile_form_details.is_valid():

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

rewrote it.

logger.error("Edit profile error: " + str(profile_form_details.errors), exc_info=True)

return render(request, self.template_name, {"form": user_form_details, "profile_form": profile_form_details})
Loading