Exemple #1
0
def index(page):
    if current_user.is_authenticated:
        activate = list(range(10))
        activate[1] = "active"
        page = int(page)
        role = Role.objects(name='student').first()
        if page is None or page == 1:
            page = request.args.get('page', 1, type=int)
            students = User.objects(role=role, is_activate=True).limit(10)
        elif page <= -1:
            page = int(
                (User.objects(role=role, is_activate=True).count() - 10) /
                10) + 2
            num_skip = User.objects(role=role).count() - 10
            if num_skip < 0: num_skip = 0
            students = User.objects(role=role, is_activate=True).skip(num_skip)
        else:
            students = User.objects(
                role=role, is_activate=True).skip(page * 10 - 10).limit(10)
        return render_template('student.html',
                               title='Student',
                               activate=activate,
                               students=students,
                               page_num=page)
    return redirect(url_for('users.login'))
def create_data_course():
    role_teacher = Role.objects(name='teacher').first()
    list_teacher = User.objects(role=role_teacher)
    role_student = Role.objects(name='student').first()
    list_student = User.objects(role=role_student)
    list_shift = Shift.objects.all()
    Course(id_course="SD-001",
           name="Word - Excel - Power Point",
           tuition=120,
           teacher=list_teacher[0],
           shift=list_shift[0]).save()
    Course(id_course="DB-001",
           name="DataBase System",
           tuition=199,
           teacher=list_teacher[1],
           shift=list_shift[1]).save()
    Course(id_course="WEB-001",
           name="Web Interface",
           tuition=149,
           teacher=list_teacher[2],
           shift=list_shift[2]).save()
    Course(id_course="JAVA-001",
           name="Java Application",
           tuition=299,
           teacher=list_teacher[3],
           shift=list_shift[0]).save()
    Course(id_course="RJ-001",
           name="React - Redux JavaScript",
           tuition=289,
           teacher=list_teacher[4],
           shift=list_shift[2]).save()
def create_data_account():
    role_admin = Role.objects(name="admin").first()
    role_academic = Role.objects(name="academic").first()
    role_cashier = Role.objects(name="cashier").first()

    list_admin = User.objects(role=role_admin)
    list_academic = User.objects(role=role_academic)
    list_cashier = User.objects(role=role_cashier)

    hashed_password = bcrypt.generate_password_hash("1").decode('utf-8')

    num = 1
    for item in list_admin:
        Account(username="******" + str(num),
                password=hashed_password,
                user=item).save()
        num += 1

    num = 1
    for item in list_academic:
        Account(username="******" + str(num),
                password=hashed_password,
                user=item).save()
        num += 1

    num = 1
    for item in list_cashier:
        Account(username="******" + str(num),
                password=hashed_password,
                user=item).save()
        num += 1
Exemple #4
0
def staff_removed(page):    
    if current_user.user.role.name != 'admin': 
        flash('You\'re not admin. You can not access this page')
        return redirect(url_for('main.index'))
    activate = list(range(10))
    activate[4] = "active"  
    page = int(page) 
    role_academic = Role.objects(name='academic').first()
    role_cashier = Role.objects(name='cashier').first() 
    if page is None or page == 1:
        page = request.args.get('page', 1, type=int) 
        users_1 = User.objects(role=role_academic,is_activate=False).limit(5) 
        users_2 = User.objects(role=role_cashier,is_activate=False).limit(5) 
        print(users_2)
    elif page <=-1:
        page = int((User.objects(role=role,is_activate=False).count()-10) /10) + 2  
        num_skip= User.objects(role=role).count()-5
        if num_skip < 0: num_skip = 0
        users_1 = User.objects(role=role_academic,is_activate=False).skip(num_skip)
        users_2 = User.objects(role=role_cashier,is_activate=False).skip(num_skip)
    else:
        users_1 = User.objects(role=role_academic,is_activate=False).skip(page*5-5).limit(5)
        users_2 = User.objects(role=role_cashier,is_activate=False).skip(page*5-5).limit(5)  
     
    users = list()
    for item in users_1:
        users.append(item)

    for item in users_2:
        users.append(item)  
    return render_template('staff_removed.html', title='Staff',activate=activate,staffs=users,page_num=page)  
