def create(request,id): data = {} student = Student.objects.get(pk=id) subject = Subject() subject.subject_name = request.POST.get('subject_name') subject.student = student subject.save() data['name'] = subject.subject_name data['id'] = subject.id return JsonResponse(data)
def subjects(request): if request.POST: item = Subject( name=request.POST['name'], level_3=request.POST['level_3'], level_4=request.POST['level_4'], level_5=request.POST['level_5'], ) item.save() object_list = Subject.objects.all().order_by("name") return render(request, 'subjects/index.html', locals())
def post(self, request, pk: int = None): if 'delete' in request.POST: subject = Subject.objects.get(id=pk) subject.delete() object_list = Subject.objects.all().order_by("name") return render(request, 'subjects/index.html', locals()) else: item = Subject( name=request.POST['name'], level_3=request.POST['level_3'], level_4=request.POST['level_4'], level_5=request.POST['level_5'], attendance_score=request.POST['attendance_score'], ) item.save() object_list = Subject.objects.all().order_by("name") return render(request, 'subjects/index.html', locals())
def add(request): if request.method == "POST": form = request.POST subject = Subject() subject.name = form['name'] subject.score = form['score'] subject.student = Student.objects.get(pk=form['student']) subject.save() return redirect('subjects:subject_detail',subject.pk) students = Student.objects.all() context = { 'students':students, 'subjects':subjects } return render(request, 'subjects/addSubject.html',context)
def test_subject(self): subject = Subject(user=self.user, uni=self.uni, name='foo') serializer = SearchSerializer(subject, context={'auth_user': self.user}) self.assertEqual(serializer.data['label'], 'foo') self.assertEqual(serializer.data['data']['name'], 'foo')
def store_subjects(path): """ Gets subjects data from subjects.json (generated by web scraping) and instantiates Subject objects in the database """ subjects_data = json_to_data(path) subjects = subjects_data["subjects"] for subject in subjects: institute_instance = Institute.objects.get( initials=subject["institute"]) try: semester_instance = Semester.objects.get( year=subject["semester"]["year"], semester=subject["semester"]["semester"]) except: semester_instance = Semester( year=subject["semester"]["year"], semester=subject["semester"]["semester"]) semester_instance.save() subject_instance = Subject(initials=subject["initials"], name=subject["name"], syllabus=subject["syllabus"], workload=string_to_int(subject["workload"]), institute=institute_instance) subject_instance.save() semester_instance.subjects.add(subject_instance) for pre_req_obj in subject["pre_reqs"]: for pre_req in pre_req_obj["pre_reqs"]: if pre_req != "": try: pre_req_instance = PreReq.objects.get( initials=str(pre_req), year_start=pre_req_obj["year_start"], year_end=pre_req_obj["year_end"]) except: pre_req_instance = PreReq( initials=str(pre_req), year_start=pre_req_obj["year_start"], year_end=pre_req_obj["year_end"]) pre_req_instance.save() subject_instance.prereqs.add(pre_req_instance) for cont_elem in subject["continencies"]: if cont_elem != "": try: continence = Continence.objects.get( initials=str(cont_elem)) except: continence = Continence(initials=str(cont_elem)) continence.save() subject_instance.continences.add(continence) for equiv_elem in subject["equivalencies"]: if equiv_elem != "": try: equivalence = Equivalence.objects.get( initials=str(equiv_elem)) except: equivalence = Equivalence(initials=str(equiv_elem)) equivalence.save() subject_instance.equivalences.add(equivalence)
def mutate(self, info, name, short_name, description): subject = Subject(name=name, short_name=short_name, description=description) subject.save() return CreateSubject(subject=subject)