def find_course(page): finder = Finder() finder.set_data(page) name_pattern = '"(.+)"' names = finder.find_references(name_pattern) price_pattern = '(\d+) дн / (\d+) р.' prices = finder.find_references(price_pattern) i0 = 0 for name in names: print(name) c = Course(site_id=s.id, name=name) c.save() of1 = Offer(course_id=c.id, duration_hours=0, duration_days=prices[i0][0], price=prices[i0][1]) of2 = Offer(course_id=c.id, duration_hours=0, duration_days=prices[i0 + 1][0], price=prices[i0 + 1][1]) i0 += 2 of1.save() of2.save() return []
def add(): """ Create a new assignment with the given information """ add_form = AddCourseForm(request.form) if request.method == 'POST': Course.new(name=add_form.name.data, owner_id = g.user.id, visibility=add_form.visibility.data) flash('New course added') return redirect(url_for('courses.index')) return render_template('courses/add.html', add_form=add_form)
def update_cart(self): #session['cart'] = [] data = {} data['loggedIn'] = False data['course_lessons'] = [] course = {} reverse_cart = [] if 'cart' not in session: session['cart'] = [] if 'reverse_cart' not in session: session['reverse_cart'] = [] if 'student' in session: data['loggedIn'] = True data['student'] = session['student'] if request.method == 'POST': newCourse = Course() course_id = request.form['course_id'] selCourse = newCourse.get_course_by_id(ObjectId(course_id)) course['title'] = selCourse['title'] course['cost'] = selCourse['price'] course['id'] = str(selCourse['_id']) if course not in session['cart']: session['cart'].append(course) session.modified = True #return jsonify(session) #return jsonify(session['cart']) if len(session['cart']) > 0: session['cart_total'] = 0 session['reverse_cart'] = [] for cart in session['cart']: reverse_cart.append(cart) session['cart_total'] = session['cart_total'] + cart[ 'cost'] rcount = len(reverse_cart) #return jsonify(reverse_cart) while (rcount > 0): session['reverse_cart'].append(reverse_cart.pop()) session.modified = True rcount = rcount - 1 return redirect( url_for('purchase_course', courseId=course['id'])) #return redirect(url_for('dashboard')) else: return redirect(url_for('dashboard')) else: return redirect(url_for('index'))
def __init__(self): if 'instructor' in session: self.loggedIn = True else: return redirect(url_for('instructor_login')) self.newInstructor = Instructor() self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent_question = Student_question()
def __init__(self): if 'student' not in session: return redirect(url_for('index')) self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response()
def addCourse(catalog_id): catalog = db_session.query(Catalog).filter( Catalog.catalog_id == catalog_id).one() school = db_session.query(School).filter( School.school_id == catalog.school_id).one() courses = db_session.query(Course).join(Catalog).filter( Catalog.catalog_id == catalog.catalog_id).all() form = initalizeCourseForm() if form.is_submitted() and form.validate_on_submit(): course = Course() course.catalog_id = catalog.catalog_id course.number = form.number.data course.name = form.name.data course.description = form.description.data course.credit_type_id = form.credit_type_id.data course.credits = form.credits.data db_session.add(course) db_session.commit() flash("Saved Successfully.") return redirect( url_for('catalog.viewCatalog', catalog_id=catalog.catalog_id)) return render_template('catalog/addCourse.html', form=form, catalog=catalog, school=school, courses=courses)
def __init__(self): if 'instructor' in session: self.loggedIn = True self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response()
def load_user(): if current_user.is_authenticated(): g.user = current_user if 'lti_course' in session: g.course = Course.by_id(session['lti_course']) else: g.user = None
def load_user(): if current_user.is_authenticated: g.user = current_user if 'lti_course' in session: g.course = Course.by_id(session['lti_course']) else: g.user = None
def submissions_filter(course_id): ''' List all the users in the course ''' is_grader = g.user.is_grader(int(course_id)) if not is_grader: return "You are not an instructor or TA in this course!" course_id = int(course_id) course = Course.by_id(course_id) students = natsorted(course.get_students(), key=lambda r: r.name()) assignments = natsorted([a for a, m in course.get_submitted_assignments()], key=lambda r: r.name) criteria = request.values.get("criteria", "none") search_key = int(request.values.get("search_key", "-1")) submissions = [] if criteria == "student": all_subs = Submission.by_student(search_key, course_id) all_subs = {s[0].assignment_id: s for s in all_subs} submissions = [all_subs.get(assignment.id, (None, None, assignment)) for assignment in assignments] elif criteria == "assignment": all_subs = Submission.by_assignment(search_key, course_id) all_subs = {s[0].user_id: s for s in all_subs} submissions = [all_subs.get(student.id, (None, student, None)) for student in students] return render_template('courses/submissions_filter.html', course_id=course_id, assignments=assignments, students=students, submissions= submissions, criteria = criteria, search_key = search_key, is_instructor=is_grader)
def run(self, **kwargs): from models.models import Role, User, Course with open('secrets.json', 'r') as secret_file: secrets = json.load(secret_file).get("ADMIN", {}) print("Adding Admin") admin = User(first_name=secrets.get("first_name", "Admin"), last_name=secrets.get("last_name", "User"), password=encrypt_password( secrets.get("password", "password")), confirmed_at=datetime.datetime.now(), active=True, email=secrets.get("email", "*****@*****.**")) db.session.add(admin) db.session.flush() db.session.add(Role(name='instructor', user_id=admin.id)) db.session.add(Role(name='admin', user_id=admin.id)) print("Adding default course") default_course = Course(name="Default Course", owner_id=admin.id, service="native") db.session.add(default_course) db.session.flush() db.session.add( Role(name='instructor', course_id=default_course.id, user_id=admin.id)) db.session.commit() print("Complete")
def lti_wrapper(*args, **kwargs): """ Pass LTI reference to function or return error. """ try: the_lti = LTI(lti_args, lti_kwargs) the_lti.verify() kwargs['lti'] = the_lti old_user = g.user g.user = User.from_lti("canvas", session["pylti_user_id"], session.get("lis_person_contact_email_primary", ""), session.get("lis_person_name_given", "Canvas"), session.get("lis_person_name_family", "User")) g.roles = session["roles"].split(",") if "roles" in session else [] g.course = Course.from_lti("canvas", session["context_id"], session.get("context_title", ""), g.user.id) session['lti_course'] = g.course.id g.user.update_roles(g.roles, g.course.id) if old_user != g.user: flask_security.utils.logout_user() flask_security.utils.login_user(g.user, remember = True) if not old_user: flask_security.utils.login_user(g.user, remember = True) except LTIException as lti_exception: kwargs['lti'] = None kwargs['lti_exception'] = dict() kwargs['lti_exception']['exception'] = lti_exception kwargs['lti_exception']['kwargs'] = kwargs kwargs['lti_exception']['args'] = args flash("LTI Error: "+str(lti_exception)+".\nTry reloading!") return function(*args, **kwargs)
def view_assignments(course_id): #TODO: ensure in course course = Course.by_id(course_id) assignments = Assignment.by_course(course_id) groups = AssignmentGroup.by_course(course_id) return render_template('courses/view_assignments.html', assignments=assignments, groups=groups, course=course, course_id=course_id)
def manage_users(course_id): ''' List all the users in the course ''' is_instructor = g.user.is_instructor(int(course_id)) students = Course.by_id(int(course_id)).get_users() return render_template('courses/manage_users.html', students=students, course_id=course_id, is_instructor=is_instructor)
def assignments(course_id): #TODO: ensure in course assignments = Assignment.get_available() groups = AssignmentGroup.query.all() course_groups = Course.get_all_groups() editable_courses = g.user.get_editable_courses() return render_template('courses/assignments.html', assignments=assignments, groups=groups, editable_courses=editable_courses, course_groups=course_groups, course_id=course_id)
class QuestionController(): def __init__(self): if 'instructor' in session: self.loggedIn = True self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response() def question(self, questionId): data = {} data['responses'] = [] question_id = ObjectId(questionId) question = self.newStudent_question.get_question(question_id) lesson = self.newLesson.get_lesson_by_id( ObjectId(question['lesson_id'])) course = self.newCourse.get_course_by_id( ObjectId(question['course_id'])) responses = self.newQuestion_response.get_question_responses( questionId) if (responses.count() > 0): for response in responses: if (response['student_id'] == 0): instructor = self.newInstructor.get_instructor_by_id( ObjectId(response['instructor_id'])) response['instructor'] = instructor if (response['instructor_id'] == 0): student = self.newStudent.get_student_by_id( ObjectId(response['student_id'])) response['student'] = student data['responses'].append(response) data['question'] = question #data['responses'] = responses data['lesson'] = lesson data['course'] = course return render_template("student/question.html", data=data) session['error_msg'].clear() def respond(self): student_id = session['student']['id'] question_id = request.form['question_id'] response = request.form['response'] result = self.newQuestion_response.student(question_id, student_id, response) if (result == 'ERROR'): return question_id + ' ' + student_id + ' ' + response + ' OOPS! Problem occured while trying to submit your response, try again later' return redirect(url_for('question', questionId=question_id))
class InstructorController(): loggedIn = False def __init__(self): if 'instructor' in session: self.loggedIn = True else: return redirect(url_for('instructor_login')) self.newInstructor = Instructor() self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent_question = Student_question() def dashboard_data(self): data = {} data['logged_in'] = True data['courses'] = [] data['instructor'] = self.newInstructor.get_instructor_by_name( session['instructor']['name']) fields = {"instructor_id": data['instructor']['_id']} courses = self.newCourse.get_courses(fields) data['new_course_form'] = CourseForm() data['new_course_form'].instructor_id.data = data['instructor']['_id'] if courses: for course in courses: course_subscription = self.newStudent_subscription.get_course_subscriptions( course['_id']) course['subscribed'] = course_subscription.count() questions = self.newStudent_question.get_course_questions( str(course['_id'])) course['questions'] = questions.count() data['courses'].append(course) return data def dashboard(self): data = self.dashboard_data() return render_template("instructor/dashboard.html", data=data) def courses(self): data = self.dashboard_data() data['view'] = 'courses' return render_template("instructor/dashboard.html", data=data) def new_course(self): data = self.dashboard_data() data['view'] = 'new' return render_template("instructor/dashboard.html", data=data)
def __init__(self): if 'instructor' in session: self.loggedIn = True else: return redirect(url_for('instructor_login')) self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response() self.uploadFolder = 'static/images/courses_cover_photos' self.allowedExtensions = set(['png', 'jpg', 'jpeg', 'gif', 'psd'])
def __init__(self): self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson()
def select(lti, menu='select', lti_exception=None): """ Let's the user select from a list of assignments. """ # Store current user_id and context_id assignments = Assignment.get_available() groups = AssignmentGroup.query.all() return_url = get_lti_property('launch_presentation_return_url') course_groups = Course.get_all_groups() editable_courses = g.user.get_editable_courses() return render_template('lti/select.html', assignments=assignments, groups=groups, return_url=return_url, menu=menu, editable_courses=editable_courses, course_groups=course_groups)
def index(): """ List all of the courses associated with the user. """ user_id = g.user.id my_courses = g.user.get_courses() public_courses = Course.get_public() return render_template('courses/index.html', my_courses=my_courses, public_courses=public_courses)
def ensure_canvas_arguments(): ''' Translates the current session data into a valid user ''' user = User.from_lti("canvas", session["pylti_user_id"], session.get("lis_person_contact_email_primary", ""), session.get("lis_person_name_given", "Canvas"), session.get("lis_person_name_family", "User")) if "roles" in session: roles = session["roles"].split(",") else: roles = [] course = Course.from_lti("canvas", session["context_id"], session.get("context_title", ""), user.id) return user, roles, course
def run(self, user_data_file, **kwargs): from models.models import Role, User, Course, Assignment print("Adding Admin") admin = User(first_name='Cory', last_name='Bart', password=encrypt_password('password'), confirmed_at=datetime.datetime.now(), active=True, email='*****@*****.**', gender='Male') db.session.add(admin) db.session.flush() db.session.add(Role(name='instructor', user_id=admin.id)) db.session.add(Role(name='admin', user_id=admin.id)) print("Adding some students for color") for student in ('Dan Tilden', 'Anamary Leal', 'Ellie Cayford'): first, last = student.split() email = '{}{}@vt.edu'.format(first[0].lower(), last.lower()) db.session.add(User(first_name=first, last_name=last, email=email)) print("Adding default course") default_course = Course(name="Default Course", owner_id=admin.id, service="blockpy") db.session.add(default_course) db.session.flush() print("Adding some assignments") assignment1 = Assignment(name="Example #1", body="a=b+c", course_id=default_course.id, owner_id=admin.id) db.session.add(assignment1) db.session.commit() print("Complete")
def submissions_grid(course_id): ''' List all the users in the course ''' course_id = int(course_id) is_instructor = g.user.is_instructor(course_id) if not is_instructor: return "You are not an instructor!" course = Course.by_id(course_id) students = course.get_students() assignments = natsorted(course.get_submitted_assignments(), key=lambda r: r[0].name) grouped_assignments = defaultdict(list) for assig_pair in assignments: assignment, membership = assig_pair grouped_assignments[membership.assignment_group_id].append(assignment) assignment_groups = course.get_assignment_groups() submissions = { (s.assignment_id, s.user_id) :s for s in course.get_submissions()} return render_template('courses/submissions_grid.html', course_id=course_id, students=students, submissions=submissions, assignment_groups= assignment_groups, grouped_assignments= grouped_assignments, is_instructor=is_instructor)
def run(self, course_id, course_data_path, **kwargs): from models.models import Course, Assignment, AssignmentGroup, AssignmentGroupMembership exported_data = Course.export(int(course_id)) with open(course_data_path, 'w') as output_file: json.dump(exported_data, output_file, indent=2) pprint(exported_data)
def run(self, course_id, **kwargs): from models.models import Course Course.remove(int(course_id), True)
def run(self, owner_id, course_data_path, **kwargs): from models.models import Course, Assignment, AssignmentGroup, AssignmentGroupMembership with open(course_data_path, 'r') as input_file: imported_data = json.load(input_file) Course.import_json(imported_data, int(owner_id))
class CourseController(): def __init__(self): if 'student' not in session: return redirect(url_for('index')) self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response() def single_course(self, courseId): data = {} data['loggedIn'] = False data['course_lessons'] = [] data['similar_courses'] = [] data['loggedIn'] = True data['student'] = session['student'] course = self.newCourse.get_course_by_id(ObjectId(courseId)) if course: student_id = ObjectId(session['student']['id']) similar_courses = self.newCourse_interest.get_similar_courses(course['_id']) instructor = self.newInstructor.get_instructor_by_id(course['instructor_id']) courseLessons = self.newLesson.get_lesson_by_courseId(course['_id']) courseDuration = 0 for lesson in courseLessons: courseDuration = int(courseDuration) + int(lesson['duration']) data['course_lessons'].append(lesson) subscribed = self.newStudent_subscription.get_student_course_subscriptions(student_id, course['_id']) if subscribed: data['subscribed'] = 1 else: data['subscribed'] = 0 thisCourse = ''; data['course'] = course data['instructor'] = instructor data['course_duration'] = courseDuration data['similar_courses'] = similar_courses #return jsonify(len(similar_courses)) return render_template("course_single.html", data=data) else: return redirect(url_for('dashboard')) def course_lesson(self, course_title, lesson_title): data = {} data['QForm'] = QuestionForm() data['loggedIn'] = False data['loggedIn'] = True data['student'] = session['student'] data['course_lessons'] = [] data['lesson_questions'] = [] student_id = ObjectId(session['student']['id']) course = self.newCourse.get_course_by_title(course_title) fields = {"course_id":course['_id'], "title":lesson_title} lesson = self.newLesson.get_lesson(fields) subscribed = self.newStudent_subscription.get_student_course_subscriptions(student_id, lesson['course_id']) free_lessons = self.newLesson.get_free_lessons(lesson['course_id']) if ((subscribed) or (lesson['_id'] in free_lessons)): #course = self.newCourse.get_course_by_id(lesson['course_id']) similar_courses = self.newCourse_interest.get_similar_courses(course['_id']) instructor = self.newInstructor.get_instructor_by_id(course['instructor_id']) courseLessons = self.newLesson.get_lesson_by_courseId(course['_id']) lesson_questions = self.newStudent_question.get_lesson_questions(str(lesson['_id'])) if lesson_questions.count() > 0: for quest in lesson_questions: question = {} question['student'] = self.newStudent.get_student_by_id(quest['student_id'])['name'] question['date_asked'] = str(quest['date_asked']) question['quest'] = quest question['responses'] = self.newQuestion_response.get_question_responses(str(quest['_id'])) data['lesson_questions'].append(question) courseDuration = 0 n = 0 nxt = 0 prev = '' for courseLesson in courseLessons: n = n + 1; if nxt == 1: lesson['nxt'] = courseLesson['title'] nxt = 0 if courseLesson['title'] == lesson['title']: lesson['prev'] = prev nxt = 1 prev = courseLesson['title'] courseDuration = int(courseDuration) + int(courseLesson['duration']) data['course_lessons'].append(courseLesson) data['course'] = course data['lesson'] = lesson data['instructor'] = instructor data['course_duration'] = courseDuration data['similar_courses'] = similar_courses #return jsonify(len(similar_courses)) return render_template("course_lesson.html", data=data) else: return redirect(url_for('dashboard')) def purchase_course(self, courseId): #session['test'] = 'this' data = {} data['loggedIn'] = False data['course_lessons'] = [] #session['reverse_cart'] = [] if 'cart' in session: data['cart'] = session['cart'] else: data['cart'] = [] if 'reverse_cart' in session: data['reverse_cart'] = session['reverse_cart'] if 'cart_total' in session: data['sub_total'] = session['cart_total'] else: data['sub_total'] = 0 data['loggedIn'] = True data['student'] = session['student'] course = self.newCourse.get_course_by_id(ObjectId(courseId)) #return jsonify(title) instructor = self.newInstructor.get_instructor_by_id(course['instructor_id']) courseLessons = self.newLesson.get_lesson_by_courseId(course['_id']) courseDuration = 0 for lesson in courseLessons: courseDuration = int(courseDuration) + int(lesson['duration']) data['course_lessons'].append(lesson) #cart = session['cart'] #count = len(cart) #while count > 0: # session['reverse_cart'].append(cart.pop()) # session.modified = True # count = count - 1 data['course'] = course data['instructor'] = instructor data['course_duration'] = courseDuration return render_template("purchase_course.html", data=data) def ask_question(self): form = QuestionForm() student_id = ObjectId(session['student']['id']) if form.validate() == False: errors = '' if form.question.errors: for error in form.question.errors: errors += ' '+error return json.dumps({'status':'ERROR','message':errors}); else: question = request.form['question'] lesson_id = request.form['lesson_id'] course_id = request.form['course_id'] result = self.newStudent_question.add(lesson_id, course_id, student_id, question) if(result == 'OK'): return json.dumps({'status':'OK'}); if(result == 'ERROR'): return json.dumps({'status':'ERROR'}); def course_questions(self): return render_template("course_questions.html")
def rename_course(course_id): new_name = request.values.get('name', "Untitled Course") Course.rename(course_id, new_name) return jsonify(success=True)
class CourseController(): def __init__(self): if 'instructor' in session: self.loggedIn = True else: return redirect(url_for('instructor_login')) self.newStudent_interest = Student_interest() self.newCourse_interest = Course_interest() self.newInterest = Interest() self.newCourse = Course() self.newStudent_subscription = Student_subscription() self.newStudent = Student() self.newInstructor = Instructor() self.newLesson = Lesson() self.newStudent_question = Student_question() self.newQuestion_response = Question_response() self.uploadFolder = 'static/images/courses_cover_photos' self.allowedExtensions = set(['png', 'jpg', 'jpeg', 'gif', 'psd']) def course_data(self, course_id): data = {} data['course_lessons'] = [] data['similar_courses'] = [] data['loggedIn'] = True data['courses'] = [] data['instructor'] = self.newInstructor.get_instructor_by_name(session['instructor']['name']) fields = {"instructor_id":data['instructor']['_id']} courses = self.newCourse.get_courses(fields) if courses: for course in courses: course_subscription = self.newStudent_subscription.get_course_subscriptions(course['_id']) course['subscribed'] = course_subscription.count() questions = self.newStudent_question.get_course_questions(str(course['_id'])) course['questions'] = questions.count() data['courses'].append(course) course = self.newCourse.get_course_by_id(ObjectId(course_id)) data['course'] = course if course: similar_courses = self.newCourse_interest.get_similar_courses(course['_id']) instructor = self.newInstructor.get_instructor_by_id(course['instructor_id']) courseLessons = self.newLesson.get_lesson_by_courseId(course['_id']) courseDuration = 0 for lesson in courseLessons: courseDuration = int(courseDuration) + int(lesson['duration']) data['course_lessons'].append(lesson) thisCourse = ''; data['instructor'] = instructor data['course_duration'] = courseDuration data['similar_courses'] = similar_courses return data def course(self, course_id): if self.loggedIn != True: return redirect(url_for('instructor_login')) data = self.course_data(course_id) data['new_course_form'] = CourseForm() data['new_course_form'].instructor_id.data = data['instructor']['_id'] data['new_lesson_form'] = LessonForm() data['new_lesson_form'].course_id.data = course_id #return jsonify(len(similar_courses)) if data['course']: return render_template("instructor/course.html", data=data) else: return redirect(url_for('index')) def create(self): form = CourseForm() if request.method == 'POST': instructor_id = form.instructor_id.data instructor_id = ObjectId(instructor_id) if form.validate() == False: return redirect(url_for('new_course')) else: if 'cover_photo' not in request.files: flash('No Cover Photo') return redirect(url_for('new_course')) photo = request.files['cover_photo'] if photo.filename == '': flash('No Photo Selected') return redirect(url_for('new_course')) if photo and self.allowed_file(photo.filename): filename = secure_filename(photo.filename) photo.save(os.path.join(self.uploadFolder, filename)) id = self.newCourse.add(form.title.data, filename, form.description.data, instructor_id) return redirect(url_for('instructor_courses')) return redirect(url_for('instructor_dashboard')) def edit(self, course_id): form = EditCourseForm() data = {} course = self.newCourse.get_course_by_id(ObjectId(course_id)) data['edit_course_form'] = form data['edit_course_form'].course_id.data = course_id data['edit_course_form'].title.data = course['title'] data['edit_course_form'].cover_photo.data = course['cover_photo'] data['edit_course_form'].description.data = course['description'] data['course'] = course data['instructor'] = self.newInstructor.get_instructor_by_name(session['instructor']['name']) return render_template('instructor/edit_course.html', data=data) def update(self): form = EditCourseForm() data = {} if request.method == 'POST': courseid = form.course_id.data course_id = ObjectId(courseid) course = self.newCourse.get_course_by_id(course_id) if form.validate() == True: if 'cover_photo' not in request.files: flash('No Cover Photo') return redirect(url_for('instructor_edit_course', courseId=course_id)) photo = request.files['cover_photo'] if photo.filename == '': filename = '' if photo and self.allowed_file(photo.filename): filename = secure_filename(photo.filename) #Add new photo photo.save(os.path.join(self.uploadFolder, filename)) #Remove old photo if os.path.isfile(self.uploadFolder+course['cover_photo']): os.remove(os.path.join(self.uploadFolder, course['cover_photo'])) result = self.newCourse.update(course_id, form.title.data, filename, form.description.data) if result == 'OK': flash('1') else: flash('0') #return jsonify(str(result)) return redirect(url_for('instructor_edit_course', courseId=course_id)) else: return redirect(url_for('instructor_edit_course', courseId=course_id)) return redirect(url_for('instructor_dashboard')) def lesson(self, lesson_id): data = {} data['QForm'] = QuestionForm() data['course_lessons'] = [] data['lesson_questions'] = [] lesson = self.newLesson.get_lesson_by_id(ObjectId(lesson_id)) course = self.newCourse.get_course_by_id(lesson['course_id']) if (lesson): #course = self.newCourse.get_course_by_id(lesson['course_id']) similar_courses = self.newCourse_interest.get_similar_courses(course['_id']) instructor = self.newInstructor.get_instructor_by_id(course['instructor_id']) courseLessons = self.newLesson.get_lesson_by_courseId(course['_id']) lesson_questions = self.newStudent_question.get_lesson_questions(str(lesson['_id'])) if lesson_questions.count() > 0: for quest in lesson_questions: question = {} question['student'] = self.newStudent.get_student_by_id(quest['student_id'])['name'] question['date_asked'] = str(quest['date_asked']) question['quest'] = quest question['responses'] = self.newQuestion_response.get_question_responses(str(quest['_id'])) data['lesson_questions'].append(question) courseDuration = 0 n = 0 nxt = 0 prev = '' for courseLesson in courseLessons: n = n + 1; if nxt == 1: lesson['nxt'] = courseLesson['title'] nxt = 0 if courseLesson['title'] == lesson['title']: lesson['prev'] = prev nxt = 1 prev = courseLesson['title'] courseDuration = int(courseDuration) + int(courseLesson['duration']) data['course_lessons'].append(courseLesson) data['course'] = course data['lesson'] = lesson data['instructor'] = instructor data['course_duration'] = courseDuration data['similar_courses'] = similar_courses #return jsonify(len(similar_courses)) return render_template("instructor/lesson.html", data=data) else: return redirect(url_for('instructor_dashboard')) def new_lesson(self): form = LessonForm() if request.method == 'POST': course_id = form.course_id.data course_id = ObjectId(course_id) if form.validate() == False: data = self.course_data(course_id) data['new_lesson_form'] = form data['new'] = 1 return render_template('instructor/course.html', data=data) else: #return jsonify(course_id) #course_id = '5a5e2612a8af96b319f84dce' #data = self.course_data(str(course_id)) #duration = request.form['duration'] id = self.newLesson.add(form.title.data, form.video_url.data, form.description.data, form.duration.data, course_id) return redirect(url_for('instructor_course', courseId=course_id)) return redirect(url_for('instructor_dashboard')) def edit_lesson(self, lesson_id): form = LessonForm() data = {} lesson = self.newLesson.get_lesson_by_id(ObjectId(lesson_id)) course = self.newCourse.get_course_by_id(lesson['course_id']) data['edit_lesson_form'] = form data['edit_lesson_form'].lesson_id.data = lesson_id data['edit_lesson_form'].title.data = lesson['title'] data['edit_lesson_form'].video_url.data = lesson['video_url'] data['edit_lesson_form'].description.data = lesson['description'] data['edit_lesson_form'].duration.data = lesson['duration'] data['lesson'] = lesson data['course'] = course data['instructor'] = self.newInstructor.get_instructor_by_name(session['instructor']['name']) return render_template('instructor/edit_lesson.html', data=data) def update_lesson(self): form = LessonForm() data = {} if request.method == 'POST': lesson_id = form.lesson_id.data lesson_id = ObjectId(lesson_id) lesson = self.newLesson.get_lesson_by_id(lesson_id) if form.validate() == True: result = self.newLesson.update(lesson_id, form.title.data, form.video_url.data, form.description.data, form.duration.data) if result == 'OK': flash('1') else: flash('0') #return jsonify(str(result)) return redirect(url_for('instructor_edit_lesson', lessonId=lesson_id)) else: return redirect(url_for('instructor_edit_lesson', lessonId=lesson_id)) return redirect(url_for('instructor_dashboard')) def course_questions(self, title): data = {} data['questions'] = [] course = self.newCourse.get_course_by_title(title) questions = self.newStudent_question.get_course_questions(str(course['_id'])) if questions: for question in questions: question['student'] = self.newStudent.get_student_by_id(question['student_id']) question['lesson'] = self.newLesson.get_lesson_by_id(ObjectId(question['lesson_id'])) data['questions'].append(question) data['course'] = course return render_template("instructor/course_questions.html", data=data) return redirect(url_for('instructor_dashboard')) def allowed_file(self, filename): return '.' in filename and \ filename.rsplit('.', 1)[1].lower() in self.allowedExtensions
def remove_course(course_id): Course.remove(course_id) return jsonify(success=True)
def run(self, user_data_file, **kwargs): from models.models import Role, User, Course, Assignment, CourseAssignment, AssignmentGroup, AssignmentGroupMembership print("Adding Admin") admin = User(first_name='Cory', last_name='Bart', password=encrypt_password('password'), confirmed_at=datetime.datetime.now(), active=True, email='*****@*****.**', gender='Male') db.session.add(admin) db.session.flush() db.session.add(Role(name='instructor', user_id=admin.id)) db.session.add(Role(name='admin', user_id=admin.id)) print("Adding some students for color") for student in ('Dan Tilden', 'Anamary Leal', 'Ellie Cayford'): first, last = student.split() email = '{}{}@vt.edu'.format(first[0].lower(), last.lower()) user = User(first_name=first, last_name=last, email=email) db.session.add(user) print("Adding default course") default_course = Course(name="Computational Thinking", owner_id=admin.id, service="native") db.session.add(default_course) db.session.flush() print("Adding public course") public_course = Course(name="Public Course", owner_id=admin.id, service="native", visibility='public') db.session.add(public_course) db.session.flush() db.session.add( Role(name='instructor', course_id=public_course.id, user_id=admin.id)) print("Adding local Canvas course") canvas_course = Course( name="Computational Thinking - Dev", owner_id=admin.id, service='canvas', visibility='private', external_id='cbdd860576c6c08ccb998b93009305c318bd269b') db.session.add(canvas_course) db.session.flush() print("Adding CS1 course") cs1_course = Course(name="CS 1", owner_id=user.id, service='canvas', visibility='private') db.session.add(cs1_course) db.session.flush() print("Adding some assignments") assignment1 = Assignment(name="Assignment #1", body="a=b+c", course_id=default_course.id, owner_id=admin.id) db.session.add(assignment1) assignment2 = Assignment(name="Assignment #2", body="Figure it out!", course_id=default_course.id, owner_id=admin.id) db.session.add(assignment2) assignment3 = Assignment(name="Assignment #3", body="Clue", course_id=default_course.id, owner_id=admin.id) db.session.add(assignment3) ca1 = CourseAssignment(course_id=public_course.id, assignment_id=assignment1.id) db.session.add(ca1) ca2 = CourseAssignment(course_id=public_course.id, assignment_id=assignment2.id) db.session.add(ca2) ag1 = AssignmentGroup(name="Day 1 - Decision", course_id=default_course.id) db.session.add(ag1) ag2 = AssignmentGroup(name="Day 2 - Iteration", course_id=default_course.id) db.session.add(ag2) db.session.commit() db.session.add( AssignmentGroupMembership(assignment_group_id=ag1.id, assignment_id=assignment1.id)) db.session.add( AssignmentGroupMembership(assignment_group_id=ag1.id, assignment_id=assignment2.id)) db.session.add( AssignmentGroupMembership(assignment_group_id=ag2.id, assignment_id=assignment3.id)) db.session.commit() print("Complete")