示例#1
0
def list_photos(args):
    tmpl1 = '{id:<3}  {chksum:<32}  {date}'
    tmpl2 = '         {comment:<30}  {added}'

    desc = dict(id='Id', chksum='Checksum', date='Date', comment='Comment', added='Added')

    head1 = tmpl1.format(**desc)
    head2 = tmpl2.format(**desc)
    print(head1)
    print(head2)
    print('-' * (max(len(head1), len(head2))  + 12))


    for p in Photo.select().dicts():
        print(tmpl1.format(**p))
        print(tmpl2.format(**p))
示例#2
0
def test_init(args):
    users = [('viewer 1', '*****@*****.**', 'pass1', False),
             ('viewer 2', '*****@*****.**', 'pass2', False),
             ('uploader 1', '*****@*****.**', 'uppass1', True),
             ('uploader 2', '*****@*****.**', 'uppass2', True)]

    photos = [('111', '2014-06-07T20:21:19', 'photo 111'),
              ('12345', '2014-06-05T20:21:19', 'photo 12345'),
              ('222', '2014-06-04T20:21:19', 'photo 222'),
              ('333', '2014-06-07T22:21:19', 'photo 333'),
              ('444', '2014-06-05T20:21:19', '444'),
              ('555', '2014-06-01T20:21:19', 'photo 555'),
              ('666', '2014-06-05T14:21:19', 'photo 666'),
              ('abcde', '2014-05-02T20:21:19', 'photo abcde'),
              ('uvw', '2014-03-02T20:21:19', 'photo uvw'),
              ('xyz', '2014-07-02T20:21:19', 'photo xyz'),
              ]


    if User.select().count() == 0:
        for n, e, p, u in users:
            User.create(name=n, email=e, password=generate_password_hash(p), uploader=u)
    else:
        print('User table already contains data')

    str2datetime = lambda s: arrow.get(s).datetime.replace(tzinfo=None)

    if Photo.select().count() == 0:
        for s, d, c in photos:
            kw = dict(chksum=s, date=str2datetime(d), comment=c,
                    added=datetime.utcnow(),
                    mimetype='image/jpeg')
            print(kw)
            Photo.create(**kw)
    else:
        print('Photo table already contains data')