예제 #1
0
def api_get_courses():
    if 'company' in session:
        login = session['company']
        id_company = GetCompany.get_company_id_from_db(login)
        results = GetCourses.api_get_courses(id_company)
        photo = GetCompany.get_photo_company(id_company)
        if photo is None:
            photo = 'http://placehold.it/100x100'
        else:
            photo = photo
        courses = []
        for result in results:
            id_course = str(result[0])
            id_company = str(result[1])
            name = result[2]
            amount = result[3]
            city = result[4]
            country = result[5]
            date_of_start = result[6]
            date_of_end = result[7]
            info = result[8]
            status = result[9]
            course = {
                "name": name,
                "amount": amount,
                "city": city,
                "country": country,
                "date_of_start": date_of_start,
                "date_of_end": date_of_end,
                "info": info,
                "status": status,
                "link": '/course/!' + id_course + '/!' + id_company,
                "photo": photo
            }
            courses.append(course)
        return render_template('courses-c.html', courses=courses)
    else:
        return redirect("/")
예제 #2
0
def comment_about_student_request():
    print(request.json)
    if not request.json:
        return abort(400)
    if 'student_login' not in request.json:
        return abort(400)
    if 'review' not in request.json:
        return abort(400)
    student_login = request.json['student_login']
    review = request.json['review']
    if 'company' in session:
        company_login = session['company']
        if CommentAboutStudent.check_student_course(student_login, company_login) == 1:
            company_id = GetCompany.get_company_id_from_db(company_login)
            student_id = GetStudent.get_students_id_from_db(student_login)
            time = str(datetime.now().strftime('%H:%M, %d.%m.%Y'))
            CommentAboutStudent.comment_about_student(student_id, company_id, review, time)
            return jsonify(redirect="true", redirect_url=student_login), 200
        else:
            return jsonify(redirect="false", message="This user does not finished your course or "
                                                     "had not approved your course"), 200
예제 #3
0
def api_create_courses():
    if request.json:
        if 'company' in session:
            if 'name' not in request.json and 'amount' not in request.json and 'city' not in request.json and 'country' not in request.json and 'date_of_start' not in request.json and 'date_of_end' not in request.json and 'info' not in request.json:
                abort(404)
            login = session['company']
            name = request.json['name']
            amount = request.json['amount']
            city = request.json['city']
            country = request.json['country']
            date_of_start = request.json['date_of_start']
            date_of_end = request.json['date_of_end']
            info = request.json['info']
            status = request.json['status']
            id_company = GetCompany.get_company_id_from_db(login)
            CreateCourses.create_course(id_company,name,amount,city,country,date_of_start,date_of_end,info,status)
            return jsonify(redirect='true', redirect_url='/company/course')
        else:
            return 'please log in'
    if not request.json:
        return 'something wrong with you request'
    def equals_password(cls, password, login, new_password):
        value = ChangePasswordCompany.check_password(login, password)
        print(value)
        if value == 1:
            connect = mysql.connect()
            cursor = connect.cursor()

            password_enc = generate_password_hash(new_password)
            id_company = GetCompany.get_company_id_from_db(login)

            query = 'update company SET CompanyPassword = %s WHERE idCompany = %s'
            param = (password_enc, id_company)
            cursor.execute(query, param)

            response_value = value

            connect.commit()
            cursor.close()

        else:
            response_value = value

        return response_value
예제 #5
0
def register_company_api():
    if not request.json:
        abort(400)
    if 'login' not in request.json and 'name' not in request.json and 'password' not in request.json and 'email' not in request.json and 'confirm' not in request.json:
        abort(400)

    login = request.json['login']
    name = request.json['name']
    password = request.json['password']
    email = request.json['email']
    confirm = request.json['confirm']
    if login != "" and name != "" and password != "" and email != "" and confirm != "":
        if password != confirm:
            return jsonify(redirect='false',
                           message='Passwords don`t match. Try again....'), 400
        else:
            if Company.check_login_for_used(login) == 0:
                return jsonify(
                    redirect='false',
                    message='Your login already exist. Try again....'), 400
            if Company.check_email_for_used(email) == 0:
                return jsonify(
                    redirect='false',
                    message='Your email already exist. Try again....'), 400

            else:
                password_enc = generate_password_hash(password)
                Company.save_company_user(login, name, email, password_enc)
                id = GetCompany.get_company_id_from_db(login)
                Company.save_info_about_company(id)
                session['company'] = login

            return jsonify(redirect='true',
                           redirect_url='/user/company/' + login), 200
    else:
        return jsonify('Bad request'), 405
