コード例 #1
0
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()
コード例 #2
0
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
コード例 #3
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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'))
コード例 #4
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
def create():
    activate = list(range(10))
    activate[1] = "active"
    form = UpdateUserForm()
    if form.validate_on_submit():
        if form.picture.data:
            picture_file = save_picture(form.picture.data)
            image_file = picture_file
        first_name = form.first_name.data
        last_name = form.last_name.data
        phone = form.phone.data
        email = form.email.data
        address = form.address.data
        birth = form.birth.data
        gender = form.gender.data
        role = Role.objects(name='student').first()
        user = User(first_name=first_name,
                    last_name=last_name,
                    phone=phone,
                    email=email,
                    address=address,
                    birth=birth,
                    gender=gender,
                    role=role)
        user.save()
        flash('Student has been created!', 'success')
        return redirect(url_for('student.student_info', id=user.id))
    return render_template('student_create.html',
                           title='Create Student\'s Info',
                           activate=activate,
                           form=form)
コード例 #5
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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)  
コード例 #6
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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)
コード例 #7
0
def send_reset_email(user):
    token = User.get_reset_token(user=user)
    msg = Message('Password Reset Request',
                  sender='*****@*****.**',
                  recipients=[user.email])
    msg.body = f'''To reset your password, visit following link: 
              {url_for('users.reset_token', token= token, _external= True)}
                If you did not make request then simply ignore this email and no changes will be made.
                '''
    mail.send(msg)
コード例 #8
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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'))
コード例 #9
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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))
コード例 #10
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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))
コード例 #11
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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)
コード例 #12
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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)
コード例 #13
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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)) 
コード例 #14
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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))
コード例 #15
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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))
コード例 #16
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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))
コード例 #17
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
def create():  
    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"  
    form = CreateStaffForm()  
    image_file = ""
    if id 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)
            image_file = picture_file
        first_name=form.first_name.data 
        last_name=form.last_name.data 
        phone =form.phone.data
        salary = form.salary.data 
        email =form.email.data
        address =form.address.data
        birth =form.birth.data 
        gender = form.gender.data  
        if form.role.data == 'cashier' or form.role.data == 'academic' or form.role.data == 'admin':
            role = Role.objects(name=form.role.data).first() 
        else:  
            flash('Can\'t find role, please reload page', 'danger')
            return redirect(url_for('staff.create'))
        if image_file == "":
            user = User(first_name=first_name,last_name=last_name,phone=phone,email=email,gender=gender,address=address,birth=birth,role=role,image_file=image_file,salary=salary).save()
        else:
            user = User(first_name=first_name,last_name=last_name,phone=phone,email=email,gender=gender,address=address,birth=birth,role=role,salary=salary).save()
        account = Account(username=phone,password="******",user=user,is_activate=False).save()
        send_reset_email(user)  
        flash('Staff has been created! Your account is also created, please use phone to login to system. Verify is sending to your gmail, please wait a few minutes. Within 3 hour, you must login to system to change your new password', 'success')
        return redirect(url_for('staff.staff_info',id=user.id)) 
    return render_template('staff_create.html', title='Staff Create Staff\'s Info',activate=activate,form=form)
コード例 #18
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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'))
コード例 #19
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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))
コード例 #20
0
def create_data_user(num_admin=2,
                     num_academic=5,
                     num_cashier=5,
                     num_teacher=10):
    num = 0
    with open('it_center/data/user.json') as f:
        list_user = json.load(f)
        roles = ["admin", "academic", "cashier", "teacher", "student"]
        ro = dict()
        num_role = 4
        for item in list_user:
            if ro.get('admin') and ro.get('admin') == num_admin:
                num_admin = 0
                roles.pop(roles.index('admin'))
                num_role -= 1
            if ro.get('academic') and ro['academic'] == num_academic:
                num_academic = 0
                roles.pop(roles.index('academic'))
                num_role -= 1
            if ro.get('cashier') and ro['cashier'] == num_cashier:
                num_cashier = 0
                roles.pop(roles.index('cashier'))
                num_role -= 1
            if ro.get('teacher') and ro['teacher'] == num_teacher:
                num_teacher = 0
                roles.pop(roles.index('teacher'))
                num_role -= 1
            num = random.randint(0, num_role)
            if ro.get(roles[num]):
                count = ro[roles[num]] + 1
            else:
                count = 1
            ro[roles[num]] = count
            role = Role.objects(name=roles[num]).first()
            birth = datetime.datetime.strptime(item['birth']['$date'],
                                               '%Y-%m-%dT%H:%M:%S.%fZ')
            if role:
                num += 1
                User(first_name=item['first_name'],
                     last_name=item['last_name'],
                     email=item['email'],
                     phone=item['phone'],
                     role=role,
                     birth=birth,
                     address=item['address'],
                     gender=item['gender'],
                     image_file=item['image_file']).save()
    print("create success", num, "data user")
コード例 #21
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.')
コード例 #22
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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)
コード例 #23
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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'))
コード例 #24
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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))
コード例 #25
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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'))
コード例 #26
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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)
コード例 #27
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
def reset_token(token):
    user = User.verify_reset_token(token)
    account = Account.objects(user=user).first()
    if user is None or account is None:
        flash('That is an invalid or expired token', 'warning')
        return redirect(url_for('users.reset_request'))
    form = ResetPasswordForm()
    if form.validate_on_submit():
        hashed_password = bcrypt.generate_password_hash(
            form.password.data).decode('utf-8')
        account.password = hashed_password
        user.is_confirmed = True
        account.is_activate = True
        user.save()
        account.save()
        flash('Your password has been updated! You are now able to log in',
              'success')
        return redirect(url_for('users.login'))
    return render_template('reset_token.html',
                           title='Reset Password',
                           form=form)
コード例 #28
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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'))
コード例 #29
0
ファイル: routes.py プロジェクト: tranngocbaoduy/it_center
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
コード例 #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()])