Exemple #5
0
def create_receipt(id): 
    activate = list(range(10))
    activate[1] = "active"     
    user = User.objects(id=id,is_activate=True).first()  
    form = PaymentReceiptForm()  
    if id is None or user is None:
        return redirect(url_for('staff.index'))  
      
    if form.validate_on_submit():
        staff = user
        money = float(form.payment.data)
        basic_salary = user.salary
        from_date = form.from_date.data
        to_date = form.to_date.data
        created_user = current_user.user 
        receipt = PaymentReceipt(staff=staff,money=money,basic_salary=basic_salary,from_date=from_date,to_date=to_date,created_user=created_user)
        receipt.save()
        flash('Receipt has been created!', 'success')
        return redirect(url_for('staff.staff_info',id=id))
    
    form.first_name.data = user.first_name
    form.last_name.data = user.last_name
    form.phone.data = user.phone
    form.email.data = user.email
    form.address.data = user.address
    form.birth.data = user.birth  
    form.address.data = user.address
    form.birth.data = user.birth    
    form.salary.data = user.salary 
    form.payment.data = 0
    
    return render_template('staff_create_receipt.html', title='Create Payment Staff',activate=activate,staff=user,form=form)
Exemple #6
0
def staff_info(id):  
    if current_user.user.role.name == 'admin' or current_user.user.role.name == 'cashier': 
        activate = list(range(10))
        activate[4] = "active"
        is_activate = True
        if current_user.is_authenticated:
            user = User.objects(id=id,is_activate=True).first()  
            form = UpdateStaffForm()  
            if id is None or user is None:
                return redirect(url_for('staff.index',page=1))  
            if form.validate_on_submit():
                if form.picture.data:
                    picture_file = save_picture(form.picture.data)
                    user.image_file = picture_file
                user.first_name=form.first_name.data 
                user.last_name=form.last_name.data 
                user.phone =form.phone.data 
                user.email =form.email.data
                user.salary =form.salary.data
                user.address =form.address.data
                user.birth =form.birth.data 
                user.gender = form.gender.data  
                role = form.role.data
                if role == 'cashier' or role == 'academic':
                    role = Role.objects(name=role).first()
                    # print(role.name)  
                    user.role = role
                    # print(user.role.id,role.id)
                else:  
                    flash('Can\'t find role, please reload page', 'danger')
                    return redirect(url_for('staff.staff_info',id=id))
                    
                user.save()
                flash('Staff has been updated!', 'success')
                return redirect(url_for('staff.staff_info',id=id))
            elif request.method == 'GET':
                form.first_name.data = user.first_name
                form.last_name.data = user.last_name
                form.phone.data = user.phone
                form.email.data = user.email
                form.salary.data = user.salary
                form.address.data = user.address 
                form.gender.data = user.gender 
                form.birth.data = user.birth
                form.role.data = user.role 
            receipts = PaymentReceipt.objects(staff=user)
            account = Account.objects(user=user).first()
            if account and account.is_activate == False:
                flash('Account of staff hasn\'t been acitved yet !!', 'info')  
                is_activate = False
            return render_template('staff_info.html', title='Staff Info',activate=activate,staff=user,form=form,receipts=receipts,is_activate = is_activate)
        return redirect(url_for('staff.index',page=1))
    else:
        flash('You\'re not admin. You can not access this page')
        return redirect(url_for('main.index'))
Exemple #7
0
def send_active_again(id): 
    if current_user.user.role.name != 'admin': 
        flash('You\'re not admin. You can not access this page')
        return redirect(url_for('main.index'))
    activate = list(range(10))
    activate[4] = "active"  
    user = User.objects(id=id).first()  
    if id is None or user is None:
        flash("Can't find this id !!!","info")
        return redirect(url_for('staff.index',page=1))
    send_reset_email(user)  
    flash('Activate is sent, this command is effectived within 30 minutes please active now', 'success')
    return redirect(url_for('staff.staff_info',id=user.id)) 
Exemple #8
0
def student_removed(page):
    activate = list(range(10))
    activate[1] = "active"
    page = int(page)
    role = Role.objects(name='student').first()
    if page is None or page == 1:
        page = request.args.get('page', 1, type=int)
        students = User.objects(role=role, is_activate=False).limit(10)
    elif page <= -1:
        page = int(
            (User.objects(role=role, is_activate=False).count() - 10) / 10) + 2
        num_skip = User.objects(role=role).count() - 10
        if num_skip < 0: num_skip = 0
        students = User.objects(role=role, is_activate=False).skip(num_skip)
    else:
        students = User.objects(
            role=role, is_activate=False).skip(page * 10 - 10).limit(10)
    return render_template('student_removed.html',
                           title='Removed Student',
                           activate=activate,
                           students=students,
                           page_num=page)
