def get_course():
    if session.get("id") is None:
        return redirect("/user/login")
    name2 = session.get("name")

    if request.method=="GET":


        return render_template('teacher_templates/importcourse.html',name=name2)

    else:
        name=request.form.get("name")
        if name=="" or name is None:
            return render_template('teacher_templates/importcourse.html', message="title不能为空")

        course =Course.query.filter_by(courseName=name).filter_by(teacherId=session.get("id")).first()
        if course:
            return render_template('teacher_templates/importcourse.html', message="该课程已经存在")

        with db.auto_commit():
            course = Course()
            course.courseName = name
            course.teacherId=session.get("id")
            db.session.add(course)
        return redirect("/course")
Exemple #2
0
    def patch(self, course_id):
        """
        Update a single course
        """

        # To do check if user is admin
        schema = CourseSchema(partial=True)

        update_data = request.get_json()

        validated_update_data, errors = schema.load(update_data)

        if errors:
            return dict(status="fail", message=errors), 400

        course = Course.get_by_id(course_id)

        if not course:
            return dict(status="fail",
                        message=f"Course with id {course_id} not found"), 404

        updated_course = Course.update(course, **validated_update_data)

        if not updated_course:
            return dict(status='fail', message='Internal Server Error'), 500

        return dict(status="success",
                    message="Course updated successfully"), 200
Exemple #3
0
    def post(self, course_id):
        course_type = self.request.get("course-type")
        title = self.request.get("title")
        city = self.request.get("city")
        place = self.request.get("place")
        start_date = self.request.get("start-date")
        end_date = self.request.get("end-date")
        price = self.request.get("price")
        currency = self.request.get("currency")
        description = self.request.get("description")
        spots = self.request.get("spots")

        course = Course.get_by_id(int(course_id))

        if course_type and title and city and place and start_date and end_date and price and currency:
            prices = [float(prc) for prc in price.strip().split(",")]
            start = start_date.split("-")
            end = end_date.split("-")

            Course.update(course=course,
                          title=title,
                          course_type=int(course_type),
                          city=city,
                          place=place,
                          spots=int(spots),
                          description=description,
                          start_date=datetime.date(int(start[0]),
                                                   int(start[1]),
                                                   int(start[2])),
                          end_date=datetime.date(int(end[0]), int(end[1]),
                                                 int(end[2])),
                          price=prices,
                          currency=currency)
            self.redirect_to("course-details", course_id=int(course_id))
Exemple #4
0
 def get(self, course_id):
     course = Course.get_by_id(int(course_id))
     applications = CourseApplication.query(
         CourseApplication.course_id == int(course_id),
         CourseApplication.deleted == False).fetch()
     params = {"course": course, "applications": applications}
     self.render_template("admin/course_details.html", params)
Exemple #5
0
 def post(self, application_id):
     application = CourseApplication.get_by_id(int(application_id))
     application.deleted = True
     application.put()
     course = Course.get_by_id(int(application.course_id))
     course.taken -= 1
     course.put()
     self.redirect_to("course-details", course_id=application.course_id)
Exemple #6
0
 def post(self, application_id):
     application = CourseApplication.get_by_id(int(application_id))
     application.deleted = True
     application.put()
     course = Course.get_by_id(int(application.course_id))
     course.taken -= 1
     course.put()
     self.redirect_to("course-details", course_id=application.course_id)
Exemple #7
0
def create_course():
    form = CourseCreateForm().validate_for_api()
    with db.auto_commit():
        course = Course()
        form.populate_obj(course)
        db.session.add(course)
        Enroll.add_user(course, form.teachers_gid.data, form.students_gid.data,
                        form.TAs_gid.data, db)
    return Success()
Exemple #8
0
 def get(self, course_id):
     course_types = CourseType.query().fetch()
     course = Course.get_by_id(int(course_id))
     selected_course_type = CourseType.get_by_id(course.course_type)
     course_price = str(course.price).replace("[", "").replace("]", "")
     params = {"course": course,
               "course_types": course_types,
               "course_price": course_price,
               "selected_course_type": selected_course_type}
     self.render_template("admin/course_edit.html", params)
