def adminCourseAdd(): if current_user.admin: form = CourseForm() if form.validate_on_submit(): newCourse = models.Course.query.filter_by( title=form.title.data).first() listOfPreRequisiteCourses = ', '.join( request.form.getlist('preRequisite')) if newCourse is None: newCourse = models.Course( title=form.title.data, description=form.description.data, capacity=form.capacity.data, duration=form.duration.data, preRequisiteCourses=listOfPreRequisiteCourses, bookingRate=0, enabled=True) db.session.add(newCourse) db.session.commit() flash('New course created!') return redirect(url_for('adminCourseAdd')) elif newCourse.enabled == False: newCourse.enabled = True newCourse.description = form.description.data newCourse.capacity = form.capacity.data newCourse.duration = form.duration.data newCourse.preRequisiteCourses = listOfPreRequisiteCourses db.session.commit() else: flash(form.title.data + " already exists!") return render_template('adminCourseAdd.html', title='Course management', courses=models.Course.query.filter_by(enabled=True), form=form)
def create_course(db_session: Session, course: courses.CourseCreate, user: user.User): db_course = models.Course(**course.dict(), owner_id=user.user_id) db_session.add(db_course) db_session.commit() db_session.refresh(db_course) return db_course
def spid_it(session): for i in range(1, 10): response = session.get('https://www.shiyanlou.com/courses/?category=all&course_type=all&fee=free&tag=all&page=' + str(i)) names = re.finditer(r'<div class="course-name">(.+?)</div>', response.text) descs = re.finditer(r'<div class="course-desc">(.+?)</div>', response.text) images = re.finditer(r'<img alt="(.+?)" src="(.+?)">', response.text) image_mapping = dict((image.group(1), image.group(2)) for image in images) courses_id = re.finditer(r'<a class="course-box" href="/courses/(\d+)">', response.text) counter = 0 for name, desc, course_id in zip(names, descs, courses_id): flag = False response = session.get('https://www.shiyanlou.com/courses/{}'.format(course_id.group(1))) label = re.search(r'data-course-tag="(.+?)"', response.text) if not label: continue label = label.group(1).split(',')[0] labs_id = re.finditer(r'<span class="lab-id" data-lab-id="(\d+)">', response.text) labs_name = re.finditer(r'<div class="lab-item-title" title=".+?">(.+?)</div>', response.text) for lab_id, lab_name in zip(labs_id, labs_name): response = session.get('https://www.shiyanlou.com/courses/{}/labs/{}/document'.format(course_id.group(1), lab_id.group(1)), headers={'Referer': response.url}) doc_uri = re.search(r'data-courses-doc="(.+?)"', response.text) if not doc_uri: continue doc_json = session.get('https://www.shiyanlou.com' + doc_uri.group(1), headers={'Referer': response.url}).json() if not doc_json['document']: continue if not flag: try: l = models.Label.objects.get(name=label) except ObjectDoesNotExist: l = models.Label(name=label) l.save() file_name = str(uuid.uuid4().int % 1000000000) + '.jpg' with open('statics/website/img/course/' + file_name, 'wb') as fd: fd.write(requests.get(image_mapping[name.group(1)]).content) course = models.Course( name=name.group(1), image=file_name, description=desc.group(1), label=l, ) course.save() flag = True course = models.Course.objects.get(name=name.group(1)) file_name = str(uuid.uuid4().int % 1000000000) + '.md' with open('statics/website/doc/' + file_name, 'w', encoding='utf-8') as fd: fd.write(doc_json['document']) lab = models.Lab( name=lab_name.group(1), content=file_name, course=course ) lab.save() counter += 1 print(counter) time.sleep(2.5)
def add_courses(): request_data = request.get_json() course_store.delete() new_courses = [] for course_row in request_data: new_course = models.Course(id=course_row['id'], category=course_row['category'], course=course_row['course']) course_store.add(new_course) new_courses.append(new_course.as_dict()) result = jsonify(new_courses) return result
def createCourses(): titles = ['Software Engineering', 'Algorithms', 'Networks', 'Artificial Intellingence', 'Numerical Computation'] for i in range(0,5): course = models.Course(title=titles[i], description='Lorem ipsum dolor sit amet, consectetur adipiscing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam, quis nostrud exercitation ullamco laboris nisi ut aliquip ex ea commodo consequat. Duis aute irure dolor in reprehenderit in voluptate velit esse cillum dolore eu fugiat nulla pariatur. Excepteur sint occaecat cupidatat non proident, sunt in culpa qui officia deserunt mollit anim id est laborum.', capacity=5, duration=5, enabled=True) db.session.add(course) db.session.commit() softEng = models.Course.query.get(1) softEng.capacity = 2 algorithms = models.Course.query.get(2) algorithms.preRequisiteCourses = 'Networks, Artificial Intellingence' db.session.commit()
def create_course(): # Only allow an admin to create a course if current_user.is_authenticated: if current_user.student_email == '*****@*****.**': user = current_user course_form = CourseForm() #when the create button is clicked if course_form.validate_on_submit(): all_courses = models.Course.query.all() if all_courses: for course in all_courses: #check if the course already exists if course_form.course_title.data == course.course_title: flash("Course already exists!") logger.warning("{} already exists".format(course)) return redirect('/create_course') else: #add the course to db course = models.Course( course_form.course_title.data, course_form.course_degree_bach.data, course_form.course_degree_mast.data, course_form.course_1y_credits.data, course_form.course_2y_credits.data, course_form.course_3y_credits.data, course_form.course_4y_credits.data) db.session.add(course) db.session.commit() flash("Course added successfully!") logger.info( "{} added to the database".format(course)) #change to display_courses return redirect('/display_courses') return render_template('/create_course.html', user=user, title='Create Course', form=course_form) return redirect('/')
def teaPostCourse(request): courseId = request.POST.get('courseId') courseName = request.POST.get('courseName') teacherId = request.POST.get('teacherId') # 检验courseId是否存在 存在返回0 不存在则插入成功返回1 res0 = models.Course.objects.filter(course_id=courseId) if res0.exists(): data = {"RESULT": 0} return HttpResponse(json.dumps(data, ensure_ascii=False), content_type="application/json,charset=utf-8") else: opreateAdd = models.Course(teacher_id=teacherId, course_id=courseId, course_name=courseName) opreateAdd.save() print("over!") data = {"RESULT": 1} return HttpResponse(json.dumps(data, ensure_ascii=False), content_type="application/json,charset=utf-8") data = {"RESULT": -1} return HttpResponse(json.dumps(data, ensure_ascii=False), content_type="application/json,charset=utf-8")
description='Address many university level ' 'technology issues') committee_member_1 = models.CommitteeMembers(role='Chair', faculty=faculty, committee=committee_1) committee_member_2 = models.CommitteeMembers(faculty=faculty, committee=committee_2) dept = models.Department(name='Computing Sciences') course_1 = models.Course(title='Software Engineering', credits=3, level='UG', description='See website', prerequisites='None', term=term_fall, department=dept) course_time_1 = models.CourseTimes(days='MWF', start_time=datetime.datetime( 2014, 9, 1, 11, 30), end_time=datetime.datetime(2014, 9, 1, 14)) course_time_2 = models.CourseTimes(days='TTR', start_time=datetime.datetime( 2014, 9, 1, 11, 30), end_time=datetime.datetime(2014, 9, 1, 14)) course_sect_1 = models.CourseSection(course_time_id='1',
courses = [ {"name": "[B17] Software Project", "faculty_id": 1}, {"name": "[B17] Probability and Statistics", "faculty_id": 1}, {"name": "[B17] Networks", "faculty_id": 1} ] print("Adding Main Professor") u = models.User(name="Prof", surname="Fessor", email="prof@mail", is_faculty=True) u.set_password(input("Enter Main Prof password: "******"Main Prof Added") print("Adding session types") for session_type in session_types: print("Adding {}...".format(session_type["name"])) s = models.SessionType(**session_type) db.session.add(s) db.session.commit() print("Added") print("Adding sample courses") for course in courses: print("Adding {}...".format(course["name"])) c = models.Course(**course) db.session.add(c) db.session.commit() print("Added")
def make_seed_course(creator): return models.Course(display_name="CS 61A", institution="UC Soumya", offering=SEED_OFFERING, instructor=[creator.key])
from app import models, db, stores dummy_courses = [ models.Course(id=1, category=1, course='Aqua Dive'), models.Course(id=2, category=2, course='First Aids'), models.Course(id=3, category=2, course='Walid'), ] dummy_instructor = [ models.Instructor(id=1, instructor='renzo'), models.Instructor(id=2, instructor='walid'), ] dummy_categories = [ models.Category(id=1, category='prof'), models.Category(id=2, category='aqua'), ] dummy_places = [ models.Place(id=1, place='f place'), models.Place(id=2, place='s place') ] dummy_points = [ models.Point(id=1, point='f point'), models.Point(id=2, point='s point'), ] def seed_courses(course_store, instructor_store, category_store, place_store, point_store):
def seed(): # db.drop_all() level1 = models.Level(id=1) level1.save() level2 = models.Level(id=2) level2.save() level3 = models.Level(id=3) level3.save() level4 = models.Level(id=4) level4.save() sessiona = models.Session(id=1, name="2011/2012", current=False) sessiona.save() sessionb = models.Session(id=2, name="2012/2013", current=False) sessionb.save() sessionc = models.Session(id=3, name="2013/2014", current=False) sessionc.save() sessiond = models.Session(id=4, name="2014/2015", current=False) sessiond.save() sessione = models.Session(id=5, name="2015/2016", current=False) sessione.save() sessiona = models.Session(id=6, name="2016/2017", current=True) sessiona.save() usera = models.User(id=178646, email="*****@*****.**", password="******") usera.save() userb = models.User(id=186674, email="*****@*****.**", password="******") userb.save() userc = models.User(id=255001, email="*****@*****.**", password="******") userc.save() userd = models.User(id=255002, email="*****@*****.**", password="******") userd.save() facultya = models.Faculty(name="Social Science") facultya.save() facultyb = models.Faculty(name="Science") facultyb.save() departmenta = models.Department(code="CSC", name="Customer Science", fac_name="Science") departmenta.save() departmentb = models.Department(code="GEO", name="Geophraphy", fac_name="Social Science") departmentb.save() studenta = models.Student(firstname="Mofope", lastname="Ojosh", department_code="CSC", student_id=178646, level=4, phone_no="08116631381", sex="F") studenta.save() studentb = models.Student(firstname="Omolola", lastname="Okunubi", department_code="GEO", student_id=186674, level=4, phone_no="08124456789", sex="F") studentb.save() staffa = models.Staff(firstname="Francis", lastname="Akomolafe", staff_id=255001, phone_no="0812345679", sex="M") staffa.save() staffb = models.Staff(firstname="Tolu", lastname="Osa", staff_id=255002, phone_no="0812345678", sex="M") staffb.save() coursea = models.Course(code=101, title="Introduction", unit=4, level=1, department_code="CSC") coursea.save() coursef = models.Course(code=401, title="Nigeria", unit=4, level=4, department_code="GEO") coursef.save() courseb = models.Course(code=401, title="Systems Programming", unit=4, level=4, department_code="CSC") courseb.save() coursec = models.Course(code=433, title="Database Systems", unit=3, level=4, department_code="CSC") courseb.save() coursed = models.Course(code=402, title="Operating Systems", unit=3, level=4, department_code="CSC") coursed.save() coursee = models.Course(code=422, title="Computer Organizations", unit=3, level=4, department_code="CSC") coursee.save() courseforma = models.Courseform(student_id=178646, level=4, session_id=6, total_units=4) courseforma.save() courseformb = models.Courseform(student_id=186674, level=4, session_id=6, total_units=4) courseformb.save() offeringa = models.Offering(courseform_id=1, course_id=3) offeringa.save() offeringb = models.Offering(courseform_id=2, course_id=2) offeringb.save() advisera = models.Adviser(staff_id=255001, department_code="CSC", level=4) advisera.save() adviserb = models.Adviser(staff_id=255002, department_code="GEO", level=1) adviserb.save()
def make_fake_course(creator): return models.Course(institution="UC Soumya", instructor=[creator.key], offering="cal/cs61a/fa14", active=True)
def setUp(self): #pylint: disable=invalid-name super(BaseUnitTest, self).setUp() self.accounts = self.get_accounts() for user in self.accounts.values(): user.put() self.courses = { "first": models.Course(institution="UC Awesome a", instructor=[self.accounts['admin'].key]), "second": models.Course(institution="UC Awesome b", instructor=[self.accounts['admin'].key]), } for course in self.courses.values(): course.put() self.enroll("student0", "first", STUDENT_ROLE) self.enroll("student1", "first", STUDENT_ROLE) self.enroll("student2", "second", STUDENT_ROLE) self.enroll("staff", "first", STAFF_ROLE) self.assignments = { "first": models.Assignment(name="first", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="first display", templates="{}", max_group_size=3, due_date=datetime.datetime.now()), "second": models.Assignment(name="second", points=3, creator=self.accounts["admin"].key, course=self.courses['second'].key, display_name="second display", templates="{}", max_group_size=3, due_date=datetime.datetime.now()), "empty": models.Assignment(name="empty", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="second display", templates="{}", max_group_size=4, due_date=datetime.datetime.now()), } for assign in self.assignments.values(): assign.put() self.backups = { "first": models.Backup( submitter=self.accounts["student0"].key, assignment=self.assignments["first"].key, ), "second": models.Backup( submitter=self.accounts["student1"].key, assignment=self.assignments["first"].key, ), "third": models.Backup( submitter=self.accounts["student2"].key, assignment=self.assignments["second"].key, ), } for backup in self.backups.values(): backup.put() self.submissions = { "first": models.Submission(backup=self.backups["first"].key), "second": models.Submission(backup=self.backups["second"].key), "third": models.Submission(backup=self.backups["third"].key), } for submission in self.submissions.values(): submission.put() self.groups = { 'group1': models.Group(member=[ self.accounts['student0'].key, self.accounts['student1'].key ], assignment=self.assignments['first'].key) } self.groups['group1'].put() group_backup = models.Backup( submitter=self.accounts['student0'].key, assignment=self.assignments['first'].key, ) group_backup.put() self.backups['group'] = group_backup group_submission = models.Submission(backup=group_backup.key) group_submission.put() self.submissions['group'] = group_submission self.queues = { "first": models.Queue( assignment=self.assignments["first"].key, assigned_staff=[self.accounts["staff"].key], ), } for queue in self.queues.values(): queue.put() self.diffs = {"first": models.Diff()} for diff in self.diffs.values(): diff.put() self.comments = { "first": models.Comment(author=self.accounts['student0'].key, diff=self.diffs["first"].key, message="First comment"), } for comment in self.comments.values(): comment.put() self.user = None
# 添加课程信息 courses = [ (u'C语言', u'11', u'张翔'), (u'English', u'11', u'wang'), (u'Language C', u'22', u'wang'), (u'RFID', u'33', u'wang'), (u'软件工程', u'33', u'费蓉') ] for course in courses: tname = course[2] teacher = models.Teacher.query.filter_by(tname=tname).first() if teacher == None: print ('添加课程失败:%r' % course[0]) print ('不存在此老师:%r' % tname) continue c = models.Course(cname=course[0], ctime=course[1], tid=teacher.tid) db.session.add(c) db.session.commit() # 添加学生信息 students = [ (u'王兴耀', u'ww141'), (u'杨乔英', u'jsj143'), (u'刘慧', u'ww141'), (u'王璞劼', u'ww141'), (u'王新宇', u'jsj143') ] for student in students: s = models.Student(sname=student[0], sclass=student[1]) db.session.add(s)
db.session.add_all([user2, user3, user4, user5]) db.session.commit() #Add courses course1 = models.Course(course_name="Anthropology and the Arab World"\ , course_description= "How have anthropologists encountered,\ written about, and produced the 'Arab world' over the past century?\ Beginning with early Western travelers' imaginaries of Arabia and\ ending with an ethnography of Egyptian dreamscapes, this course\ provides an introduction to the anthropological project and to the\ everyday realities of people living in the region. Through\ ethnography, literature, film, and field trips, we explore such topics\ as colonialism, nation building and development, family, gender and\ piety, media, art and globalization, labor migration, diaspora, and\ pilgrimage." ) course2 = models.Course(course_name="What is Music?", course_description= "This course analyzes what we understand as\ 'music.' Drawing on music of different styles from all over the world,\ we will explore what constitutes musical meaning, how it is produced,\ and how music expresses feelings. Taking advantage of the\ multicultural nature of NYUAD, we will explore the cultural and\ universal mechanisms at play when we listen and understand music. A\ lab portion of the class guides students through basic musical\ elements such as notation systems, scales, and simple compositional\
def generate_demo_data(session: Session): """Generates demonstration data from models""" # check that the db is empty if session.query(models.User).first(): log.info("Data already exists, skipping data generation.") return log.info("Generating demo data.") user = models.User( name="Tom Hill", email="*****@*****.**", password_hash=security.get_password_hash("password"), stripe_customer_id=stripe.Customer.create()["id"], ) session.add(user) session.commit() session.refresh(user) discrete_maths = models.Course( name="Introduction to Reinforcement Learning", code="RL479", description="description", status="completing", due="2021-12-12", syllabus=[ { "id": 1, "name": "Introduction to Reinforcement Learning", "completed": False, }, { "id": 2, "name": "Exploration and Control", "completed": False }, { "id": 3, "name": "MDPs and Dynamic Programming", "completed": False }, { "id": 4, "name": "Fundementals of Dynamic Programming Algorithms", "completed": False, }, { "id": 5, "name": "Model-Free Prediction", "completed": False }, { "id": 6, "name": "Model-Free Control", "completed": False }, { "id": 7, "name": "Function Approximation", "completed": False }, { "id": 8, "name": "Planning & Models", "completed": False }, { "id": 9, "name": "Policy-Gradient and Actor-Critic Methods", "completed": False, }, { "id": 10, "name": "Approximate Dynamic Programming", "completed": False }, { "id": 11, "name": "Multi-Step & Off Policy", "completed": False }, { "id": 12, "name": "Deep RL 1", "completed": False }, { "id": 13, "name": "Deep RL 2", "completed": False }, ], cover={"color": "#8bbeb2"}, user_id=user.id, ) maths = models.Topic(name="mathematics") algebra = models.Topic(name="algebra") session.add_all([discrete_maths, maths, algebra]) session.commit() session.refresh(maths) session.refresh(algebra) # could try session.expire_all() instead? linear_algebra = models.Resource( name="Interactive Linear Algebra", url="http://textbooks.math.gatech.edu/ila/index.html", user_id=user.id, topics=[maths, algebra], ) big_exam = models.Assignment( name="Big Exam", description="Examination of:Set theory, Proof, Graph Theory", due="2021-12-12", course_id=discrete_maths.id, status="in_progress", weight=50, ) session.add_all([linear_algebra, big_exam]) session.commit()
def setUp(self): super(FinalSubmissionTest, self).setUp() self.courses = { "first": models.Course(institution="UC Awesome", display_name="First Course", instructor=[self.accounts['admin'].key]), "second": models.Course(institution="UC Awesome", display_name="Second Course", instructor=[self.accounts['admin'].key]), } for course in self.courses.values(): course.put() for student in ["student0", "student1", "student2"]: models.Participant.add_role(self.accounts[student], self.courses['first'], constants.STUDENT_ROLE) self.assignments = { "first": models.Assignment(name="first", points=3, creator=self.accounts["admin"].key, course=self.courses['first'].key, display_name="first display", templates="{}", max_group_size=3, due_date=NOW + datetime.timedelta(days=1)), } for assign in self.assignments.values(): assign.put() self.assign = self.assignments["first"] self.backups = { "first": models.Backup( submitter=self.accounts["student0"].key, assignment=self.assignments["first"].key, messages=[ models.Message(kind='file_contents', contents={"trends.py": ""}) ], ), "second": models.Backup( submitter=self.accounts["student1"].key, assignment=self.assignments["first"].key, messages=[ models.Message(kind='file_contents', contents={"trends.py": ""}) ], ), "third": models.Backup( submitter=self.accounts["student2"].key, assignment=self.assignments["first"].key, messages=[ models.Message(kind='file_contents', contents={"trends.py": ""}) ], ), } for backup in self.backups.values(): backup.put()
values = get_values(row) first.append(values[0]) try: last.append(values[1]) except: i += 1 continue i += 1 course_list = first + last dict[sheet] = course_list return dict dict = get_math_offerings(xl_workbook, sheet_names) df = pd.DataFrame.from_dict(dict, orient='index').transpose() for sheet_name in df: institution_id = models.Institution.query.filter_by( sheet_name=sheet_name).first().id for course in df[sheet_name]: if course: rubric, number = course.split(' ')[:2] name = ' '.join(course.split(' ')[2:]) course = models.Course(name=name, rubric=rubric, number=number, institution_id=institution_id) db.session.add(course) db.session.commit()