예제 #6
0
def api_info_about_company(login):
    if login == "":
        return jsonify(status="User`s login is null"), 404
    else:
        id_company = GetCompany.get_company_id_from_db(login)
        if id_company == 0:
            return 'Not such User in db'
        else:
            result = CompanySession.check_in_session_company()
            if result == 0:
                return "Please log in"
            if result == login:
                name = GetCompany.get_company_name_from_db(login)
                email = GetCompany.get_company_email_from_db(login)
                web_site = GetCompany.get_company_web_site(id_company)
                city = GetCompany.get_company_city(id_company)
                country = GetCompany.get_company_country(id_company)
                about_company = GetCompany.get_about_company(id_company)
                photo = GetCompany.get_photo_company(id_company)
                check = GetCompany.get_check_company(login)
                courses = GetCompany.get_company_course(id_company)
                courses_response = []
                for course in courses:
                    course = {
                        'name':
                        course[0],
                        'status':
                        course[2],
                        'url':
                        '/course/!' + str(course[1]) + "/!" + str(id_company)
                    }
                    courses_response.append(course)
                if photo is None:
                    photo = 'http://placehold.it/500x500'
                else:
                    photo = photo
                if check == 0:
                    check = "color:transparent"
                    company = {
                        'name': name,
                        'email': email,
                        'website': web_site,
                        'city': city,
                        'country': country,
                        'about_company': about_company,
                        'check': check,
                        'photo': photo
                    }
                    return render_template("profile-c.html",
                                           company=company,
                                           courses=courses_response)
                if check == 1:
                    check = "color:grey"
                    company = {
                        'name': name,
                        'email': email,
                        'website': web_site,
                        'city': city,
                        'country': country,
                        'about_company': about_company,
                        'check': check,
                        'photo': photo
                    }
                    return render_template("profile-c.html",
                                           company=company,
                                           courses=courses_response)
            else:
                return 'Please log in'
예제 #7
0
def api_get_info_about_company_review(login):
    check = GetCompany.check_such_user_company(login)
    if login != 0:
        id_company = GetCompany.get_company_id_from_db(login)
        name = GetCompany.get_company_name_from_db(login)
        email = GetCompany.get_company_email_from_db(login)
        web_site = GetCompany.get_company_web_site(id_company)
        city = GetCompany.get_company_city(id_company)
        country = GetCompany.get_company_country(id_company)
        about_company = GetCompany.get_about_company(id_company)
        photo = GetCompany.get_photo_company(id_company)
        check = GetCompany.get_check_company(login)
        if photo is None:
            photo = 'http://placehold.it/500x500'
        else:
            photo = photo
        company = {
            'name': name,
            'email': email,
            'website': web_site,
            'city': city,
            'country': country,
            'about_company': about_company,
            'check': check,
            'photo': photo
        }
        courses = GetCompany.get_company_course(id_company)
        courses_response = []
        for course in courses:
            course = {
                'name': course[0],
                'status': course[2],
                'url': '/course/!' + str(course[1]) + "/!" + str(id_company)
            }
            courses_response.append(course)
        return render_template("profile-c-reviews.html",
                               company=company,
                               courses=courses_response)
    else:
        return 'Not such user'
예제 #8
0
def get_photo(id_company):
    photo = GetCompany.get_photo_company(id_company)
    photo_js = {'photo': photo}
    return jsonify(photo=photo_js), 200
