Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions events/migrations/0059_studentpasswordresethistory.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2026-02-09 05:19
from __future__ import unicode_literals

from django.conf import settings
from django.db import migrations, models
import django.db.models.deletion


class Migration(migrations.Migration):

dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
('events', '0058_merge_20260105_1154'),
]

operations = [
migrations.CreateModel(
name='StudentPasswordResetHistory',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('changed_on', models.DateTimeField(auto_now_add=True)),
('status', models.PositiveSmallIntegerField(default=0, help_text='1 = success, 0 = failed')),
('batch', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='events.StudentBatch')),
('changed_by', models.ForeignKey(on_delete=django.db.models.deletion.PROTECT, to=settings.AUTH_USER_MODEL)),
],
options={
'db_table': 'student_password_reset_history',
'ordering': ['-changed_on'],
},
),
]
23 changes: 23 additions & 0 deletions events/migrations/0060_auto_20260209_1107.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
# -*- coding: utf-8 -*-
# Generated by Django 1.11.29 on 2026-02-09 05:37
from __future__ import unicode_literals

from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
('events', '0059_studentpasswordresethistory'),
]

operations = [
migrations.AlterModelOptions(
name='studentpasswordresethistory',
options={},
),
migrations.AlterModelTable(
name='studentpasswordresethistory',
table=None,
),
]
9 changes: 9 additions & 0 deletions events/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -1820,3 +1820,12 @@ class AcademicKey(models.Model):

def __str__(self):
return self.academic.institution_name

class StudentPasswordResetHistory(models.Model):
batch = models.ForeignKey('StudentBatch',on_delete=models.CASCADE)
changed_by = models.ForeignKey(User,on_delete=models.PROTECT)
changed_on = models.DateTimeField(auto_now_add=True)
status = models.PositiveSmallIntegerField(default=0,help_text="1 = success, 0 = failed")

def __str__(self):
return f"Batch {self.batch.id} | Status {self.status}"
8 changes: 7 additions & 1 deletion events/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -3336,6 +3336,7 @@ def handover(request):

return render(request, 'handover.html', context)


def reset_student_pwd(request):
context = {}
template = 'events/templates/reset_student_password.html'
Expand All @@ -3350,6 +3351,7 @@ def reset_student_pwd(request):
school = form.cleaned_data['school']
batches = form.cleaned_data['batches']
new_password = form.cleaned_data['new_password']
status = 0

batch_ids = [x.id for x in batches]
batches = StudentBatch.objects.filter(id__in=batch_ids)
Expand All @@ -3364,7 +3366,9 @@ def reset_student_pwd(request):
mdlUsers = MdlUser.objects.filter(email__in=emails)
mdlUsers.update(password=encript_password(new_password))
send_bulk_student_reset_mail(school,batches,users.count(), new_password,request.user)

status = 1

for batch in batches:StudentPasswordResetHistory.objects.create(batch=batch,changed_by=request.user,status=status)
# Add the success message
success_msg = "Password updated for {} students.".format(users.count())
messages.success(request, success_msg)
Expand All @@ -3375,6 +3379,8 @@ def reset_student_pwd(request):
return render(request,template,context)




def get_schools(request):
state_id = request.GET.get('state_id')
if state_id:
Expand Down