def post(self):
        '''POST /subjects/ -> add a new subject
        '''
        data = subjectResource.parser.parse_args()
        subject_name = data.get('name')
        subject_age = data.get('age')

        subject = Subject(subject_name, subject_age)
        subject.save()

        return subject.json(), 201
示例#2
0
def create():
    s = Subject(
        category=request.form['category']
    )

    if s.save():
        flash("Subject created")
    else:
        flash("Subject not created", errors = s.errors)
示例#3
0
# This file shall only run once upon initiation
# To be placed in Procfile -> release: section

# if there are no subjects in database yet,
# create a list of preset subjects.

print("Loading environment variables from .env")
from dotenv import load_dotenv
load_dotenv()

from models.subject import Subject

exist_subjects = Subject.select()

if not len(exist_subjects):
    presets = [
        "Language", "Mathematics", "Coding", "Accounting", "Life Skills"
    ]
    for p in presets:
        subject = Subject(category=p)
        if subject.save():
            print(f"Subject {p} saved.")
        else:
            print(f"Unable to create subject {p}.")
示例#4
0
import sys, os
sys.path.append(os.path.join(os.getcwd(), ".."))

from models.collections import Collections

from models.subject import Subject

from persistence import mongoInterface

mongoInterface.setup()

collections = Collections()
collections.save(mongoInterface)

for collectionId, subjectsIds in collections.getCollections():
    print "############################"
    print "# Preprocessing collection: " + collectionId
    print "############################\n"
    for subjectId in subjectsIds:
        try:
            subject = Subject(subjectId)
            subject.fetch()
            subject.parse()
            subject.save(mongoInterface)
        except (OSError, Exception) as e:
            print "Error: ", e

mongoInterface.close()
示例#5
0
    def get(self):
        
        # Load all Guardians
        path = os.path.join(os.path.dirname(__file__), 'data/voogdouder.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_guardian = Guardian(key_name=row[0].strip())
            new_guardian.title=row[1].strip()
            new_guardian.initials=row[2].strip()
            new_guardian.preposition=row[3].strip()
            new_guardian.lastname=row[4].strip()
            new_guardian.streetname=row[6].strip()
            new_guardian.housenumber=row[7].strip()
            new_guardian.city=row[8].strip()
            new_guardian.postalcode=row[9].strip()
            new_guardian.email=row[12].strip()
            new_guardian.save()
            print "Guardian " + new_guardian.key().id_or_name() + " stored"

        # Load all Students
        path = os.path.join(os.path.dirname(__file__), 'data/leerlingen.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_student = Student(key_name=row[0].strip())
            new_student.firstname=row[1].strip()
            new_student.preposition=row[2].strip()
            new_student.lastname=row[3].strip()
            new_student.gender=row[4].strip()
            new_student.class_id=row[5].strip()
            new_student.guardian=Guardian.all().filter("__key__ >=", Key.from_path('Guardian', row[6].strip())).get()
            new_student.save()
            print "Student " + new_student.key().id_or_name() + " stored"
            
        # Load all Teachers
        path = os.path.join(os.path.dirname(__file__), 'data/docenten.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader:
            new_teacher = Teacher(key_name=row[0].strip())
            new_teacher.name=row[1].strip()
            new_teacher.boxnumber=int(row[2].strip())
            new_teacher.email=row[3].strip()
            new_teacher.save()
            print "Teacher " + new_teacher.key().id_or_name() + " stored"
            
        # Load all Subjects
        path = os.path.join(os.path.dirname(__file__), 'data/vakken.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader:
            new_subject = Subject(key_name=row[0].strip())
            new_subject.name=row[1].strip()
            new_subject.save()
            print "Subject " + new_subject.key().id_or_name() + " stored"

        # Load all Students
        path = os.path.join(os.path.dirname(__file__), 'data/docent_vak.txt')
        my_file = open(path)
        fileReader = csv.reader(my_file, delimiter=";") 
        for row in fileReader: 
            new_combination = Combination()
            new_combination.class_id=row[0].strip()
            new_combination.subject=Subject.all().filter("__key__ >=", Key.from_path('Subject', row[1].strip())).get()
            new_combination.teacher=Teacher.all().filter("__key__ >=", Key.from_path('Teacher', row[2].strip())).get()
            new_combination.save()
            print "Combination " + str(new_combination.key().id_or_name()) + " stored"
        self.redirect("/fix")
示例#6
0
import sys, os
sys.path.append(os.path.join(os.getcwd(), ".."))

from models.collections import Collections

from models.subject import Subject

from persistence import mongoInterface


mongoInterface.setup()

collections = Collections()
collections.save(mongoInterface)

for collectionId, subjectsIds in collections.getCollections():
	print "############################"
	print "# Preprocessing collection: " + collectionId
	print "############################\n"
	for subjectId in subjectsIds:
		try:
			subject = Subject(subjectId)
			subject.fetch()
			subject.parse()
			subject.save(mongoInterface)
		except (OSError, Exception) as e:
			print "Error: ", e


mongoInterface.close()