-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathpractice.py
More file actions
71 lines (59 loc) · 1.92 KB
/
practice.py
File metadata and controls
71 lines (59 loc) · 1.92 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
from rest_framework.test import APIRequestFactory
from grade_sheets.views import GradeSheetViewSet # Adjust import path if needed
from students.models import Student
from enrollment.models import Enrollment
from levels.models import Level
from academic_years.models import AcademicYear
from subjects.models import Subject
from periods.models import Period
# Get the objects by their IDs
student = Student.objects.get(id=1)
level = Level.objects.get(id=1)
year = AcademicYear.objects.get(id=6) # 2026/2027
subject = Subject.objects.get(id=9) # Agriculture
period = Period.objects.get(period="1st")
enrollment = Enrollment.objects.get(student=student, level=level, academic_year=year)
# Prepare the grades list
grades = [
{
"student_id": student.id,
"score": 88, # Example score
"period_id": period.id
}
]
# Prepare the POST data
data = {
"level": level.id,
"subject_id": subject.id,
"period_id": period.id,
"grades": grades,
"academic_year": year.name
}
# Create the request and call the view
factory = APIRequestFactory()
request = factory.post('/api/grade_sheets/input/', data, format='json')
view = GradeSheetViewSet.as_view({'post': 'input_grades'})
response = view(request)
print(response.data)
from students.models import Student
from levels.models import Level
from academic_years.models import AcademicYear
from enrollment.models import Enrollment
from datetime import date
# Get the level and academic year
level = Level.objects.get(name="7")
year = AcademicYear.objects.get(name="2024/2025")
# Add the student with all required fields
student = Student.objects.create(
firstName="John",
lastName="Doe",
dob="2012-05-15", # Example date of birth
gender="M"
)
# Enroll the student (provide date_enrolled)
enrollment = Enrollment.objects.create(
student=student,
level=level,
academic_year=year,
date_enrolled=date.today() # or date(2024, 9, 1)
)