예제 #9
0
def api_get_one_course(id_course, id_company):
    if 'student' in session or 'company' in session:
        status = OneCourse.api_get_status_course(id_course, id_company)
        if 'student' in session and status == "Started" or status == "Not started" and 'company' not in session:
            global list_of_student
            course = OneCourse.api_get_one_course(id_course, id_company)
            students = OneCourse.get_students_list_on_course(id_course)
            photo = GetCompany.get_photo_company(id_company)
            if photo is None:
                photo = 'http://placehold.it/500x500'
            else:
                photo = photo
            list_of_student = []
            for student in students:
                student = {
                    'student_name': student[0],
                    'student_last_name': student[1],
                    'link': '/student/review/' + student[2]
                }
                list_of_student.append(student)
            return render_template('course-apply.html',
                                   course=course,
                                   list_of_student=list_of_student,
                                   photo=photo)

        if 'student' in session and status == "Finished":
            global comments
            course = OneCourse.api_get_one_course(id_course, id_company)
            reviews = OneCourse.get_review_about_course(id_course)
            photo = GetCompany.get_photo_company(id_company)
            if photo is None:
                photo = 'http://placehold.it/500x500'
            else:
                photo = photo
            comments = []
            for review in reviews:
                comment = {
                    'student_name': review[0],
                    'student_last_name': review[1],
                    'review': review[2],
                    'time': review[3],
                    'id_comment': review[4]
                }
                comments.append(comment)
            return render_template('course-reviews.html',
                                   course=course,
                                   course_id=id_course,
                                   comments=comments,
                                   photo=photo)

        if 'company' in session:
            login_company_in_session = session['company']
            id_company_in_session = GetCompany.get_company_id_from_db(
                login_company_in_session)
            if int(id_company) == int(id_company_in_session):
                if status == "Started" or status == "Not started":
                    course = OneCourse.api_get_one_course(
                        id_course, id_company)
                    list_link = '/list_of_statement/' + id_course
                    students = OneCourse.get_students_list_on_course(id_course)
                    photo = GetCompany.get_photo_company(id_company)
                    if photo is None:
                        photo = 'http://placehold.it/500x500'
                    else:
                        photo = photo
                    list_of_student = []
                    for student in students:
                        student = {
                            'student_name': student[0],
                            'student_last_name': student[1],
                            'link': '/student/review/' + student[2]
                        }
                        list_of_student.append(student)
                    return render_template(
                        'course-company-list-of-student.html',
                        course=course,
                        list_link=list_link,
                        list_of_student=list_of_student,
                        photo=photo,
                        id_course=id_course)
                if status == "Finished":
                    course = OneCourse.api_get_one_course(
                        id_course, id_company)
                    reviews = OneCourse.get_review_about_course(id_course)
                    photo = GetCompany.get_photo_company(id_company)
                    if photo is None:
                        photo = 'http://placehold.it/500x500'
                    else:
                        photo = photo
                    comments = []
                    for review in reviews:
                        comment = {
                            'student_name': review[0],
                            'student_last_name': review[1],
                            'review': review[2],
                            'time': review[3],
                            'id_comment': review[4]
                        }
                        comments.append(comment)
                    students = OneCourse.get_students_list_on_course(id_course)
                    list_of_student = []
                    for student in students:
                        student = {
                            'student_name': student[0],
                            'student_last_name': student[1],
                            'link': '/student/review/' + student[2]
                        }
                        list_of_student.append(student)
                    return render_template(
                        'course-company-review-finished.html',
                        course=course,
                        comments=comments,
                        list_of_student=list_of_student,
                        photo=photo,
                        id_course=id_course)

            if int(id_company) != int(id_company_in_session):
                if status == "Finished":
                    course = OneCourse.api_get_one_course(
                        id_course, id_company)
                    reviews = OneCourse.get_review_about_course(id_course)
                    photo = GetCompany.get_photo_company(id_company)
                    if photo is None:
                        photo = 'http://placehold.it/500x500'
                    else:
                        photo = photo
                    comments = []
                    for review in reviews:
                        comment = {
                            'student_name': review[0],
                            'student_last_name': review[1],
                            'review': review[2],
                            'time': review[3]
                        }
                        comments.append(comment)
                    return render_template(
                        'course-company-review-finished-without-student.html',
                        course=course,
                        comments=comments,
                        photo=photo)

                if status == "Started" or status == "Not started":
                    course = OneCourse.api_get_one_course(
                        id_course, id_company)
                    students = OneCourse.get_students_list_on_course(id_course)
                    photo = GetCompany.get_photo_company(id_company)
                    if photo is None:
                        photo = 'http://placehold.it/500x500'
                    else:
                        photo = photo
                    list_of_student = []
                    for student in students:
                        student = {
                            'student_name': student[0],
                            'student_last_name': student[1]
                        }
                        list_of_student.append(student)
                    return render_template(
                        'course-company-review-student.html',
                        course=course,
                        list_of_student=list_of_student,
                        photo=photo)
    else:
        return redirect('/'), 200
예제 #10
0
def api_update_company():
    if 'company' in session:
        global value
        login = session['company']
        id_company = GetCompany.get_company_id_from_db(login)
        value = 0
        if 'webSite' in request.json:
            web_site = request.json['webSite']
            if web_site != "":
                UpdateCompany.update_web_site(id_company, web_site)
                value = 1

        if 'City' in request.json:
            city = request.json['City']
            if city != "" and city != "Null":
                UpdateCompany.update_city(city, id_company)
                value = 1

        if 'Country' in request.json:
            country = request.json['Country']
            if country != "" and country != "Null":
                UpdateCompany.update_country(country, id_company)
                value = 1

        if 'Photo' in request.json:
            photo = request.json['Photo']
            if photo != "":
                UpdateCompany.update_image(photo, id_company)
                value = 1

        if 'CompanyName' in request.json:
            company_name = request.json['CompanyName']
            if company_name != "":
                UpdateCompany.update_company_name(company_name, id_company)
                value = 1

        if 'AboutCompany' in request.json:
            about_company = request.json['AboutCompany']
            if about_company != "":
                UpdateCompany.update_about_company(about_company, id_company)
                value = 1

        if 'Email' in request.json:
            email = request.json['Email']
            if email != "":
                check = UpdateCompany.check_company_email(email)
                if check != 1:
                    UpdateCompany.update_company_email(id_company, email)
                    value = 1

        if 'NewPassword' in request.json and 'OldPassword' in request.json and 'ConfirmPassword' in request.json:
            new_password = request.json['NewPassword']
            old_password = request.json['OldPassword']
            confirm_password = request.json['ConfirmPassword']
            if new_password != "" and old_password != "" and confirm_password != "":
                if confirm_password == new_password:
                    value = ChangePasswordCompany.equals_password(old_password, login, new_password)
                    if value == 0:
                        return jsonify(redirect='false', message='Incorrect old password'), 200
                else:
                    return jsonify(redirect='false',message='Password don`t match. Try again....'), 200
        if value == 1:
            return jsonify(redirect="true", redirect_url='/user/company/' + login,
                           message='Changes have been successfully saved'), 200
        if value == 0:
            return jsonify(redirect="true", redirect_url='/user/company/' + login,
                           message='Something went wrong. Try again later!!!'), 200
    else:
        message = 'Please log in. Something wrong with your session.'
        return jsonify(redirect='true', redirect_url='/error/' + message), 405