This repository has been archived by the owner on Oct 1, 2024. It is now read-only.
-
-
Notifications
You must be signed in to change notification settings - Fork 261
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
12 changed files
with
87 additions
and
91 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -118,30 +118,24 @@ def save(self, commit=True): | |
user.address = self.cleaned_data.get("address") | ||
user.email = self.cleaned_data.get("email") | ||
|
||
# Generate a username based on first and last name and registration date | ||
registration_date = datetime.now().strftime("%Y%m%d%H%M") | ||
# Generate a username | ||
registration_date = datetime.now().strftime("%Y") | ||
total_lecturers_count = User.objects.filter(is_lecturer=True).count() | ||
generated_username = ( | ||
f"{user.first_name.lower()}{user.last_name.lower()}{registration_date}" | ||
f"{settings.LECTURER_ID_PREFIX}-{registration_date}-{total_lecturers_count}" | ||
) | ||
|
||
# Check if the generated username already exists, and regenerate if needed | ||
while User.objects.filter(username=generated_username).exists(): | ||
registration_date = datetime.now().strftime("%Y%m%d%H%M") | ||
generated_username = f"{user.first_name.lower()}{user.last_name.lower()}{registration_date}".replace( | ||
" ", "" | ||
) | ||
# Generate a password | ||
generated_password = User.objects.make_random_password() | ||
|
||
user.username = generated_username | ||
|
||
generated_password = User.objects.make_random_password() | ||
user.set_password(generated_password) | ||
|
||
if commit: | ||
user.save() | ||
|
||
# Send email with the generated credentials | ||
send_mail( | ||
"Your account credentials", | ||
"Your Django LMS account credentials", | ||
f"Your username: {generated_username}\nYour password: {generated_password}", | ||
"[email protected]", | ||
[user.email], | ||
|
@@ -285,30 +279,29 @@ def save(self, commit=True): | |
user.email = self.cleaned_data.get("email") | ||
|
||
# Generate a username based on first and last name and registration date | ||
registration_date = datetime.now().strftime("%Y%m%d%H%M") | ||
registration_date = datetime.now().strftime("%Y") | ||
total_students_count = Student.objects.count() | ||
generated_username = ( | ||
f"{user.first_name.lower()}{user.last_name.lower()}{registration_date}" | ||
f"{settings.STUDENT_ID_PREFIX}-{registration_date}-{total_students_count}" | ||
) | ||
|
||
# Check if the generated username already exists, and regenerate if needed | ||
while User.objects.filter(username=generated_username).exists(): | ||
registration_date = datetime.now().strftime("%Y%m%d%H%M") | ||
generated_username = f"{user.first_name.lower()}{user.last_name.lower()}{registration_date}".replace( | ||
" ", "" | ||
) | ||
# Generate a password | ||
generated_password = User.objects.make_random_password() | ||
|
||
user.username = generated_username | ||
|
||
generated_password = User.objects.make_random_password() | ||
user.set_password(generated_password) | ||
|
||
if commit: | ||
user.save() | ||
Student.objects.create( | ||
student=user, | ||
level=self.cleaned_data.get("level"), | ||
program=self.cleaned_data.get("program"), | ||
) | ||
|
||
# Send email with the generated credentials | ||
send_mail( | ||
"Your account credentials", | ||
f"Your username: {generated_username}\nYour password: {generated_password}", | ||
"Your Django LMS account credentials", | ||
f"Your ID: {generated_username}\nYour password: {generated_password}", | ||
settings.EMAIL_FROM_ADDRESS, | ||
[user.email], | ||
fail_silently=False, | ||
|
@@ -348,6 +341,15 @@ class ProfileUpdateForm(UserChangeForm): | |
label="Last Name", | ||
) | ||
|
||
gender = forms.CharField( | ||
widget=forms.Select( | ||
choices=GENDERS, | ||
attrs={ | ||
"class": "browser-default custom-select form-control", | ||
}, | ||
), | ||
) | ||
|
||
phone = forms.CharField( | ||
widget=forms.TextInput( | ||
attrs={ | ||
|
@@ -370,7 +372,15 @@ class ProfileUpdateForm(UserChangeForm): | |
|
||
class Meta: | ||
model = User | ||
fields = ["email", "phone", "address", "picture", "first_name", "last_name"] | ||
fields = [ | ||
"first_name", | ||
"last_name", | ||
"gender", | ||
"email", | ||
"phone", | ||
"address", | ||
"picture", | ||
] | ||
|
||
|
||
class EmailValidationOnForgotPassword(PasswordResetForm): | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters