def test_delete_course(self): headers = {"authorization": "Bearer " + self.administratorToken} course = Courses(name="data visulization", courseTimePeriod="morning") course.insert() id = course.id response = self.client().delete('/courses/{}'.format(id), headers=headers) data = json.loads(response.data) self.assertEqual(response.status_code, 200) self.assertEqual(data['success'], True)
def add(request): if request.method == 'POST': course_name = request.POST['name'] description_post = request.POST['description'] if course_name == "" or description_post == "": return redirect('/') c = Courses(name = course_name) c.save() d = Descriptions(description = description_post, course = c) d.save() return redirect('/')
def insertData(request): #after resetting the database, this function will repopulate the tables with data d= database() teachers = d.getDatabase() for prof in teachers.keys(): insertProf = Professors(name = prof) insertProf.save() for clas in teachers[prof]: insertclass = Courses(professor = insertProf , title = clas[0], days = clas[1], time = clas[2], location = clas[3], cid = clas[4]) insertclass.save() return redirect('/') #go to the home page
def add(request): if request.method == 'POST': course_name = request.POST['name'] description_post = request.POST['description'] if course_name == "" or description_post == "": return redirect('/') c = Courses(name=course_name) c.save() d = Descriptions(description=description_post, course=c) d.save() return redirect(reverse('main'))
def course(UKPRN, KISCOURSEID): institution = Institutions().GetByPRN(UKPRN) course = Courses().GetSingleByKIS(KISCOURSEID) related_courses=Courses().GetRelatedBySubject(KISCOURSEID) if course == None: abort(404) return render_template('course.html', course=course, institution=institution, related_courses=related_courses )
def institution(UKPRN): inst = Institutions().GetByPRN(UKPRN) if inst == None: #fail gracefully if the institution is not found abort(404) logo = get_logo(inst['PROVIDER_NAME']) #logo = "https://via.placeholder.com/1200x1200.png?text=InstitutionLogo" #in case you exceed the limit wiki = get_wiki(inst['PROVIDER_NAME']) courses = Courses() top_courses = courses.GetTopPerInstitution(UKPRN) all_courses = courses.GetByInstitution(UKPRN) return render_template('institution.html', inst=inst, top_courses=top_courses, logo=logo, wiki=wiki, all_courses=all_courses)
def day_time_selection(): if request.method == "POST": final_selected = request.form.getlist("selected_course") session_user = session.get("user_id") for item in final_selected: new_record = SelectedCourseInfo.create(faculty_id=session_user, course_id=item) try: with db.atomic(): new_record.save() print(new_record) except Exception as e: flash("Something went wrong.") return redirect(url_for("day_time_selection")) flash("Your selected course has been sent to Moderator for review") return redirect(url_for("faculty_selection")) if request.method == "GET": selected_courses = [] for item in request.args.getlist("selected_courses"): selected_courses.append(Courses.get(id=item)) selected_term = Semester.get(id=request.args['selected_term']) return render_template( "select_days_and_time.html", selected_term=selected_term, selected_courses=selected_courses )
def add_Courses(payload): name = request.get_json()['name'] description = request.get_json()['description'] image_link = 'https://www.freeiconspng.com/thumbs/'\ + 'book-icon/book-icon-black-good-galleries--24.jpg' # request.get_json()['image_link'] duration = request.get_json()['duration'] try: course = Courses(name=name, description=description, image_link=image_link, duration=duration) course.insert() return jsonify({"success": True, "Courses": course.format()}) except BaseException: abort(422)
def faculty_selection(): if request.method == "POST": form_term = request.form.get("term_id") form_courses = request.form.getlist("course_ids") return redirect(url_for("day_time_selection", selected_term=form_term, selected_courses=form_courses)) courses = Courses.select() semester = Semester.select() return render_template("selection.html", courses=courses, semester=semester)
def createCourse(): if request.method == 'GET': academicyears = Academicyears.query.all() return render_template('admin/course/create.html', academicyears=academicyears) elif request.method == 'POST': #get and validate input params course_id = request.form['id'] course_name = request.form['name'] course_cfu = request.form['cfu'] course_ssd = request.form['ssd'] course_year = request.form['year'] course_semester = request.form['semester'] course_url = request.form['url'] course_ac = request.form['academicyear'] course = Courses(id=course_id, name=course_name, cfu=course_cfu, ssd=course_ssd) course.year = course_year course.semester = course_semester course.url = course_url course.ac = course_ac if isValidCourse(course): db.session.add(course) db.session.commit() return redirect(url_for('indexCourse'))
def run(): for aux in range(len(list_departaments)): departament = DataSourceDepartament.read( "https://matriculaweb.unb.br/graduacao/oferta_dep.aspx?cod=" + str(list_departaments_numbers[aux]), list_departaments[aux]) DataSinkDepartament.write(departament, list_departaments[aux]) for new_aux in range(len(list_departaments_cods)): subjects = DataSourceSubject.read( "https://matriculaweb.unb.br/graduacao/oferta_dis.aspx?cod=" + str(list_departaments_cods[new_aux]), new_aux) DataSinkSubject.write(subjects) subjects_darcy = DataSourceDepartament.read( "https://matriculaweb.unb.br/graduacao/oferta_dep.aspx?cod=" + str(list_departaments_numbers[3]), list_departaments[3]) subjects_darcy_cods = subjects_darcy.list_cods subjects_darcy_initials = subjects_darcy.list_initials size_subjects_darcy = 76 for aux in range(size_subjects_darcy): subject = DataSourceSubjectsDarcy.read( "https://matriculaweb.unb.br/graduacao/oferta_dis.aspx?cod=" + str(subjects_darcy_cods[aux]), subjects_darcy_initials[aux], subjects_darcy_cods[aux]) DataSinkSubject.write(subject) for aux in range(len(list_campi_numbers)): request = requests.get( "https://matriculaweb.unb.br/graduacao/curso_rel.aspx?cod=" + str(list_campi_numbers[aux])) soup = BeautifulSoup(request.content, "html.parser") courses = Courses() list_content = [] for tr in soup.find_all('tr'): for td in tr.find_all('td'): list_content.append(td.text) list_content = Filter.blank_space(list_content) list_content = Filter.upper_words(list_content) list_content = Filter.remove_accents(list_content) list_cods = Filter.remove_vogals(list_content) list_modalities = Filter.get_modalities(list_content) list_shift = Filter.get_shift(list_content) list_names = Filter.get_names(list_content) courses.codes = list_cods courses.modalities = list_modalities courses.list_shift = list_shift courses.names = list_names DataSinkCourse.write(courses, list_departaments[aux])
def insert_course(payload): Message_body = request.get_json() New_course = Courses() if not Message_body: abort(400) name = Message_body.get('name', None) courseTimePeriod = Message_body.get('courseTimePeriod', None) if not name or not courseTimePeriod: abort(400) New_course.name = name New_course.courseTimePeriod = courseTimePeriod New_course.insert() return jsonify({'success': True})
def online_courses(): data = request.get_json() global response_id response_id += 1 username = data[0]['username'] video = data[0]['video'] new_lectory = Courses(username=username, video=video) new_stata = Stata(name=username, num_lec=100, num_video=1, mark=-1) if Stata.query.filter_by(name=username).first(): db.session.add(new_lectory) db.session.commit() courses = Stata.query.filter_by(name=username).first() courses.num_video += 1 db.session.commit() name, num_lectury, num_video, mark = str(courses).split(' ') return Response(dumps([{ 'id': response_id, 'statistic': { 'name': name, 'num_lectury': num_lectury, 'num_video': num_video, 'mark': mark } }]), status=201, mimetype='application/json') db.session.add_all([new_lectory, new_stata]) db.session.commit() return Response(dumps([{ 'id': response_id, 'statistic': { 'name': username, 'num_video': 1 } }]), status=201, mimetype='application/json')
def init_db(): #Creating the fixtures of the daatabase Tobiloba = StudentName(name= 'Tobiloba') Tobiloba.save() John = StudentName(name='John') John.save() Ayomide = StudentName(name='Ayomide') Ayomide.save() MEG101 = Courses(name='MEG101') MEG101.save() CEG103 = Courses(name='CEG103') CEG103.save() FSC103 = Courses(name='FSC103') FSC103.save()
def createCoursesFromCsvParser(): if request.method == 'GET': academicyears = Academicyears.query.all() return render_template('admin/course/parser.html', academicyears=academicyears) else: csvfile = open("csv/corsi.csv", "r") csvfile.readline() print("::::: parsing courses :::::") msg = "" course_counter = 0 # column of interest from csv # 3 = course code | 4 = name | 5 = ssd | 6 = cfu | 0 = year | 1 = semester for line in csvfile: row = line.split(";") course_counter += 1 if row[4] != "PROVA FINALE " and row[4] != "LABORATORIO/TIROCINIO ": #remove last empty char from parsed strings id = row[3] id = id[:-1] ssd = row[5] ssd = ssd[:-1] name = row[4] name = name[:-1] semester = int(row[1]) cfu = int(row[6]) year = int(row[0]) url = "#" ac = request.form['academicyear'] if Courses.query.get(id) is None: course = Courses(id=id, name=name, cfu=cfu, ssd=ssd) db.session.add(course) else: course = Courses.query.get(id) course.name = name course.cfu = cfu course.ssd = ssd course.year = year course.semester = semester course.url = url course.ac = ac if OtherCourses.query.get(id) is None: othercourse = OtherCourses(id=id, name=name, cfu=cfu, ssd=ssd) db.session.add(othercourse) else: othercourse = OtherCourses.query.get(id) othercourse.name = name othercourse.cfu = cfu othercourse.ssd = ssd db.session.commit() return redirect(url_for('indexCourse'))
def add(request): n = Courses(name=request.POST['name'], description=request.POST['description']) n.save() return redirect(reverse('courses:index'))
def add(request): n = Courses(name=request.POST['name'], description=request.POST['description']) n.save() return redirect('/')
def upload_course(): if current_user.role != 'admin': flash('You are not authorized to perform this action', 'danger') return redirect(url_for('dashboard')) dashboard_data = get_dashboard() form = AdminAddFileForm() if form.validate_on_submit(): added = False file = form.fileInput.data file_string = str(file.read(), 'utf-8') course_dict = csv.DictReader(file_string.splitlines(), skipinitialspace=True) for course_details in course_dict: try: course = find_course(course_details['courseCode']) if course is None: # Add the course if it is not inside the database added = True course = Courses(name=course_details['name'], courseCode=course_details['courseCode']) db.session.add(course) course_index = find_index(course_details['index']) if course_index is None: added = True course_index = Indexes( indexId=course_details['index'], className=course_details['className'], room=course_details['room'], courseId=get_course_id( course_details['courseCode']).id) db.session.add(course_index) date_obj = datetime.datetime.strptime(course_details['date'], '%d/%m/%Y') index_date = find_index_date(course_index.id, date_obj) if index_date is None: added = True index_date = IndexDates(date=date_obj, indexId=course_index.id) db.session.add(index_date) staff = get_staff(course_details['staffInCharged']) if staff is None: flash( f'{course_details["staffInCharged"]} is not inside the database. Please add this staff first', 'danger') return redirect(url_for('manage_course')) staff_in_charged = find_staff_in_charged( course_index.id, staff.id) if staff_in_charged is None: added = True staff_in_charged = StaffInCharged(indexId=course_index.id, staffId=staff.id) db.session.add(staff_in_charged) except: flash('CSV contains incorrect fields', 'danger') return redirect(url_for('manage_course')) if added: db.session.commit() flash('Course details have been added', 'success') else: flash('No course details was added', 'info') return redirect(url_for('manage_course')) return render_template('admin_add_file.html', form=form, dashboard_data=dashboard_data, legend='Upload Course')