Exemple #9
0
def restore(id):
    activate = list(range(10))
    activate[2] = "active"
    role = Role.objects(name="teacher").first()
    teacher = User.objects(role=role, id=id, is_activate=False).first()
    if teacher:
        teacher.is_activate = True
        teacher.save()
        flash('Teacher restore success !!', 'success')
        return redirect(url_for('teacher.teacher_removed', page=1))
    else:
        flash('Teacher with id ' + id + ' can\'t find  !!', 'danger')
    return redirect(url_for('teacher.teacher_removed', page=1))
Exemple #10
0
def index(page):
    activate = list(range(10))
    activate[2] = "active"
    page = int(page)
    role = Role.objects(name='teacher').first()
    if page is None or page == 1:
        page = request.args.get('page', 1, type=int)
        teachers = User.objects(role=role, is_activate=True).limit(10)
    elif page <= -1:
        page = int(
            (User.objects(role=role, is_activate=True).count() - 10) / 10) + 2
        num_skip = User.objects(role=role).count() - 10
        if num_skip < 0: num_skip = 0
        teachers = User.objects(role=role, is_activate=True).skip(num_skip)
    else:
        teachers = User.objects(role=role, is_activate=True).skip(page * 10 -
                                                                  10).limit(10)
    return render_template('teacher.html',
                           title='Teacher',
                           activate=activate,
                           teachers=teachers,
                           page_num=page)
Exemple #11
0
def restore(id):
    activate = list(range(10))
    activate[1] = "active"
    role = Role.objects(name="student").first()
    student = User.objects(role=role, id=id, is_activate=False).first()
    if student:
        student.is_activate = True
        student.save()
        flash('Student restore success !!', 'success')
        return redirect(url_for('student.student_removed', page=1))
    else:
        flash('Student with id ' + id + ' can\'t find  !!', 'danger')
    return redirect(url_for('student.student_removed', page=1))
Exemple #12
0
def teacher_info(id):
    if current_user.user.role.name != 'admin' and current_user.user.role.name != 'academic':
        flash('You\'re not authorization.')
        return redirect(url_for('main.index'))
    activate = list(range(10))
    activate[2] = "active"
    is_activate = True
    if current_user.is_authenticated:
        user = User.objects(id=id, is_activate=True).first()
        form = UpdateTeacherForm()
        if id is None or user is None:
            return redirect(url_for('teacher.index', page=1))
        print(form.validate_on_submit())
        if form.validate_on_submit():
            print(123)
            if form.picture.data:
                picture_file = save_picture(form.picture.data)
                user.image_file = picture_file
            print(123)
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            user.phone = form.phone.data
            user.email = form.email.data
            user.salary = form.salary.data
            user.address = form.address.data
            user.birth = form.birth.data
            user.gender = form.gender.data
            if user.role.name != 'teacher':
                flash('Can\'t find role, please reload page', 'danger')
                return redirect(url_for('teacher.teacher_info', id=id))

            user.save()
            flash('Teacher has been updated!', 'success')
            return redirect(url_for('teacher.teacher_info', id=id))
        else:
            form.first_name.data = user.first_name
            form.last_name.data = user.last_name
            form.phone.data = user.phone
            form.email.data = user.email
            form.salary.data = user.salary
            form.address.data = user.address
            form.gender.data = user.gender
            form.birth.data = user.birth
        receipts = PaymentReceipt.objects(staff=user)
        return render_template('teacher_info.html',
                               title='Teacher Info',
                               activate=activate,
                               teacher=user,
                               form=form,
                               receipts=receipts)
    return redirect(url_for('teacher.index', page=1))
Exemple #13
0
def remove(id):
    activate = list(range(10))
    activate[1] = "active"
    role = Role.objects(name="student").first()
    student = User.objects(role=role, id=id, is_activate=True).first()
    if student:
        receipts = TuitionReceipt.objects(student=student)
        if len(receipts) > 0:
            flash('Student can\'t remove !!', 'danger')
            return redirect(url_for('student.student_info', id=student.id))
        student.is_activate = False
        student.save()
        flash('Student delete success !!', 'success')
    return redirect(url_for('student.index', page=1))
