示例#1
0
文件: manage.py 项目: fallaha/quiza
def add_participant(uuid,
                    participants: AddParticipantsRequest,
                    current_user: User = Depends(get_current_user)):
    added_user = []
    try:
        quiz = current_user.created_quizzes.where(Quiz.uuid == uuid).get()
    except (peewee.DoesNotExist, peewee.DataError):
        return {'code': -2, 'msg': 'invalid quiz'}

    if quiz.public:
        return {'code': -12, 'msg': 'you cant add person to private quiz'}

    for email in participants.participants:
        try:
            user = User.select().where(User.email == email).get()
        except peewee.DoesNotExist:
            pass
        else:
            try:
                with database.atomic():
                    QuizUsers.create(quiz=quiz, user=user)
            except peewee.IntegrityError:
                pass
            else:
                added_user.append(user.email)
    return {'data': added_user}
示例#2
0
def override_get_current_user():
    return User.select().where(User.email == '*****@*****.**')
示例#3
0
文件: manage.py 项目: fallaha/quiza
def users():
    u = User.select().dicts()
    return {'row': list(u)}
示例#4
0
def get_user_by_email(email):
    try:
        return User.select().where(User.email == email).get()
    except peewee.DoesNotExist:
        raise HTTPException(status_code=401, detail="Incorrect username")