Exemplo n.º 1
0
    def create(self, objective_data, by_user):
        """Create a new Objective from the given data

        :param objective_data: is a dictionary of data used to populate the
                               initial Objective.  It must match the schema
                               defined within.
        :param by_user: the `User` who is creating the `Objective`.
        """

        creation_schema = merge(self._base_schema, {
            s.Optional('id'): None,
            'subject_id': s.Or(None, s.Use(int)),
        })

        o = s.Schema(creation_schema).validate(objective_data)
        self._validate_topic(o['topic_id'], o['subject_id'])
        self._validate_name(o['name'])

        prerequisites = self._validate_prerequisites(o['prerequisites'], by_user)

        now = datetime.utcnow()
        o['prerequisites'] = prerequisites
        o['created_by_id'] = by_user.id
        o['last_updated'] = now
        o['time_created'] = now
        objective = Objective(**o)
        db.session.add(objective)
        db.session.commit()
        return objective
Exemplo n.º 2
0
parent = User(email="*****@*****.**",
              password="******",
              name="Parent",
              time_registered=datetime.utcnow(),
              last_seen=datetime.utcnow(),
              role=ROLE_USER)
parent.students.append(student)

db.session.add(parent)

db.session.commit()

objective = Objective(
    name="Rationalise the denominator of fractions with surds",
    subject=maths,
    topic=number,
    created_by_id=User.main_admin_user().id
    #prerequisites=[Objective.query.get(2)]
)
db.session.add(objective)
db.session.commit()

objective = Objective(name="Estimate powers and roots of any given positive",
                      subject=maths,
                      topic=number,
                      created_by_id=User.main_admin_user().id
                      #prerequisites=[Objective.query.get(2)]
                      )
db.session.add(objective)
db.session.commit()