Exemple #14
0
def remove(id):
    activate = list(range(10))
    activate[2] = "active"
    role = Role.objects(name="teacher").first()
    teacher = User.objects(role=role, id=id, is_activate=True).first()
    if teacher:
        receipts = PaymentReceipt.objects(staff=teacher)
        if len(receipts) > 0:
            flash('Teacher can\'t remove !!', 'danger')
            return redirect(url_for('teacher.teacher_info', id=teacher.id))
        teacher.is_activate = False
        teacher.save()
        flash('Teacher delete success !!', 'success')
    return redirect(url_for('teacher.index', page=1))
Exemple #15
0
def educate_info(id):
    if current_user.is_authenticated:
        activate = list(range(10))
        activate[3] = "active"
        form = UpdateCourseForm()
        if id is None:
            return redirect(url_for('educate.index'))
        course = Course.objects(id=id).first_or_404()
        if form.validate_on_submit():
            role_teacher = Role.objects(name='teacher').first()
            list_teacher = User.objects(role=role_teacher, is_activate=True)
            course.name = form.name.data
            course.start_date = form.start_date.data
            course.finish_date = form.finish_date.data
            course.tuition = float(form.tuition.data)
            shift = Shift.objects(name=form.shift.data).first()
            course.shift = shift
            for item in list_teacher:
                if item.first_name + ' ' + item.last_name == form.teacher.data:
                    course.teacher = item
                    break

            if form.status.data == 'True':
                course.status = True
            else:
                course.status = False
            course.save()
            flash('Course has been updated!', 'success')
            return redirect(url_for('educate.educate_info', id=id))
        elif request.method == 'GET':
            form.id_course.data = course.id_course
            form.name.data = course.name
            form.start_date.data = course.start_date
            form.finish_date.data = course.finish_date
            form.tuition.data = course.tuition

            form.shift.data = course.shift.name
            form.teacher.data = course.teacher.first_name + ' ' + course.teacher.last_name

            form.status.data = course.status
            TuitionReceipts = TuitionReceipt.objects(course=course)
        return render_template('educate_info.html',
                               title='Educate Info',
                               activate=activate,
                               form=form,
                               students=course.list_student,
                               id_course=id,
                               TuitionReceipts=TuitionReceipts)
    return redirect(url_for('users.login'))
Exemple #16
0
def restore(id): 
    activate = list(range(10))
    activate[4] = "active"     
    staff = User.objects(id=id,is_activate=False).first() 
    account = Account.objects(user=staff).first()
    if staff: 
        staff.is_activate = True
        account.is_activate = True
        staff.save()
        account.save()
        flash('Staff restore success !!', 'success')  
        return redirect(url_for('staff.staff_removed',page=1))
    else:
        flash('Student with id ' + id+ ' can\'t find  !!', 'danger')
    return redirect(url_for('staff.staff_removed',page=1))
Exemple #17
0
 def validate_teacher(self, teacher):
     if current_user.user.role.name == 'admin' or current_user.user.role.name == 'academic':
         flag = False
         role_teacher = Role.objects(name='teacher').first()
         list_teacher = User.objects(role=role_teacher, is_activate=True)
         for item in list_teacher:
             if item.first_name + ' ' + item.last_name == teacher.data:
                 flag = True
                 break
         if flag == False:
             raise ValidationError(
                 'Name teacher isn\'t exist. Please reload page and input again'
             )
     else:
         raise ValidationError(
             'You\'re not a member of system. Please contact to manager.')
Exemple #18
0
def reset_request():
    form = RequestResetForm()
    if form.validate_on_submit():
        user = User.objects(email=form.email.data).first()
        account = Account.objects(user=user).first()
        if user and account and account.is_activate:
            send_reset_email(user)
            flash(
                'An email has been sent with instructions to reset your password.',
                'info')
            return redirect(url_for('users.login'))
        elif user and account and account.is_activate == False:
            flash(
                'You haven\'t login yet. Please contact admin to get more info.',
                'info')
    return render_template('reset_request.html',
                           title='Reset Password',
                           form=form)
