예제 #1
0
def load_test_data(choice="file", overwrite=True):
    '''
        This will load test data.
    '''

    if overwrite:
        getall = models.storage.all().copy()
        for ele in getall.values():
            models.storage.delete(ele)

    users = [('Alabama', "Allie", "Bama"), ('Arizona', "Arie", "Zona"),
             ('Washington', "Washi", "Tony"), ('Texas', "Tea", "Xena"),
             ('California', "Calie", "Fornia")]

    records = [()]

    if choice == "file":
        fs = models.storage
        for user in users:
            new_user = models.User()
            setattr(new_user, "username", user[0])
            setattr(new_user, "first_name", user[1])
            setattr(new_user, "last_name", user[2])
            fs.new(new_user)
        fs.save()

        stored_users = fs.all("User")
        records = [(3200, 2400, 200), (6400, 4800, 400),
                   (1600, 1200, 100)]  #meters, seconds, calories
        for user in stored_users.values():
            for record in records:
                new_record = models.Record()
                setattr(new_record, "user_id", user.id)
                setattr(new_record, "number", user.record_num)

                setattr(user, "record_num", user.record_num + 1)

                setattr(new_record, "distance", record[0])
                setattr(new_record, "time", record[1])
                setattr(new_record, "calories", record[2])
                fs.new(new_record)
        fs.save()

    else:
        pass
예제 #2
0
def test_Record_can_be_instantiated():
    data = models.Record(
        1,
        "dfname",
        "dlname",
        "daddres",
        "dspecialty",
        "npi",
        "pfname",
        "plname",
        "ssn",
        "icd_code",
        "icd_description",
        "diagnosis",
        "examination_date",
    )

    assert f"{data}" == "pfname plname visited Dr. dfname dlname"
예제 #3
0
    def rec_add(self):
        file_id = long(self.request.get('_PARENT'))

        # 項目仕様収集
        tmp_file = models.File.get_by_id(file_id)
        query = QueryMan.children('Element', 'table_id', tmp_file.table_id)

        # シーケンス補正
        seqs = []
        for it in query.fetch(1000):
            if it.f_type == 23:
                seqs.append(it.key().id_or_name())

        # パラメータ名収集
        args = []
        for it in self.request.arguments():
            if (it[0] == '_'):
                continue
            args.append(it)

        # ディクショナリ化
        values = {}
        for it in args:
            values[it] = self.request.get(it)

        # シーケンス補正
        for it in seqs:
            values['f_%d' % it] = models.Sequence.next_val(file_id, it)

        # レコード生成
        record = models.Record(owner_id=self.user_id,
                               file_id=long(self.request.get("_PARENT")),
                               json=simplejson.dumps(values,
                                                     ensure_ascii=False))
        record.put()

        # 戻り値生成
        ret = {'success': True, '_id': str(record.key().id_or_name())}

        # シーケンス補正
        for it in seqs:
            ret['f_%d' % it] = values['f_%d' % it]

        return ret
예제 #4
0
def update_db(user, d):
    record = models.Record(user_id=user['id'],
                           user_name=user['username'],
                           datetime=datetime.now(),
                           emotions=d.get('emotions', ''),
                           energy=d.get('energy', ''),
                           attention=d.get('attention', ''),
                           conscientiousness=d.get('conscientiousness', ''),
                           planning=d.get('planning', ''),
                           stress=d.get('stress', ''),
                           regime=d.get('regime', ''),
                           body=d.get('body', ''),
                           reading=d.get('reading', ''),
                           day_wish=d.get('day_wish', ''),
                           day_accomplishment=d.get('day_accomplishment', ''),
                           comment=d.get('comment', ''),
                           rating=int(d['rating']))
    db_session.add(record)
    db_session.commit()
