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
7 changes: 6 additions & 1 deletion api/views/default.py
Original file line number Diff line number Diff line change
Expand Up @@ -392,7 +392,7 @@ def add_student_to_class(request, class_id):
username = data["username"]

errors = []

already_assigned = []
for username in data["username"]:
username = username.strip().upper()
user = None
Expand All @@ -406,6 +406,10 @@ def add_student_to_class(request, class_id):
user.save()

if user:
if Class.objects.filter(subject=clazz.subject, students=user).exists():
already_assigned.append(username)
errors.append(username)
continue
clazz.students.add(user)
else:
errors.append(username)
Expand All @@ -414,6 +418,7 @@ def add_student_to_class(request, class_id):
{
"success": not errors,
"not_found": errors,
"already_assigned": already_assigned,
}
)

Expand Down
9 changes: 7 additions & 2 deletions common/bulk_import.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,7 @@ class ImportResult:
firstname: str
lastname: str
created: bool
already_assigned: bool


def run(
Expand Down Expand Up @@ -103,6 +104,7 @@ def run(
firstname, lastname = student.firstName, student.secondName

created = False
already_assigned = False

student_user = None
try:
Expand All @@ -111,6 +113,9 @@ def run(
student_user = user_from_login(login)
created = True

class_in_db[c].students.add(student_user)
if Class.objects.filter(subject=class_in_db[c].subject, students=user).exists():
already_assigned = True
else:
class_in_db[c].students.add(student_user)

yield ImportResult(login, firstname, lastname, created)
yield ImportResult(login, firstname, lastname, created, already_assigned)
7 changes: 5 additions & 2 deletions frontend/src/AddStudentsToClass.svelte
Original file line number Diff line number Diff line change
Expand Up @@ -42,8 +42,11 @@ async function addStudents() {
let res = await req.json();
if (res) {
if (res['not_found'].length) {
addStudentError = 'Not found users left in textarea.';
textarea = res['not_found'].join('\n');
addStudentError =
'Not found users left in textarea. Already assigned students are separated by a newline';
textarea = res['not_found'].filter((x) => !res['already_assigned'].includes(x)).join('\n');
textarea += '\n\n';
textarea += res['already_assigned'].join('\n');
dispatch('update');
} else if (res['success'] === true) {
textarea = '';
Expand Down
3 changes: 3 additions & 0 deletions frontend/src/Teacher/InbusImport.vue
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ interface ImportResult {
firstname: string;
lastname: string;
created: boolean;
already_assigned: boolean;
}

interface Result {
Expand Down Expand Up @@ -374,6 +375,7 @@ function onTeacherSelected(event) {
<th>First name</th>
<th>Last name</th>
<th>User created</th>
<th>Already assigned</th>
</tr>
</thead>
<tbody>
Expand All @@ -382,6 +384,7 @@ function onTeacherSelected(event) {
<td>{{ item.firstname }}</td>
<td>{{ item.lastname }}</td>
<td>{{ item.created }}</td>
<td>{{ item.already_assigned }}</td>
</tr>
</tbody>
</table>
Expand Down
Loading