Skip to content

Commit 4ce9cb4

Browse files
author
Celio Maximiano
committed
release: v1.2.5
1 parent 176df91 commit 4ce9cb4

2 files changed

Lines changed: 59 additions & 56 deletions

File tree

Lines changed: 57 additions & 54 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from flask import Blueprint, Response, jsonify, session, request
1+
from flask import Blueprint, Response, jsonify, session, request, current_app
22
from functools import wraps
33
from werkzeug.security import generate_password_hash
44
from db.database import db
@@ -52,19 +52,58 @@ def import_students():
5252
if course:
5353
courses.append(course)
5454

55+
app = current_app._get_current_object()
56+
5557
def generate():
56-
total = len(student_list)
57-
imported = 0
58-
skipped = 0
59-
errors = []
60-
61-
for i, entry in enumerate(student_list):
62-
name = entry.get('name', '').strip()
63-
email = entry.get('email', '').strip().lower()
64-
65-
if not email:
66-
errors.append(f'Linha {i + 1}: email vazio')
67-
skipped += 1
58+
with app.app_context():
59+
total = len(student_list)
60+
imported = 0
61+
skipped = 0
62+
errors = []
63+
64+
for i, entry in enumerate(student_list):
65+
name = entry.get('name', '').strip()
66+
email = entry.get('email', '').strip().lower()
67+
68+
if not email:
69+
errors.append(f'Linha {i + 1}: email vazio')
70+
skipped += 1
71+
yield json.dumps({
72+
'progress': {
73+
'current': i + 1,
74+
'total': total,
75+
'imported': imported,
76+
'skipped': skipped,
77+
}
78+
}) + '\n'
79+
continue
80+
81+
if not name:
82+
name = email.split('@')[0]
83+
84+
# Check existing
85+
existing = Student.query.filter(
86+
Student.email.ilike(email)
87+
).first()
88+
89+
if existing:
90+
# Add courses to existing student
91+
for c in courses:
92+
if c not in existing.courses:
93+
existing.courses.append(c)
94+
db.session.commit()
95+
skipped += 1
96+
else:
97+
# Create new student
98+
hashed = generate_password_hash(default_password)
99+
new_student = Student(email=email, password=hashed, name=name)
100+
db.session.add(new_student)
101+
db.session.flush()
102+
for c in courses:
103+
new_student.courses.append(c)
104+
db.session.commit()
105+
imported += 1
106+
68107
yield json.dumps({
69108
'progress': {
70109
'current': i + 1,
@@ -73,49 +112,13 @@ def generate():
73112
'skipped': skipped,
74113
}
75114
}) + '\n'
76-
continue
77-
78-
if not name:
79-
name = email.split('@')[0]
80-
81-
# Check existing
82-
existing = Student.query.filter(
83-
Student.email.ilike(email)
84-
).first()
85-
86-
if existing:
87-
# Add courses to existing student
88-
for c in courses:
89-
if c not in existing.courses:
90-
existing.courses.append(c)
91-
db.session.commit()
92-
skipped += 1
93-
else:
94-
# Create new student
95-
hashed = generate_password_hash(default_password)
96-
new_student = Student(email=email, password=hashed, name=name)
97-
db.session.add(new_student)
98-
db.session.flush()
99-
for c in courses:
100-
new_student.courses.append(c)
101-
db.session.commit()
102-
imported += 1
103115

104116
yield json.dumps({
105-
'progress': {
106-
'current': i + 1,
107-
'total': total,
108-
'imported': imported,
109-
'skipped': skipped,
110-
}
117+
'done': True,
118+
'imported': imported,
119+
'skipped': skipped,
120+
'total': total,
121+
'errors': errors,
111122
}) + '\n'
112123

113-
yield json.dumps({
114-
'done': True,
115-
'imported': imported,
116-
'skipped': skipped,
117-
'total': total,
118-
'errors': errors,
119-
}) + '\n'
120-
121124
return Response(generate(), mimetype='application/x-ndjson')

frontend/src/components/sidebar/NavUser.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ export function NavUser({ user, onLogout }: NavUserProps) {
5656
<div className="grid flex-1 text-left text-sm leading-tight">
5757
<span className="truncate font-medium">{user.name}</span>
5858
<span className="truncate text-[10px] text-muted-foreground/60">
59-
v1.2.4
59+
v1.2.5
6060
</span>
6161
</div>
6262
<i className="ri-arrow-up-down-line text-base text-muted-foreground" />
@@ -78,7 +78,7 @@ export function NavUser({ user, onLogout }: NavUserProps) {
7878
<div className="grid flex-1 text-left text-sm leading-tight">
7979
<span className="truncate font-medium">{user.name}</span>
8080
<span className="truncate text-[10px] text-muted-foreground/60">
81-
v1.2.4
81+
v1.2.5
8282
</span>
8383
</div>
8484
</div>

0 commit comments

Comments
 (0)