Exemple #19
0
def student_info(id):
    activate = list(range(10))
    activate[1] = "active"
    if current_user.is_authenticated:

        user = User.objects(id=id, is_activate=True).first()
        form = UpdateUserForm()
        if id is None or user is None:
            return redirect(url_for('student.index', page=1))

        if form.validate_on_submit():
            if form.picture.data:
                picture_file = save_picture(form.picture.data)
                user.image_file = picture_file
            user.first_name = form.first_name.data
            user.last_name = form.last_name.data
            user.phone = form.phone.data
            user.email = form.email.data
            user.address = form.address.data
            user.birth = form.birth.data
            user.gender = form.gender.data

            user.save()
            flash('Student has been updated!', 'success')
            return redirect(url_for('student.student_info', id=id))
        elif request.method == 'GET':
            form.first_name.data = user.first_name
            form.last_name.data = user.last_name
            form.phone.data = user.phone
            form.email.data = user.email
            form.address.data = user.address
            form.gender.data = user.gender
            form.birth.data = user.birth

        receipts = TuitionReceipt.objects(student=user)
        return render_template('student_info.html',
                               title='Student Info',
                               activate=activate,
                               student=user,
                               form=form,
                               receipts=receipts)
    return redirect(url_for('users.login'))
Exemple #20
0
def remove(id): 
    activate = list(range(10))
    activate[4] = "active"  
    role = Role.objects(name="staff").first()
    staff = User.objects(id=id,is_activate=True).first()
    account = Account.objects(user=staff).first()
    
    if staff and account:
        TuitionReceipts = TuitionReceipt.objects(student=staff)
        if len(TuitionReceipts) > 0:
            flash('Staff can\'t remove !!', 'danger')
            return redirect(url_for('staff.staff_info',id=staff.id)) 
        staff.is_activate = False 
        account.is_activate = False
        staff.save()  
        account.save()
        flash('Staff delete success !!', 'success') 
        return redirect(url_for('staff.index',page=1))
    flash('Can\'t find staff !!', 'danger')
    return redirect(url_for('staff.index',page=1))
Exemple #21
0
def create():
    activate = list(range(10))
    activate[3] = "active"
    if current_user.is_authenticated:
        form = CreateCourseForm()
        if form.validate_on_submit():
            id_course = form.id_course.data
            course = Course.objects(id_course=id_course).first()
            if course is None:

                name = form.name.data

                start_date = form.start_date.data
                finish_date = form.finish_date.data
                tuition = float(form.tuition.data)
                shift = Shift.objects(name=form.shift.data).first()
                role_teacher = Role.objects(name='teacher').first()
                list_teacher = User.objects(role=role_teacher,
                                            is_activate=True)
                for item in list_teacher:
                    if item.first_name + ' ' + item.last_name == form.teacher.data:
                        teacher = item
                        break
                course = Course(id_course=id_course,
                                name=name,
                                start_date=start_date,
                                finish_date=finish_date,
                                tuition=tuition,
                                shift=shift,
                                teacher=teacher)
                course.save()
                flash('Course has been created!', 'success')
                return redirect(url_for('educate.educate_info', id=course.id))
            flash('Course is exist!, please check again', 'danger')
            return redirect(url_for('educate.create'))

        return render_template('educate_create.html',
                               title='Educate Create Course',
                               activate=activate,
                               form=form)
    return redirect(url_for('users.login'))
Exemple #22
0
def profile():
    activate = list(range(10))
    activate[7] = "active"
    form = UpdateUserForm()
    if form.validate_on_submit():
        user = User.objects(id=current_user.user.id, is_activate=True).first()
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            current_user.user.image_file = picture_file
        current_user.user.first_name = form.first_name.data
        current_user.user.last_name = form.last_name.data
        current_user.user.phone = form.phone.data
        current_user.user.email = form.email.data
        current_user.user.address = form.address.data
        current_user.user.birth = form.birth.data
        current_user.user.gender = form.gender.data
        current_user.user.save()
        flash('Your account has been updated!', 'success')
        return redirect(url_for('users.profile'))
    elif request.method == 'GET':
        form.first_name.data = current_user.user.first_name
        form.last_name.data = current_user.user.last_name
        form.phone.data = current_user.user.phone
        form.email.data = current_user.user.email
        form.address.data = current_user.user.address
        form.birth.data = current_user.user.birth
        form.gender.data = current_user.user.gender
    image_file = current_user.user.image_file
    error = False
    if form.first_name.errors or form.last_name.errors or form.phone.errors or form.email.errors or form.address.errors or form.birth.errors or form.gender.errors:
        error = True
    receipts = ""
    if current_user.user.role.name != 'admin' and current_user.user.role.name != 'student' and current_user.user.role.name != 'teacher':
        receipts = PaymentReceipt.objects(staff=current_user.user)
    return render_template('profile.html',
                           title='Profile',
                           image_file=image_file,
                           form=form,
                           activate=activate,
                           error=error,
                           receipts=receipts)
