feat: lets teacher entry thier own token an name in token

This commit is contained in:
a2nr 2026-05-12 08:09:16 +07:00
parent 31dfe87c60
commit c578d1b4d6
1 changed files with 7 additions and 25 deletions

View File

@ -80,38 +80,20 @@ def generate_tokens_csv():
and h not in ('token', 'nama_siswa')] and h not in ('token', 'nama_siswa')]
# Rebuild each row with the new header order # Rebuild each row with the new header order
other_rows = [] merged_rows = []
guru_row = None for i, row in enumerate(rows):
TEACHER_TOKEN = 'guru_123'
for row in rows:
new_row = {} new_row = {}
# Check if this is the teacher row (by token)
is_teacher = row.get('token', '').strip() == TEACHER_TOKEN
for h in new_headers: for h in new_headers:
if h in ('token', 'nama_siswa'): if h in ('token', 'nama_siswa'):
new_row[h] = row.get(h) # Ambil apa adanya dari baris yang sudah ada
new_row[h] = row.get(h, '')
else: else:
if is_teacher: # Baris pertama (index 0) selalu dipaksa completed
if i == 0:
new_row[h] = 'completed' new_row[h] = 'completed'
else: else:
new_row[h] = row.get(h, 'not_started') new_row[h] = row.get(h, 'not_started')
merged_rows.append(new_row)
if is_teacher:
guru_row = new_row
else:
other_rows.append(new_row)
# Ensure at least one Teacher exists
if not guru_row:
guru_row = {'token': TEACHER_TOKEN, 'nama_siswa': 'Pengajar'}
for h in lesson_names:
guru_row[h] = 'completed'
print(f"Teacher user with token '{TEACHER_TOKEN}' automatically added.")
# Always put Guru at the top
merged_rows = [guru_row] + other_rows
with open(TOKENS_FILE, 'w', newline='', encoding='utf-8') as f: with open(TOKENS_FILE, 'w', newline='', encoding='utf-8') as f:
writer = csv.DictWriter(f, fieldnames=new_headers, delimiter=';') writer = csv.DictWriter(f, fieldnames=new_headers, delimiter=';')