Exemple #9
0
    def post(self):
        course_type = self.request.get("course-type")
        title = self.request.get("title")
        city = self.request.get("city")
        place = self.request.get("place")
        start_date = self.request.get("start-date")
        end_date = self.request.get("end-date")
        price = self.request.get("price")
        currency = self.request.get("currency")
        description = self.request.get("description")
        spots = self.request.get("spots")

        if course_type and title and city and place and start_date and end_date and price and currency:
            prices = [float(prc) for prc in price.strip().split(",")]
            start = start_date.split("-")
            end = end_date.split("-")

            Course.create(title=title, course_type=int(course_type), city=city, place=place, spots=int(spots),
                          description=description, start_date=datetime.date(int(start[0]), int(start[1]), int(start[2])),
                          end_date=datetime.date(int(end[0]), int(end[1]), int(end[2])), price=prices, currency=currency)
            self.redirect_to("course-list")
Exemple #10
0
 def get(self, course_id):
     course_types = CourseType.query().fetch()
     course = Course.get_by_id(int(course_id))
     selected_course_type = CourseType.get_by_id(course.course_type)
     course_price = str(course.price).replace("[", "").replace("]", "")
     params = {
         "course": course,
         "course_types": course_types,
         "course_price": course_price,
         "selected_course_type": selected_course_type
     }
     self.render_template("admin/course_edit.html", params)
Exemple #11
0
    def post(self):
        """
        Creating an Course ad
        """
        course_schema = CourseSchema()

        course_data = request.get_json()

        validated_course_data, errors = course_schema.load(course_data)

        if errors:
            return dict(status='fail', message=errors), 400

        course = Course(**validated_course_data)

        saved_course = course.save()

        if not saved_course:
            return dict(status='fail', message='Internal Server Error'), 500

        new_course_data, errors = course_schema.dumps(course)

        return dict(status='success',
                    data=dict(course=json.loads(new_course_data))), 201
Exemple #12
0
    def get(self):
        """
        Getting All courses
        """

        course_schema = CourseSchema(many=True)

        courses = Course.find_all()

        courses_data, errors = course_schema.dumps(courses)

        if errors:
            return dict(status="fail", message="Internal Server Error"), 500

        return dict(status="success",
                    data=dict(courses=json.loads(courses_data))), 200
Exemple #13
0
    def delete(self, course_id):
        """
        Delete a single course
        """

        course = Course.get_by_id(course_id)

        if not course:
            return dict(status="fail",
                        message=f"Course with id {course_id} not found"), 404

        deleted_course = course.delete()

        if not deleted_course:
            return dict(status='fail', message='Internal Server Error'), 500

        return dict(status='success', message="Successfully deleted"), 200
Exemple #14
0
def add_course(category_id):
    try:
        category = session.query(Category).filter_by(id=category_id).one()
    except:
        return error_message(
            404, "Cannot add new course to this category: Category not found.")
    name = request.form.get('name')
    if name:
        course = Course(name=name,
                        description=request.form.get('description'),
                        img_url=request.form.get('img-url'),
                        intro_video_url=request.form.get('intro-video-url'),
                        category_id=category.id)
        session.add(course)
        session.commit()
    else:
        return error_message(400, "Course name is required.")
    return data_message(200, {"Course": course.serialize},
                        "Successfully added a course.")
Exemple #15
0
    def get(self, course_id):
        """
        Getting individual course
        """
        schema = CourseSchema()

        course = Course.get_by_id(course_id)

        if not course:
            return dict(status="fail",
                        message=f"Course with id {course_id} not found"), 404

        course_data, errors = schema.dumps(course)

        if errors:
            return dict(status="fail", message=errors), 500

        return dict(status='success',
                    data=dict(course=json.loads(course_data))), 200
Exemple #16
0
def teacher_create():
    form = CourseCreateForm()

    if form.validate_on_submit():
        course = Course()
        course.name = form.name.data
        course.grade_level = form.grade_level.data
        course.price = form.price.data
        course.teacher = current_user

        db.session.add(course)
        db.session.commit()

        return redirect(url_for('course.teacher_show', id=course.id))

    return render_template('views/course/teacher_create.html',
                           title='Create Course',
                           form=form)