Exemple #23
0
def create_receipt(id):
    activate = list(range(10))
    activate[1] = "active"
    if current_user.is_authenticated:
        user = User.objects(id=id, is_activate=True).first()
        form = AddStudentToClass()
        if id is None or user is None:
            return redirect(url_for('student.index'))

        if form.validate_on_submit():
            id_course = form.course.data
            course = Course.objects(id=id_course).first()
            reservate_tuition = float(form.reservate_tuition.data)
            tuition_left = course.tuition - reservate_tuition
            money_return = 0
            status = False
            if tuition_left <= 0:
                status = True
                money_return = -1 * tuition_left
                tuition_left = 0
            if course is None:
                flash('Can\'t find class, please inform to admin!', 'danger')
                return redirect(url_for('student.create_receipt', id=id))
            list_detail_tuition = list()
            course.list_student.append(user)
            if len(course.list_student) > 5:
                course.status = True
            course.save()
            detail_receipt = DetailTuitionReceipt(
                tuition=reservate_tuition,
                money_return=money_return,
                created_user=current_user.user).save()
            list_detail_tuition.append(detail_receipt)
            receipt = TuitionReceipt(student=user,
                                     course=course,
                                     reservate_tuition=reservate_tuition,
                                     tuition_left=tuition_left,
                                     list_detail=list_detail_tuition,
                                     status=status).save()
            flash('Receipt has been created!', 'success')
            return redirect(url_for('student.student_info', id=id))

        # list_course = Course.objects.all()
        # form.course_choices = [(str(c['id']), c['id_course']) for c in list_course if c.finish_date >= datetime.utcnow()]

        # list_shift = Shift.objects.all()
        # form.shift_choices = [(str(c['id']), c['name']) for c in list_shift]

        form.first_name.data = user.first_name
        form.last_name.data = user.last_name
        form.phone.data = user.phone
        form.email.data = user.email
        form.address.data = user.address
        form.birth.data = user.birth
        form.gender.data = user.gender
        form.reservate_tuition.data = 0
        form.money_return.data = 0
        return render_template('student_create_receipt.html',
                               title='Student Info',
                               activate=activate,
                               student=user,
                               form=form)
    return redirect(url_for('users.login'))
Exemple #24
0
 def validate_email(self, email):
     user = User.objects(email=email.data).first()
     if user is None:
         raise ValidationError('That username isn\'t exist.')