예제 #5
0
async def post_form_record(
        form_id: str = Path(..., regex="^[0-9a-fA-F]{32}$"),
        week: int = Path(..., ge=1, le=200),
        boss: int = Path(..., ge=1, le=5),
        record: schemas.PostRecord = ...,
        user_id: int = Depends(oauth.get_current_user_id),
        db: Session = Depends(get_db),
):
    """
    Add or update a record\n
    It will try to update exist record if request include an id.
    """
    formData = db.query(models.Form).filter(models.Form.id == form_id).first()
    if not formData:
        raise HTTPException(404, "Form Not Exist")
    if formData.status != 0:
        raise HTTPException(403, "Form Locked")

    teamJson = jsonable_encoder(record.team) if record.team else null()
    if record.id:
        record_data = (db.query(
            models.Record).filter(models.Record.form_id == form_id).filter(
                models.Record.user_id == user_id).filter(
                    models.Record.id == record.id).filter(
                        models.Record.status != 99).first())
        if not record_data:
            raise HTTPException(404, "Record Not Exist")

        record_data.status = record.status.value
        record_data.damage = record.damage
        record_data.comment = record.comment
        record_data.team = teamJson
        record_data.last_modified = datetime.utcnow()
        db.commit()
        data = jsonable_encoder(schemas.AllRecord(**record_data.as_dict()))
        await sio.emit("FormTracker", {
            "type": "RecUP",
            "data": data
        },
                       room=form_id)
        return data
    else:
        record_data = models.Record(
            form_id=form_id,
            month=record.month if record.month else formData.month,
            week=week,
            boss=boss,
            status=record.status.value,
            damage=record.damage,
            comment=record.comment,
            user_id=user_id,
            team=teamJson,
        )
        db.add(record_data)
        db.commit()
    data = jsonable_encoder(schemas.AllRecord(**record_data.as_dict()))
    await sio.emit("FormTracker", {
        "type": "RecNEW",
        "data": data
    },
                   room=form_id)
    return data
예제 #6
0
def addRecord():
    Record = models.Record()
    tokenid = request.form['tokenid']
    recordLog = request.form['record']
    return Record.addRecord(tokenid, recordLog)
예제 #7
0
def db_start():
    create_engine('sqlite:///tmp/test.db', convert_unicode=True)
    db.create_all()
    db.session.commit()

    user_1 = models.User()
    user_1.username = "******"
    user_1.password = bcrypt.generate_password_hash('pppp1234')
    user_1.email = '*****@*****.**'
    user_1.admin = True
    user_1.poweruser = True

    db.session.add(user_1)
    db.session.commit()

    user_2 = models.User()
    user_2.username = "******"
    user_2.password = bcrypt.generate_password_hash('ewelina1')
    user_2.email = '*****@*****.**'
    user_2.admin = False
    user_2.poweruser = False

    db.session.add(user_2)
    db.session.commit()

    user_3 = models.User()
    user_3.username = "******"
    user_3.password = bcrypt.generate_password_hash('qwertyuiop')
    user_3.email = '*****@*****.**'
    user_3.admin = True
    user_3.poweruser = True

    db.session.add(user_3)
    db.session.commit()

    user_4 = models.User()
    user_4.username = "******"
    user_4.password = bcrypt.generate_password_hash('admin')
    user_4.email = '*****@*****.**'
    user_4.admin = True
    user_4.poweruser = True

    db.session.add(user_4)
    db.session.commit()

    record_1 = models.Record(title='Black Sabbath', artist='Black Sabbath')
    record_2 = models.Record(title='The Doors', artist='The Doors')
    record_3 = models.Record(title='Led Zeppelin', artist='Led Zeppelin')
    record_4 = models.Record(title='Ramones', artist='Ramones')
    record_5 = models.Record(title='American Idiot', artist='Green Day')
    record_6 = models.Record(title='Noc', artist='Budka Suflera')
    record_7 = models.Record(title='Bad', artist='Michael Jackson')
    record_8 = models.Record(title='Thriller', artist='Michael Jackson')
    db.session.add(record_1)
    db.session.add(record_2)
    db.session.add(record_3)
    db.session.add(record_4)
    db.session.add(record_5)
    db.session.add(record_6)
    db.session.add(record_7)
    db.session.add(record_8)
    db.session.commit()