Exemple #17
0
def add_user_to_course(user, kraj_tecaja, kotizacija, prenosnik, majica):
    course_type = CourseType.query(CourseType.title == "SmartNinja Vikend Slovenia").get()
    if not course_type:
        course_type = CourseType()
        course_type.title = "SmartNinja Vikend Slovenia"
        course_type.put()

    course = None

    price = [97.00, 147.00, 197.00]

    if kraj_tecaja == "Ljubljana":
        course = Course.query(Course.title == "SmartNinja Vikend Ljubljana").get()
        if not course:
            course = Course.create(title="SmartNinja Vikend Ljubljana", city="Ljubljana", start_date=datetime.date(2015, 2, 7),
                                   end_date=datetime.date(2015, 2, 8), description="", price=price, place="",
                                   course_type=course_type.get_id, currency="EUR", spots=10)
    elif kraj_tecaja == "Maribor":
        course = Course.query(Course.title == "SmartNinja Vikend Maribor").get()
        if not course:
            course = Course.create(title="SmartNinja Vikend Maribor", city="Maribor", start_date=datetime.date(2015, 2, 14),
                                   end_date=datetime.date(2015, 2, 15), description="", price=price, place="",
                                   course_type=course_type.get_id, currency="EUR", spots=10)
    elif kraj_tecaja == "NovaGorica":
        course = Course.query(Course.title == "SmartNinja Vikend Nova Gorica").get()
        if not course:
            course = Course.create(title="SmartNinja Vikend Nova Gorica", city="Nova Gorica", start_date=datetime.date(2015, 2, 28),
                                   end_date=datetime.date(2015, 3, 1), description="", price=price, place="",
                                   course_type=course_type.get_id, currency="EUR", spots=10)

    if course:
        course_app = CourseApplication.create(course_title=course.title, course_id=course.get_id, student_name=user.get_full_name,
                                              student_id=user.get_id, student_email=user.email, price=kotizacija, currency="EUR",
                                              laptop=prenosnik, shirt=majica)
        course.taken += 1
        course.put()
Exemple #18
0
 def post(self, course_id):
     course = Course.get_by_id(int(course_id))
     course.deleted = True
     course.put()
     self.redirect_to("course-list")
Exemple #19
0
 def post(self, course_id):
     course = Course.get_by_id(int(course_id))
     course.deleted = True
     course.put()
     self.redirect_to("course-list")
Exemple #20
0
 def get(self, course_id):
     course = Course.get_by_id(int(course_id))
     params = {"course": course}
     self.render_template("admin/course_delete.html", params)
Exemple #21
0
 def get(self):
     courses = Course.query(Course.deleted == False).fetch()
     params = {"courses": courses}
     self.render_template("admin/course_list.html", params)
teacher = Teacher()
teacher.name = 'Ömer Çulha'
teacher.email = '*****@*****.**'
teacher.phone = '0000 000 00 00'
teacher.generate_password_hash('123456')
db.session.add(teacher)

student = Student()
student.name = 'Yunus Emre'
student.email = '*****@*****.**'
student.phone = '0000 000 00 00'
student.grade_level = 1
student.parent_code = "11111111111"
student.generate_password_hash('123456')
db.session.add(student)

course = Course()
course.name = 'Fen Bilgisi'
course.grade_level = 1
course.teacher = teacher
course.price = "25"
db.session.add(course)

exam = Exam()
exam.name = 'Fen Sınavı'
exam.date = date.today()
exam.course = course
db.session.add(exam)

db.session.commit()
Exemple #23
0
 def get(self, course_id):
     course = Course.get_by_id(int(course_id))
     params = {"course": course}
     self.render_template("admin/course_delete.html", params)
Exemple #24
0
 def get(self):
     courses = Course.query(Course.deleted == False).fetch()
     params = {"courses": courses}
     self.render_template("admin/course_list.html", params)
def getAllCourses():
    return Course.getAllCourses()
Exemple #26
0
# session.rollback()
session = DBSession()

# CATEGORY: Web Development
category1 = Category(name='Web Development')

session.add(category1)
session.commit()

course1 = Course(
    name='JavaScript: Understanding the Weird Parts',
    description=
    'In this course you will gain a deep understanding of Javascript, '
    'learn how Javascript works under the hood, and how that knowledge '
    'helps you avoid common pitfalls and drastically improve your ability '
    'to debug problems. You will find clarity in the parts that others, '
    'even experienced coders, may find weird, odd, and at times incomprehensible. '
    'You\'ll learn the beauty and deceptive power of this language that is at the '
    'forefront of modern software development today.',
    img_url='https://udemy-images.udemy.com/course/750x422/364426_2991_5.jpg',
    intro_video_url='',
    category_id=category1.id)

session.add(course1)
session.commit()

