def delete(self, service_id):
     args = self.parser.parse_args()
     common_users_not_authorized(args['Authorization'])
     s = Service().query.get_or_404(service_id)
     if s is not None:
         s.remove()
         return '', 204
 def put(self, service_id):
     args = self.parser.parse_args()
     only_admins_authorized(args['Authorization'])
     s = Service().query.get_or_404(service_id)
     if args['owner_id'] is not None:
         u = User.query.get(args['owner_id'])
         s.owner = u
     elif args['owner_login'] is not None:
         u = User.query.filter_by(login=args['owner_login']).first()
         s.owner = u
     else:
         return 'You are not updating anything', 400
     s.insert()
     return {'service': marshal(s, service_fields)}, 201
 def post(self):
     args = self.parser.parse_args()
     bots_are_not_authorized(args['Authorization'])
     s = Service().query.filter_by(name=args['name']).first()
     if s is not None:
         abort(400, message="Service already exists")
     else:
         if is_user(args['Authorization']):
             u = User.query.filter_by(token=args['Authorization']).first()
         else:
             u = User.query.filter_by(login=args['owner_login']).first()
         s = Service(name=args['name'],
                     region=args['region'],
                     size=args['size'],
                     image=args['image'],
                     ssh_keys=args['ssh_keys'],
                     backups=args['backups'],
                     ipv6=args['ipv6'],
                     user_data=args['user_data'],
                     private_networking=args['private_networking'],
                     volumes=args['volumes'],
                     owner=u)
         s.insert()
         return {'service': marshal(s, service_fields)}, 201
Beispiel #4
0
def load_clinics(file_rows):
    """Load clinics into database"""

    print("Clinics")

    # Delete all rows in table, so if we need to run this a second time,
    # we won't be trying to add duplicate users
    # Clinic.query.delete()

    # Read file_rows and insert data
    for row in file_rows[1:]:
         # unpack part of each row
        clinic_id, clinic_name, city, state, director = row[:5]

        fresh_mul_1, fresh_mul_2, fresh_mul_3, fresh_mul_4, fresh_mul_5= map(convert_to_float, row[5:10])
        fresh_sin_1, fresh_sin_2, fresh_sin_3, fresh_sin_4, fresh_sin_5 = map(convert_to_float, row[10:15]) 
        fro_mul_1, fro_mul_2, fro_mul_3, fro_mul_4, fro_mul_5 = map(convert_to_float, row[15:20])
        fro_sin_1, fro_sin_2, fro_sin_3, fro_sin_4, fro_sin_5 = map(convert_to_float, row[20:25])

        is_sart, is_surrogates, is_single, is_eggcryo, is_embryocryo, is_donor_emb, is_donor_egg = row[-3:-10:-1]


        clinic = Clinic(clinic_name=clinic_name, city=city, state=state, director=director)

        rate = Rate(fresh_mul_1=fresh_mul_1, fresh_mul_2=fresh_mul_2, fresh_mul_3=fresh_mul_3, fresh_mul_4=fresh_mul_4, fresh_mul_5=fresh_mul_5,
                    fresh_sin_1=fresh_sin_1, fresh_sin_2=fresh_sin_2, fresh_sin_3=fresh_sin_3, fresh_sin_4=fresh_sin_4, fresh_sin_5=fresh_sin_5, 
                    fro_mul_1=fro_mul_1, fro_mul_2=fro_mul_2, fro_mul_3=fro_mul_3, fro_mul_4=fro_mul_4, fro_mul_5=fro_mul_5,
                    fro_sin_1=fro_sin_1, fro_sin_2=fro_sin_2, fro_sin_3=fro_sin_3, fro_sin_4=fro_sin_4, fro_sin_5=fro_sin_5)

        service = Service(is_sart=is_sart, is_surrogates=is_surrogates, is_single=is_single, is_eggcryo=is_eggcryo,
                        is_embryocryo=is_embryocryo, is_donor_emb=is_donor_emb, is_donor_egg=is_donor_egg)

        
        rate.clinic = clinic

        db.session.add(clinic)

        service.clinic = clinic

        # add to the session or it won't ever be stored
        
        db.session.add(service)



    # Once done, commit
    db.session.commit()
Beispiel #5
0
def load_services():
    """Loads services from services.txt"""

    print "Services"

    #prevents adding duplicate entries when the file is rerun
    Service.query.delete()

    #read file and insert data
    for row in open('seed_data/services.txt'):
        name, yelp_code, picture = row.rstrip().split("|")

        service = Service(name=name, yelp_code=yelp_code, picture=picture)

        db.session.add(service)

    db.session.commit()
def populate_services():
    """Create minimum sample data for the services table."""

    Service.query.delete()

    b = Business.query.all()

    services = [{
        'business_id': b[0].id,
        'description': 'Walk',
        'cost': 30
    }, {
        'business_id': b[0].id,
        'description': 'Board',
        'cost': 40
    }, {
        'business_id': b[0].id,
        'description': 'Daycare',
        'cost': 60
    }, {
        'business_id': b[1].id,
        'description': 'Walk',
        'cost': 25
    }, {
        'business_id': b[1].id,
        'description': 'Board',
        'cost': 35
    }, {
        'business_id': b[1].id,
        'description': 'Daycare',
        'cost': 55
    }]

    for service in services:
        s = Service(business_id=service['business_id'],
                    description=service['description'],
                    cost=service['cost'])

        db.session.add(s)
    db.session.commit()
    return None
Beispiel #7
0
    def create(cls, mechanic_id, truck_id, delivery_prevision_date,
               delivery_prevision_hour, effective_delivered_date,
               effective_delivered_hour, service_description, total_charge,
               payment_type):

        mechanic = MechanicDataHandler.get_by_id(mechanic_id)
        truck = TruckDataHandler.get_by_id(truck_id)

        if not truck:
            IndexUnrelatedToAnyObject

        if not mechanic:
            raise IndexUnrelatedToAnyObject

        if not isinstance(delivery_prevision_date, date) or not isinstance(
                effective_delivered_date, date):
            raise TypeError
        elif not isinstance(delivery_prevision_hour, time) or not isinstance(
                effective_delivered_hour, time):
            raise TypeError
        elif not isinstance(payment_type, PaymentType):
            raise TypeError

        service = Service(mechanic_id=mechanic_id,
                          truck_id=truck_id,
                          entry_date=date.today(),
                          entry_time=datetime.now().time(),
                          delivery_prevision_date=delivery_prevision_date,
                          delivery_prevision_hour=delivery_prevision_hour,
                          effective_delivered_date=effective_delivered_date,
                          effective_delivered_hour=effective_delivered_hour,
                          service_description=service_description,
                          total_charge=total_charge,
                          payment_type=payment_type)

        if cls.exists(service):
            raise UniqueObjectViolated

        cls.__db_session.add(service)
        cls.__db_session.commit()
Beispiel #8
0
def load_services(services_filename):
    """Load services."""

    print("Service")

    for i, row in enumerate(open(services_filename)):
        row = row.rstrip()

        service_name, miles = row.split("|")

        for j in range(1, 11):
            suggested_mileage = j * int(miles)

            for k in range(1, 19):

                new_service = Service(model_id=k,
                                      service_name=service_name,
                                      suggested_mileage=suggested_mileage)
                db.session.add(new_service)

                print(k)

    db.session.commit()
Beispiel #9
0
def services(serz):
    sz = []
    for variety, examples in list(serz.items()):
        for example in examples:
            sz.append(Service(name=example, variety=variety))
    db.put_multi(sz)