def create_users(loop): yield from orm.create_pool(loop=loop, user='******', password='******', db='check_in_system') user_dict = { 'u1': { 'name': 'tonyyeti', 'passwd': 'Tonyalston911', 'admin': True}, 'u2': { 'name': 'feifei', 'passwd': '123456', 'admin': False}, 'u3': { 'name': 'maomao', 'passwd': '123456', 'admin': False} } for user in user_dict.values(): uid = next_id() sha1_passwd = '%s:%s' % (uid, user['passwd']) u = User(id=uid, name=user['name'], passwd=hashlib.sha1(sha1_passwd.encode('utf-8')).hexdigest(), image='about:blank', admin=user['admin']) yield from u.save() print(user['name'] + 'saved.') feifei = yield from User.findAll('name=?', ['feifei']) maomao = yield from User.findAll('name=?', ['maomao']) r1 = Relation(active_user_id=feifei[0].id, active_user_name=feifei[0].name, passive_user_id=maomao[0].id, passive_user_name=maomao[0].name) r2 = Relation(active_user_id=maomao[0].id, active_user_name=maomao[0].name, passive_user_id=feifei[0].id, passive_user_name=feifei[0].name) yield from r1.save() print('r1 saved.') yield from r2.save() print('r2 saved')
def add_following(request): user = request.__user__ add_following = request.POST['add'] new_following = yield from User.findAll('name=?', [add_following]) result = None if len(new_following) == 1: following_user = new_following[0] relations = yield from Relation.findAll('active_user_name=?', [user.name]) if len(relations) >= 1: for relation in relations: if relation.passive_user_name == following_user.name: result = 'already following' if result != 'already following': r1 = Relation(active_user_id=user.id, active_user_name=user.name, passive_user_id=following_user.id, passive_user_name=following_user.name) yield from r1.save() else: r1 = Relation(active_user_id=user.id, active_user_name=user.name, passive_user_id=following_user.id, passive_user_name=following_user.name) yield from r1.save() else: result = 'User Not Found' # 重新载入此页 following = yield from Relation.findAll('active_user_name=?', [user.name]) noFollowing = False if type(following) == type(None): noFollowing = True follower = yield from Relation.findAll('passive_user_name=?', [user.name]) noFollower = False if type(follower) == type(None): noFollower = True return { '__template__': 'group.html', 'username': user.name, 'following': following, 'follower': follower, 'noFollowing': noFollowing, 'noFollower': noFollower, 'result': result }