Example #1
0
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)
Example #2
0
def save_or_edit_subject(request, grade_id, subject_id):

    data = JSON_parse(request.POST.get('data'))

    print data

    if 'subject_name' in data:
        name = data['subject_name']
    else:
        return JSON_response({'status': "error"})
    if 'times' in data:
        times = data['times']

    try:
        grade = Grade.objects.get(id=grade_id)
    except Grade.DoesNotExist:
        return JSON_response({'status': "error"})

    print subject_id

    if int(subject_id) != -1:
        try:
            subject = Subject.objects.get(id=subject_id)
            subject.name=name
        except Subject.DoesNotExist:
            return JSON_response({'messege': 'school does not exists'})
    else:
        subject = Subject(
            name=name,
            grade=grade,
        )
        print "so far so good"
        subject.save()

    subject.time.clear()
    for d in times:
        if int(d['time_id'] == -1):
            t = TimeStamp(
                day=d['time_day'],
                tm=d['time_tm']
            )
            t.save()
        else:
            try:
                t = TimeStamp.objects.get(id=int(d['time_id']))
            except TimeStamp.DoesNotExist:
                return JSON_response({'messege': 'this should not happen'})


        subject.time.add(t)

    subject.save()
    print (subject_to_dict(subject, request.user))
    return JSON_response(subject_to_dict(subject, request.user))
Example #3
0
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 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)
Example #7
0
 def mutate(self, info, name, short_name, description):
     subject = Subject(name=name,
                       short_name=short_name,
                       description=description)
     subject.save()
     return CreateSubject(subject=subject)