Esempio n. 1
0
    def post(self):
        token = self.get_argument('stripeToken')
        amount = int(self.get_argument('amount')) * 100
        name = self.get_argument('name')
        email = self.get_argument('email')
        currency = "usd"
        description = "Donation to west coast economics x-term."

        charge = stripe.Charge.create(
            amount=amount,
            card=token,
            description=description,
            currency=currency
        )

        p = Person()
        p.name = name
        p.email = email
        p.stripe_charge_id = charge.id
        p.amount = amount

        database.session.add(p)
        database.session.commit()

        self.redirect('/receipts/%s' % p.stripe_charge_id)
Esempio n. 2
0
def get_person_http(name):
    with flask_to_scope(flask_tracer, request) as scope:
        person = Person.get(name)
        if person is None:
            if name in ["Neonicotinoid", "Insecticide", "DDT"]:
                raise Exception(f"{name}s are not kind to bees.")
            person = Person()
            person.name = name
        else:
            person.description
        response = {
            'name': person.name,
            'title': person.title,
            'description': person.description,
        }
        opentracing.tracer.active_span.log_kv(response)
        return json.dumps(response)
Esempio n. 3
0
 def insert_person(self, person):
     exists = self.session.query(Person).filter_by(
         name=person['name']).first()
     if not exists:
         pers = Person(name=person['name'])
         self.session.add(pers)
         logger.write_log("added: " + person['name'] + " to database")
     self.session.commit()
Esempio n. 4
0
def add_person_to_database(first_name_arg, last_name_arg, age_arg):
    new_person = Person(first_name=first_name_arg,
                        last_name=last_name_arg,
                        age=age_arg)
    new_person.save()
    return
Esempio n. 5
0
    def save_state(self, db_name='amity_db'):
        '''This methods saves informatin from
        the application to the database'''

        if db_name:
            engine = create_engine('sqlite:///%s' % db_name)

        else:
            engine = create_engine('sqlite:///amity_db')

        Base.metadata.create_all(engine)
        Session = sessionmaker(bind=engine)
        session = Session()
        # go through every person
        for person in self.all_people:
            # condition for a fellow object
            if isinstance(person, Fellow):
                fellow = Mtu()
                # put data to columns
                fellow.name = person.name
                fellow.role = 'Fellow'
                if person.office is None:
                    fellow.office = 'has no office'
                else:
                    fellow.office = person.office.name
                if person.hostel is None:
                    fellow.living_space = "no room"
                else:
                    fellow.living_space = person.hostel.name

                session.add(fellow)
                session.commit()

            # condition for a Staff object
            elif isinstance(person, Staff):
                staff = Mtu()
                # put data to columns
                staff.name = person.name
                staff.role = 'Staff'

                staff.office = person.office.name

                session.add(staff)
                session.commit()

        # go through all rooms
        for room in self.all_rooms:
            if isinstance(room, Office):
                office_room = Ofisi()
                office_room.name = room.name

                session.add(office_room)
                session.commit()

            elif isinstance(room, LivingSpace):
                hostel_room = Hostel()
                hostel_room.name = room.name
                session.add(hostel_room)
                session.commit()
Esempio n. 6
0
def add_another_person_to_database():
    another_person = Person(first_name="Bob", last_name="Boynton", age=35)
    another_person.save()
Esempio n. 7
0
def resolve_delete_person(_, info, id):
    """Removes a given person from the database."""
    return Person.delete(id=id)
Esempio n. 8
0
def resolve_create_person(_, info, name, age, last_name):
    """Creates a new person in the database."""
    person = Person.create(name, last_name, age)
    return person