Exemple #25
0
def get_removed_student(key_word):
    if current_user.is_authenticated:
        data = list()
        role = Role.objects(name='student').first()
        if key_word == 'all':
            students = User.objects(role=role, is_activate=False).limit(10)
            if students:
                for item in students:
                    ele = {
                        "id": str(item.id),
                        "address": item.address,
                        "birth": item.birth.strftime("%m-%d-%Y"),
                        "email": item.email,
                        "first_name": item.first_name,
                        "gender": item.gender,
                        "image_file": item.image_file,
                        "last_name": item.last_name,
                        "phone": item.phone,
                        "is_activate": item.is_activate
                    }
                    data.append(ele)
                response = {
                    'status': True,
                    'message': 'Get Students Success',
                    'data': data
                }
        else:
            students = User.objects(role=role,
                                    is_activate=False,
                                    first_name__istartswith=key_word).limit(5)
            if students:
                for item in students:
                    ele = {
                        "id": str(item.id),
                        "address": item.address,
                        "birth": item.birth.strftime("%m-%d-%Y"),
                        "email": item.email,
                        "first_name": item.first_name,
                        "gender": item.gender,
                        "image_file": item.image_file,
                        "last_name": item.last_name,
                        "phone": item.phone,
                        "is_activate": item.is_activate
                    }
                    data.append(ele)

            students = User.objects(role=role,
                                    is_activate=False,
                                    last_name__istartswith=key_word).limit(5)
            if students:
                for item in students:
                    flag = False
                    for ele in data:
                        if ele['id'] == item.id:
                            flag = True
                            break
                    if flag == False:
                        ele = {
                            "id": str(item.id),
                            "address": item.address,
                            "birth": item.birth.strftime("%m-%d-%Y"),
                            "email": item.email,
                            "first_name": item.first_name,
                            "gender": item.gender,
                            "image_file": item.image_file,
                            "last_name": item.last_name,
                            "phone": item.phone,
                            "is_activate": item.is_activate
                        }
                        data.append(ele)
            students = User.objects(role=role,
                                    is_activate=False,
                                    phone__istartswith=key_word).limit(5)
            if students:
                for item in students:
                    flag = False
                    for ele in data:
                        if ele['id'] == item.id:
                            flag = True
                            break
                    if flag == False:
                        ele = {
                            "id": str(item.id),
                            "address": item.address,
                            "birth": item.birth.strftime("%m-%d-%Y"),
                            "email": item.email,
                            "first_name": item.first_name,
                            "gender": item.gender,
                            "image_file": item.image_file,
                            "last_name": item.last_name,
                            "phone": item.phone,
                            "is_activate": item.is_activate
                        }
                        data.append(ele)
            students = User.objects(role=role,
                                    is_activate=False,
                                    email__istartswith=key_word).limit(5)
            if students:
                for item in students:
                    flag = False
                    for ele in data:
                        if ele['id'] == item.id:
                            flag = True
                            break
                    if flag == False:
                        ele = {
                            "id": str(item.id),
                            "address": item.address,
                            "birth": item.birth.strftime("%m-%d-%Y"),
                            "email": item.email,
                            "first_name": item.first_name,
                            "gender": item.gender,
                            "image_file": item.image_file,
                            "last_name": item.last_name,
                            "phone": item.phone,
                            "is_activate": item.is_activate
                        }
                        data.append(ele)
            response = {
                'status': True,
                'message': 'Get Students Success',
                'data': data
            }
    else:
        response = {
            'status': False,
            'message': 'Get Students Failed',
            'data': None
        }
    return response
Exemple #26
0
 def validate_phone(self, phone):
     user = User.objects(phone=phone.data).first()
     if user is None:
         raise ValidationError('That username isn\'t exist.')
Exemple #27
0
 def validate_username(self, username):
     user = User.objects(username=username.data).first()
     if user:
         raise ValidationError(
             'That username is taken. Please choose a different one.')
Exemple #28
0
 def validate_phone(self, phone):
     user = User.objects(phone=phone.data).first()
     if user:
         raise ValidationError(
             'That phone is taken. Please choose a different one.')
         return
Exemple #29
0
 def validate_email(self, email):
     user = User.objects(email=email.data).first()
     if user is None:
         raise ValidationError(
             'There is no account with that email. You must contact to admin to register first.'
         )
Exemple #30
0
from flask_wtf import FlaskForm
from flask_wtf.file import FileField, FileAllowed
from wtforms import StringField, PasswordField, SubmitField, BooleanField, SelectField, widgets, FieldList, FormField
from wtforms.validators import DataRequired, Email, Length, EqualTo, ValidationError
from flask_login import current_user
from it_center.models import Course, User, Shift, Role
from wtforms.fields.html5 import DateField

list_shift = Shift.objects.all()
shift_choices = [(str(c['name']), c['name']) for c in list_shift]

role_teacher = Role.objects(name='teacher').first()
list_teacher = User.objects(role=role_teacher, is_activate=True)
teacher_choices = [(c['first_name'] + ' ' + c['last_name'],
                    c['first_name'] + ' ' + c['last_name'])
                   for c in list_teacher]


class UpdateCourseForm(FlaskForm):
    id_course = StringField('Code',
                            validators=[DataRequired(),
                                        Length(min=2, max=30)])
    name = StringField('Course Name',
                       validators=[DataRequired(),
                                   Length(min=2, max=50)])
    start_date = DateField('Start Date', validators=[DataRequired()])
    finish_date = DateField('Finish Date', validators=[DataRequired()])
    tuition = StringField('Tuition', validators=[DataRequired()])
    shift = SelectField('Shift',
                        choices=shift_choices,
                        validators=[DataRequired()])