course2 = Course(
    name='The Web Developer Bootcamp',
    description=
    'The only course you need to learn web development - HTML, CSS, JS, Node, and More!',
    img_url='https://udemy-images.udemy.com/course/750x422/625204_436a_2.jpg',
Exemple #27
0
def import_course(filename='', replace=False):
    print("Filename: {}".format(filename))
    print(" Replace: {}".format(replace))

    with open(filename) as csvfile:
        courses = csv.DictReader(csvfile)
        for row in courses:
            cid = row['課程編號'].decode("UTF-8")
            name = row['課程名稱'].decode("UTF-8")
            description = row['課程敘述'].decode("UTF-8")
            classroom = row['教室'].decode("UTF-8")
            price = row['收費價格'].decode("UTF-8")
            teacher = row['教師'].decode("UTF-8")
            teacher_tag = row['教師說明'].decode("UTF-8")
            teacher_phone = row['教師聯絡電話'].decode("UTF-8")
            grades = row['開課年級'].decode("UTF-8")
            lowbound = row['下限人數'].decode("UTF-8")
            upbound = row['上限人數'].decode("UTF-8")
            datetime = row['上課日期時間'].decode("UTF-8")

            # lookup first
            # unique => grade, class, number
            c = Course.query.filter_by(cid=cid).first()

            # not exist then add a course
            if c is None:
                c = Course(
                    cid=cid,
                    name=name,
                    description=description,
                    classroom=classroom,
                    price=price,
                    teacher=teacher,
                    teacher_tag=teacher_tag,
                    teacher_phone=teacher_phone,
                    grades=grades,
                    lowbound=lowbound,
                    upbound=upbound,
                    datetime=datetime,
                )
                db.session.add(c)
            else:
                # exist then update a ticket
                if replace:
                    c.name = name
                    c.description = description
                    c.classroom = classroom
                    c.price = price
                    c.teacher = teacher
                    c.teacher_tag = teacher_tag
                    c.teacher_phone = teacher_phone
                    c.grades = grades
                    c.lowbound = lowbound
                    c.upbound = upbound
                    c.datetime = datetime
                    c.count = 0

        db.session.commit()
Exemple #28
0
def add_user_to_course(user, kraj_tecaja, kotizacija, prenosnik, majica):
    course_type = CourseType.query(
        CourseType.title == "SmartNinja Vikend Slovenia").get()
    if not course_type:
        course_type = CourseType()
        course_type.title = "SmartNinja Vikend Slovenia"
        course_type.put()

    course = None

    price = [97.00, 147.00, 197.00]

    if kraj_tecaja == "Ljubljana":
        course = Course.query(
            Course.title == "SmartNinja Vikend Ljubljana").get()
        if not course:
            course = Course.create(title="SmartNinja Vikend Ljubljana",
                                   city="Ljubljana",
                                   start_date=datetime.date(2015, 2, 7),
                                   end_date=datetime.date(2015, 2, 8),
                                   description="",
                                   price=price,
                                   place="",
                                   course_type=course_type.get_id,
                                   currency="EUR",
                                   spots=10)
    elif kraj_tecaja == "Maribor":
        course = Course.query(
            Course.title == "SmartNinja Vikend Maribor").get()
        if not course:
            course = Course.create(title="SmartNinja Vikend Maribor",
                                   city="Maribor",
                                   start_date=datetime.date(2015, 2, 14),
                                   end_date=datetime.date(2015, 2, 15),
                                   description="",
                                   price=price,
                                   place="",
                                   course_type=course_type.get_id,
                                   currency="EUR",
                                   spots=10)
    elif kraj_tecaja == "NovaGorica":
        course = Course.query(
            Course.title == "SmartNinja Vikend Nova Gorica").get()
        if not course:
            course = Course.create(title="SmartNinja Vikend Nova Gorica",
                                   city="Nova Gorica",
                                   start_date=datetime.date(2015, 2, 28),
                                   end_date=datetime.date(2015, 3, 1),
                                   description="",
                                   price=price,
                                   place="",
                                   course_type=course_type.get_id,
                                   currency="EUR",
                                   spots=10)

    if course:
        course_app = CourseApplication.create(course_title=course.title,
                                              course_id=course.get_id,
                                              student_name=user.get_full_name,
                                              student_id=user.get_id,
                                              student_email=user.email,
                                              price=kotizacija,
                                              currency="EUR",
                                              laptop=prenosnik,
                                              shirt=majica)
        course.taken += 1
        course.put()
Exemple #29
0
 def get(self, course_id):
     course = Course.get_by_id(int(course_id))
     applications = CourseApplication.query(CourseApplication.course_id == int(course_id), CourseApplication.deleted == False).fetch()
     params = {"course": course, "applications": applications}
     self.render_template("admin/course_details.html", params)