def scancoursepage(self): match = Course.find(courseCode_equal=self.coursecode) urlstart = 'https://uspdigital.usp.br/jupiterweb/obterDisciplina' parameters = {'sgldis': str(self.coursecode)} completeurl = appendparameters(urlstart, parameters) self.crawler.loadpage(completeurl) name = self.findname() startdate = self.findstartdate() if match: course = match[0] else: course = Course(self.coursecode, name, startdate) course.store() idealtermmatch = IdealTermCourse.find(idCycle=self.cycle.idCycle, term=self.term, idCourse=course.idCourse, requisitionType= self.requisitiontype) if not idealtermmatch: idealterm = IdealTermCourse(self.cycle.idCycle, self.term, startdate, self.requisitiontype, course) idealterm.store() else: idealterm = idealtermmatch[0] return course
def scancoursepage(self): match = Course.find(courseCode_equal=self.coursecode) urlstart = 'https://uspdigital.usp.br/jupiterweb/obterDisciplina' parameters = {'sgldis': str(self.coursecode)} completeurl = appendparameters(urlstart, parameters) self.crawler.loadpage(completeurl) name = self.findname() startdate = self.findstartdate() if match: course = match[0] else: course = Course(self.coursecode, name, startdate) course.store() idealtermmatch = IdealTermCourse.find( idCycle=self.cycle.idCycle, term=self.term, idCourse=course.idCourse, requisitionType=self.requisitiontype) if not idealtermmatch: idealterm = IdealTermCourse(self.cycle.idCycle, self.term, startdate, self.requisitiontype, course) idealterm.store() else: idealterm = idealtermmatch[0] return course
def create_timePeriod_and_course(self): cursor = MySQLConnection() length = cursor.execute( 'SELECT idLength FROM minitableLength where length="Semestral"') if not length: cursor.execute( 'INSERT INTO minitableLength (length) values ("Semestral")') self.course = Course('tst9999', 'teste9999', '0000-00-00') self.course.store() length = cursor.execute( 'SELECT idLength FROM minitableLength where length="Semestral"') self.timePeriod = TimePeriod(1, 2014, 1) self.timePeriod.store()
def __init__(self, idTimePeriod, idCourses, useProfessorsName, byOffer, idFaculty, assessmentNumber): outputDirectory = settings.PASTA_RELATORIOS timePeriod = TimePeriod.pickById(idTimePeriod) faculty = Faculty.pickById(idFaculty) for idCourse in idCourses: course = Course.pickById(idCourse) courseReport = CourseReport(course, timePeriod, settings.TEMPLATE_RELATORIOS) courseReport.setReportInstructions(faculty, assessmentNumber, byOffer, useProfessorsName) courseReport.writeDocument(outputDirectory + "/" + str(idCourse)) timePeriodStr = str(timePeriod.year) if timePeriod.length == 1: timePeriodStr += "s" elif timePeriod.length == 2: timePeriodStr += "q" else: raise TimePeriodError("Invalid timePeriod length") timePeriodStr += str(timePeriod.session) try: subprocess.check_call(['cp', outputDirectory + '/' + str(idCourse) + '/' + courseReport.generateTitle() + ".pdf", settings.PASTA_RELATORIOS_SEPARADO + timePeriodStr + '/']) # Copia o relatorio para a pasta com os relatorios separados por semestres... por algum motivo except CalledProcessError: print 'Relatorio nao foi copiado para a disciplina ' + unicode(course)
def expandCourse(idCourse, idTimePeriod): """ Returns a list of dicts containig the keys: courseName, courseAbbreviation, courseCode. Where each one is a possible subgroup of the given course. It could be only the practical offers, only the offers given by one professor ... @param int idCourse : The database assossiated key to the wanted course @param int idTimePeriod : The idTimePeriod of the wanted subgroup's timePeriod. @return {} : @author """ course = Course.pickById(idCourse) offers = Offer.find(course=course, timePeriod=TimePeriod.pickById(idTimePeriod)) subgroups = Offer.possibleNames(offers) finalList = [] for subgroup in subgroups: subgroupDict = {} subgroupDict['courseName'] = course.name + subgroup['name'] subgroupDict[ 'courseAbbreviation'] = course.abbreviation + subgroup['name'] subgroupDict['courseCode'] = course.courseCode + subgroup['name'] subgroupDict['idCourse'] = course.idCourse finalList.append(subgroupDict) return finalList
def generateCourses(request): data = request.GET idCourses = json.loads(data['idCourses']) #Do something with this list idCourses = [int(idCourse) for idCourse in idCourses] if int(data['useProfessorsName']) == 1: useProfessorsName = True else: useProfessorsName = False if int(data['byOffer']) == 1: byOffer = 1 elif int(data['byOffer']) == 2: byOffer = 2 elif int(data['byOffer']) == 0: byOffer = 0 idTimePeriod = int(data['idTimePeriod']) idFaculty = int(data['idFaculty']) assessmentNumber = int(data['assessmentNumber']) user= request.user user_name = request.user.username time = get_time() timePeriod = str(TimePeriod.pickById(idTimePeriod)) courses = [str(Course.pickById(idCourse).courseCode) for idCourse in idCourses] cycle = Cycle.pickById(int(data['idCycle'])).name action = u"Usuário " + str(user_name) + u" gerou relatório: " \ + u"{ Curso: " + cycle \ + u"; Semestre: " + data['term'] \ + u"; Matérias: " + str(courses) \ + u"; Período: " + timePeriod \ + u"; Avaliação: " + data['assessmentNumber'] + " }" report_generate_log = Log(user=user, action=action, time=time) report_generate_log.save() CourseReportGenerator(idTimePeriod, idCourses, useProfessorsName, byOffer, idFaculty, assessmentNumber) return HttpResponse('Relatórios Gerados')
def tearDown(self): cursor = MySQLConnection() [offer.delete() for offer in Offer.find()] [schedule.delete() for schedule in Schedule.find()] cursor.execute('DELETE FROM minitableDayOfTheWeek') [timePeriod.delete() for timePeriod in TimePeriod.find()] [course.delete() for course in Course.find()] [professor.delete() for professor in Professor.find()] self.browser.quit()
def create_timePeriod_and_course(self): cursor = MySQLConnection() length = cursor.execute('SELECT idLength FROM minitableLength where length="Semestral"') if not length: cursor.execute('INSERT INTO minitableLength (length) values ("Semestral")') self.course = Course('tst9999', 'teste9999', '0000-00-00') self.course.store() length = cursor.execute('SELECT idLength FROM minitableLength where length="Semestral"') self.timePeriod = TimePeriod(1, 2014, 1) self.timePeriod.store()
def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id( 'id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str( self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id( 'id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id( 'id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id( 'numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text)
def findCourses(searchedAbbreviation, searchedCourseCode, searchedName, idTimePeriod, idCycle=None, term=None): """ returns a list of dicts containig the keys: courseName, courseAbbreviation, courseCode and idCourse. @param string searchedAbbreviation : Part of the wanted course's abbreviation. @param string searchedCourseCode : Part of the wanted course's courseCode @param string searchedName : Part of the wanted course's name. @param int idTimePeriod : The idTimePeriod of the wanted course's timePeriod. @param int idCycle : Is None by default, if it is set the courses related to the chosen cycle will be the firsts of the returned list. @param int term : The term related to the idCycle, is None by default. @return [] : @author """ cursor = MySQLConnection() activeIdCourses = cursor.execute( 'SELECT idCourse FROM aggr_offer WHERE idTimePeriod = ' + str(idTimePeriod) + ' GROUP BY idCourse') activeIdCourses = [course[0] for course in activeIdCourses] firstIdCourses = [] if idCycle != None or term != None: query = 'SELECT idCourse FROM rel_course_cycle WHERE endDate = "0000-00-00"' if idCycle != None: query = query + ' AND idCycle = ' + str(idCycle) if term != None: query = query + ' AND term = ' + str(term) firstIdCourses = cursor.execute(query) firstIdCourses = [course[0] for course in firstIdCourses] courses = Course.find(abbreviation_like=searchedAbbreviation, courseCode_like=searchedCourseCode, name_like=searchedName, endDate_equal='0000-00-00', idCourse=activeIdCourses) finalList = [] for course in courses: dictCourse = {} dictCourse['courseName'] = course.name dictCourse['courseAbbreviation'] = course.abbreviation dictCourse['courseCode'] = course.courseCode dictCourse['idCourse'] = course.idCourse if course.idCourse in firstIdCourses: #if it is an empty list no one will be at the top finalList.insert(0, dictCourse) dictCourse['oneOfTheFirst'] = True else: finalList.append(dictCourse) dictCourse['oneOfTheFirst'] = False return finalList
def offer(request): if request.method == 'POST': form = IndexForm(request.POST) form.updateForm() if form.is_valid(): timePeriod = TimePeriod.pickById(form.cleaned_data['dropDownTimePeriod']) course = Course.pickById(form.cleaned_data['dropDownCourse']) offers = Offer.find(timePeriod=timePeriod, course=course) rendered_page = render(request, 'offer.html', {'offers': offers, 'timePeriod': timePeriod, 'course': course}) return rendered_page else: return HttpResponseRedirect('/interface/')
def updateForm(self): timePeriods = TimePeriod.find() timePeriods.reverse() timePeriodNames = [str(timePeriod) for timePeriod in timePeriods] timePeriodIds = [t.idTimePeriod for t in timePeriods] timePeriodInfo = zip(timePeriodIds, timePeriodNames) courses = Course.find() courseCode = [course.courseCode for course in courses] courseIds = [course.idCourse for course in courses] courseInfo = zip(courseIds, courseCode) courseInfo = sorted(courseInfo, key=getKey) self.fields['dropDownTimePeriod'] = forms.ChoiceField(widget=forms.Select, choices=timePeriodInfo, label = 'Periodo') self.fields['dropDownCourse'] = forms.ChoiceField(widget=forms.Select, choices=courseInfo, label = 'Codigo do Curso')
def offer_create(request, idTimePeriod, idCourse): timePeriod = TimePeriod.pickById(idTimePeriod) course = Course.pickById(idCourse) if request.method == 'POST': form = OfferForm(request.POST) form.updateForm() if form.is_valid(): idProfessor = form.cleaned_data['dropDownProfessor'] classNumber = form.cleaned_data['classNumber'] practical = form.cleaned_data['dropDownTeoricaPratica'] numberOfRegistrations = form.cleaned_data['numberOfRegistrations'] schedulesIds = form.cleaned_data['listSchedules'] schedules = [ Schedule.pickById(schedule) for schedule in schedulesIds ] professor = Professor.pickById(idProfessor) practical = (practical == 1) offer = Offer(timePeriod, course, classNumber, practical, professor) offer.setSchedules(schedules) offer.setNumberOfRegistrations(numberOfRegistrations) offer.store() user = request.user user_name = request.user.username time = get_time() schedules_string = '[ ' for schedule in schedules: schedules_string += str(schedule).replace('ç', 'c') + " " schedules_string += ']' action = u"Usuário " + user_name + u" criou o oferecimento id: " + str(offer.idOffer) + " {" \ + u" Código do Curso: " + str(course.courseCode) \ + u"; Turma: T" + str(classNumber) \ + u"; Professor: " + professor.name \ + u"; Periodo: " + str(timePeriod) \ + u"; Horários: " + schedules_string + " }" offer_create_log = Log(user=user, action=action, time=time) offer_create_log.save() return HttpResponseRedirect('/interface/offer/' + str(offer.idOffer)) else: form = OfferForm() form.updateForm() rendered_page = render(request, 'offer_create.html', { 'form': form, 'timePeriod': timePeriod, 'course': course }) return rendered_page
def getOffers(courseCode, idTimePeriod): """ Returns the set of idOffers defined by this courseCode as is defined in expandCourse method. @param string courseCode : If it is a normal course this is not used, if this is a subgroup of a course, this courseCode is going to define the offers.Ex PTC3011(P)[ProfName] = only practical offers given by ProfName in course PTC3011. @param int idTimePeriod : The idTimePeriod of the wanted offer's timePeriod. @return : @author """ professor = None practical = None if courseCode.find('[') != -1: professorName = courseCode.rsplit('[')[1].rsplit(']')[0] professor = Professor.find(name_equal=professorName)[0] courseCode = courseCode.rsplit('[')[0] + courseCode.rsplit(']')[1] if courseCode.find('(') != -1: practical = courseCode.rsplit('(')[1].rsplit(')')[0] if practical == 'P': practical = True elif practical == 'T': practical = False else: raise ColumnsControllerError( "The parameter given between the '()' must be equal to 'P' or 'T'." ) courseCode = courseCode.rsplit('(')[0] + courseCode.rsplit(')')[1] course = Course.find(courseCode_equal=courseCode, endDate_equal='0000-00-00')[0] timePeriod = TimePeriod.pickById(idTimePeriod) if professor and practical != None: offers = Offer.find(course=course, practical=practical, professor=professor, timePeriod=timePeriod) elif professor: offers = Offer.find(course=course, professor=professor, timePeriod=timePeriod) elif practical != None: offers = Offer.find(course=course, practical=practical, timePeriod=timePeriod) else: offers = Offer.find(course=course, timePeriod=timePeriod) idOffers = [offer.idOffer for offer in offers] return idOffers
def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id('id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id('id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id('id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id('numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text)
def offer(request): if request.method == 'POST': form = IndexForm(request.POST) form.updateForm() if form.is_valid(): timePeriod = TimePeriod.pickById( form.cleaned_data['dropDownTimePeriod']) course = Course.pickById(form.cleaned_data['dropDownCourse']) offers = Offer.find(timePeriod=timePeriod, course=course) rendered_page = render(request, 'offer.html', { 'offers': offers, 'timePeriod': timePeriod, 'course': course }) return rendered_page else: return HttpResponseRedirect('/interface/')
def test_delete_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface', self.browser.title) open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertNotIn('Interface - Offer Detail', self.browser.title)
def findCourses(searchedAbbreviation, searchedCourseCode, searchedName, idTimePeriod, idCycle = None, term = None): """ returns a list of dicts containig the keys: courseName, courseAbbreviation, courseCode and idCourse. @param string searchedAbbreviation : Part of the wanted course's abbreviation. @param string searchedCourseCode : Part of the wanted course's courseCode @param string searchedName : Part of the wanted course's name. @param int idTimePeriod : The idTimePeriod of the wanted course's timePeriod. @param int idCycle : Is None by default, if it is set the courses related to the chosen cycle will be the firsts of the returned list. @param int term : The term related to the idCycle, is None by default. @return [] : @author """ cursor = MySQLConnection() activeIdCourses = cursor.execute('SELECT idCourse FROM aggr_offer WHERE idTimePeriod = ' + str(idTimePeriod) + ' GROUP BY idCourse') activeIdCourses = [course[0] for course in activeIdCourses] firstIdCourses = [] if idCycle != None or term != None: query = 'SELECT idCourse FROM rel_course_cycle WHERE endDate = "0000-00-00"' if idCycle != None: query = query + ' AND idCycle = ' + str(idCycle) if term != None: query = query + ' AND term = ' + str(term) firstIdCourses = cursor.execute(query) firstIdCourses = [course[0] for course in firstIdCourses] courses = Course.find(abbreviation_like = searchedAbbreviation, courseCode_like = searchedCourseCode, name_like = searchedName, endDate_equal = '0000-00-00', idCourse = activeIdCourses) finalList = [] for course in courses: dictCourse = {} dictCourse['courseName'] = course.name dictCourse['courseAbbreviation'] = course.abbreviation dictCourse['courseCode'] = course.courseCode dictCourse['idCourse'] = course.idCourse if course.idCourse in firstIdCourses: #if it is an empty list no one will be at the top finalList.insert(0,dictCourse) dictCourse['oneOfTheFirst'] = True else: finalList.append(dictCourse) dictCourse['oneOfTheFirst'] = False return finalList
def offer_create(request, idTimePeriod, idCourse): timePeriod = TimePeriod.pickById(idTimePeriod) course = Course.pickById(idCourse) if request.method == 'POST': form = OfferForm(request.POST) form.updateForm() if form.is_valid(): idProfessor = form.cleaned_data['dropDownProfessor'] classNumber = form.cleaned_data['classNumber'] practical = form.cleaned_data['dropDownTeoricaPratica'] numberOfRegistrations = form.cleaned_data['numberOfRegistrations'] schedulesIds = form.cleaned_data['listSchedules'] schedules = [Schedule.pickById(schedule) for schedule in schedulesIds] professor = Professor.pickById(idProfessor) practical = (practical == 1) offer = Offer(timePeriod, course, classNumber, practical, professor) offer.setSchedules(schedules) offer.setNumberOfRegistrations(numberOfRegistrations) offer.store() user= request.user user_name = request.user.username time = get_time() schedules_string = '[ ' for schedule in schedules: schedules_string += str(schedule).replace('ç','c') + " " schedules_string += ']' action = u"Usuário " + user_name + u" criou o oferecimento id: " + str(offer.idOffer) + " {" \ + u" Código do Curso: " + str(course.courseCode) \ + u"; Turma: T" + str(classNumber) \ + u"; Professor: " + professor.name \ + u"; Periodo: " + str(timePeriod) \ + u"; Horários: " + schedules_string + " }" offer_create_log = Log(user=user, action=action, time=time) offer_create_log.save() return HttpResponseRedirect('/interface/offer/' + str(offer.idOffer)) else: form = OfferForm() form.updateForm() rendered_page = render(request, 'offer_create.html', {'form': form, 'timePeriod': timePeriod, 'course': course}) return rendered_page
def expandCourse(idCourse, idTimePeriod): """ Returns a list of dicts containig the keys: courseName, courseAbbreviation, courseCode. Where each one is a possible subgroup of the given course. It could be only the practical offers, only the offers given by one professor ... @param int idCourse : The database assossiated key to the wanted course @param int idTimePeriod : The idTimePeriod of the wanted subgroup's timePeriod. @return {} : @author """ course = Course.pickById(idCourse) offers = Offer.find(course = course, timePeriod = TimePeriod.pickById(idTimePeriod)) subgroups = Offer.possibleNames(offers) finalList = [] for subgroup in subgroups: subgroupDict = {} subgroupDict['courseName'] = course.name + subgroup['name'] subgroupDict['courseAbbreviation'] = course.abbreviation + subgroup['name'] subgroupDict['courseCode'] = course.courseCode + subgroup['name'] subgroupDict['idCourse'] = course.idCourse finalList.append(subgroupDict) return finalList
def getOffers(courseCode, idTimePeriod): """ Returns the set of idOffers defined by this courseCode as is defined in expandCourse method. @param string courseCode : If it is a normal course this is not used, if this is a subgroup of a course, this courseCode is going to define the offers.Ex PTC3011(P)[ProfName] = only practical offers given by ProfName in course PTC3011. @param int idTimePeriod : The idTimePeriod of the wanted offer's timePeriod. @return : @author """ professor = None practical = None if courseCode.find('[') != -1: professorName = courseCode.rsplit('[')[1].rsplit(']')[0] professor = Professor.find(name_equal = professorName)[0] courseCode = courseCode.rsplit('[')[0] + courseCode.rsplit(']')[1] if courseCode.find('(') != -1: practical = courseCode.rsplit('(')[1].rsplit(')')[0] if practical == 'P': practical = True elif practical == 'T': practical = False else: raise ColumnsControllerError("The parameter given between the '()' must be equal to 'P' or 'T'.") courseCode = courseCode.rsplit('(')[0] + courseCode.rsplit(')')[1] course = Course.find(courseCode_equal = courseCode, endDate_equal = '0000-00-00')[0] timePeriod = TimePeriod.pickById(idTimePeriod) if professor and practical != None: offers = Offer.find(course = course, practical = practical, professor = professor, timePeriod = timePeriod) elif professor: offers = Offer.find(course = course, professor = professor, timePeriod = timePeriod) elif practical != None: offers = Offer.find(course = course, practical = practical, timePeriod = timePeriod) else: offers = Offer.find(course = course, timePeriod = timePeriod) idOffers = [offer.idOffer for offer in offers] return idOffers
def generateCourses(request): data = request.GET idCourses = json.loads(data['idCourses']) #Do something with this list idCourses = [int(idCourse) for idCourse in idCourses] if int(data['useProfessorsName']) == 1: useProfessorsName = True else: useProfessorsName = False if int(data['byOffer']) == 1: byOffer = 1 elif int(data['byOffer']) == 2: byOffer = 2 elif int(data['byOffer']) == 0: byOffer = 0 idTimePeriod = int(data['idTimePeriod']) idFaculty = int(data['idFaculty']) assessmentNumber = int(data['assessmentNumber']) user = request.user user_name = request.user.username time = get_time() timePeriod = str(TimePeriod.pickById(idTimePeriod)) courses = [ str(Course.pickById(idCourse).courseCode) for idCourse in idCourses ] cycle = Cycle.pickById(int(data['idCycle'])).name action = u"Usuário " + str(user_name) + u" gerou relatório: " \ + u"{ Curso: " + cycle \ + u"; Semestre: " + data['term'] \ + u"; Matérias: " + str(courses) \ + u"; Período: " + timePeriod \ + u"; Avaliação: " + data['assessmentNumber'] + " }" report_generate_log = Log(user=user, action=action, time=time) report_generate_log.save() CourseReportGenerator(idTimePeriod, idCourses, useProfessorsName, byOffer, idFaculty, assessmentNumber) return HttpResponse('Relatórios Gerados')
def storeOpticalSheet(idOpticalSheet, surveyType, idCycle, term, idTimePeriod, fields, surveys, encoded): """ Tries to store the opticalSheet and returns a mensage explaning what happend. @param int idOpticalSheet : Id of the opticalSheet to be store, if it is a new one it should be None. @param string surveyType : A string defining the type of the opticalSheets survey, must be in minitableSurveyType. @param int idCycle : The database id of the cycle to be added in this opticalSheet, it can't be None, it is ok if this cycle is alredy related to this opticalSheet. @param int term : Term to be added in the relation cycle opticalSheet . @param int idTimePeriod : Database id of the timePeriod in which this opticalSheet exist. @param [] fields : If not encoded: A list of dicts, where each dict represent a field and contain the keys: idsOffer, courseIndex, abbreviation, idCourse. Else is just the encoding name @param [] surveys : A list of dicts where each dict represents a survey with the keys: assessmentNumber, idQuestionnaire: None or the IdQuestionnaire, questions: [{questionWording, questionIndex} @param string encoded : A boolean to define if this opticalSheet is encoded @return string: @author """ timePeriod = TimePeriod.pickById(idTimePeriod) cycle = Cycle.pickById(idCycle) storedFields = False storedQuestionnaire = False if idOpticalSheet != None: opticalSheet = OpticalSheet.pickById(idOpticalSheet) if opticalSheet.surveyType != surveyType: raise OpticalSheetError("ERROR: Given surveyType is different than opticalSheet's surveyType.") #clear opticalSheets surveys opticalSheet.surveys = [] else: #Before creating a new one check if it already exist if encoded: if len(OpticalSheet.find(encodingName = fields)) > 0: raise OpticalSheetError("There can only be one opticalSheet per encoding!") if len(OpticalSheet.find(cycles = [cycle], term = term, timePeriod = timePeriod)) > 0: #Even encoded opticalSheets have to pass through this raise OpticalSheetError("There can be only one opticalSheet per cycle, term and timePeriod") #Now it is ok to store opticalSheet = OpticalSheet(surveyType) if encoded: opticalSheet.setEncodingName(fields) opticalSheet.store() hasAnswers = False answers = Answer.countAnswers(opticalSheet = opticalSheet) for key in answers: if answers[key] > 0: hasAnswers = True if not hasAnswers: #Can't alter offers with answers #First deal with the fields if not encoded: for field in fields: idsOffer = [int(offer) for offer in field['idOffers']] if len(idsOffer) > 0: course = Course.pickById(field['idCourse']) abbreviation = field['abbreviation'].split('(')[0].split('[')[0] course.setAbbreviation(abbreviation) course.store() opticalSheet.addOpticalSheetField(Offer.find(idOffer = idsOffer), int(field['courseIndex']) + 1) else: opticalSheet.removeOpticalSheetField(int(field['courseIndex']) + 1) print field['courseIndex'] storedFields = True #Next the cycle if not {'term':term, 'cycle':cycle} in opticalSheet.cycles: opticalSheet.addCycle_Term(cycle, term) for survey in surveys: hasAnswers = False answers = Answer.countAnswers(opticalSheet = opticalSheet, assessmentNumber = survey['assessmentNumber']) for key in answers: if answers[key] > 0: hasAnswers = True if not hasAnswers: #Can't alter a survey with answers #prepare the questionDict questionDict = {} for questionData in survey['questions']: if questionData['idQuestion'] != None: question = Question.pickById(questionData['idQuestion']) questionDict[int(questionData['questionIndex']) + 1] = question #Create or find the questionnaire if survey['idQuestionnaire'] != None: questionnaire = Questionnaire.pickById(survey['idQuestionnaire']) #If the questionnaire exist update its questions if questionnaire.questions != questionDict: questionnaire.questions = questionDict questionnaire.store() else: #Create it if encoded: #this is only to know the questionnaire's discription questionnaire = Questionnaire(questionDict, fields + str(timePeriod)) else: questionnaire = Questionnaire(questionDict, cycle.name + '-' + str(term) + '-' + str(timePeriod)) questionnaire.store() #Now remove old survey of this assessment in this opticalSheet (this method works even if there are no surveys in this opticalSheet) opticalSheet.removeSurvey(survey['assessmentNumber']) opticalSheet.addSurvey(questionnaire, survey['assessmentNumber']) storedQuestionnaire = True if storedQuestionnaire or storedFields: opticalSheet.store() if storedFields: return 'OpticalSheet was stored' elif storedQuestionnaire: return 'Only Questionnaire was stored' else: raise OpticalSheetError("Can't save a opticalSheet with answers in the same assessment!!")
class OfferTest(LiveServerTestCase): def setUp(self): self.name_professor = 'teste' self.create_timePeriod_and_course() self.create_professor_and_schedule() self.browser = WebDriver() create_user_and_login(self.browser, self.live_server_url, 'john', 'johnpassword', '*****@*****.**') self.browser.implicitly_wait(40) def tearDown(self): cursor = MySQLConnection() [offer.delete() for offer in Offer.find()] [schedule.delete() for schedule in Schedule.find()] cursor.execute('DELETE FROM minitableDayOfTheWeek') [timePeriod.delete() for timePeriod in TimePeriod.find()] [course.delete() for course in Course.find()] [professor.delete() for professor in Professor.find()] self.browser.quit() def create_timePeriod_and_course(self): cursor = MySQLConnection() length = cursor.execute( 'SELECT idLength FROM minitableLength where length="Semestral"') if not length: cursor.execute( 'INSERT INTO minitableLength (length) values ("Semestral")') self.course = Course('tst9999', 'teste9999', '0000-00-00') self.course.store() length = cursor.execute( 'SELECT idLength FROM minitableLength where length="Semestral"') self.timePeriod = TimePeriod(1, 2014, 1) self.timePeriod.store() def create_professor_and_schedule(self): cursor = MySQLConnection() cursor.execute( 'INSERT INTO `minitableDayOfTheWeek` (dayOfTheWeek) VALUES ("Domingo"), ("Segunda"), ("Terça"), ("Quarta"), ("Quinta"), ("Sexta"), ("Sabado")' ) self.schedule = Schedule('Domingo', '14:00:00', 'weekly', '12:00:00') self.schedule.store() self.schedule = Schedule('Segunda', '19:00:00', 'weekly', '16:00:00') self.schedule.store() self.schedule = Schedule('Quarta', '16:00:00', 'weekly', '14:00:00') self.schedule.store() self.professor = Professor('Professor Teste') self.professor.store() self.second_professor = Professor('Professor Teste2') self.second_professor.store() def login_to_offer_page(self): open_page(self.browser, '/interface/', self.live_server_url) dropdown_timePeriod = self.browser.find_element_by_id( 'id_dropDownTimePeriod') dropdown_course = self.browser.find_element_by_id('id_dropDownCourse') select_timePeriod = Select(dropdown_timePeriod) select_timePeriod.select_by_value(str(self.timePeriod.idTimePeriod)) select_course = Select(dropdown_course) select_course.select_by_value(str(self.course.idCourse)) professor_interface = self.browser.find_element_by_link_text('Offer') professor_interface.click() self.assertIn('Interface - Offer', self.browser.title) def test_create_offer(self): self.login_to_offer_page() button_create_offer = self.browser.find_element_by_name('criar') button_create_offer.click() self.assertIn('Interface - Offer Create', self.browser.title) dropdown_professor = self.browser.find_element_by_id( 'id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id( 'id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id( 'id_numberOfRegistrations') input_numberOfRegistrations.send_keys('10') self.browser.find_element_by_id("id_listSchedules_0").click() self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_store = self.browser.find_element_by_name('Cadastrar') button_store.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T01') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "TEORICA") id_numberOfRegistrations = self.browser.find_element_by_id( 'numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '10') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertIn("Quarta 14:00 - 16:00", id_schedules.text) def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id( 'id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str( self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id( 'id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id( 'id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id( 'numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text) def test_delete_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface', self.browser.title) open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertNotIn('Interface - Offer Detail', self.browser.title)
class OfferTest (LiveServerTestCase): def setUp(self): self.name_professor = 'teste' self.create_timePeriod_and_course() self.create_professor_and_schedule() self.browser = WebDriver() create_user_and_login(self.browser, self.live_server_url,'john','johnpassword','*****@*****.**') self.browser.implicitly_wait(40) def tearDown(self): cursor = MySQLConnection() [offer.delete() for offer in Offer.find()] [schedule.delete() for schedule in Schedule.find()] cursor.execute('DELETE FROM minitableDayOfTheWeek') [timePeriod.delete() for timePeriod in TimePeriod.find()] [course.delete() for course in Course.find()] [professor.delete() for professor in Professor.find()] self.browser.quit() def create_timePeriod_and_course(self): cursor = MySQLConnection() length = cursor.execute('SELECT idLength FROM minitableLength where length="Semestral"') if not length: cursor.execute('INSERT INTO minitableLength (length) values ("Semestral")') self.course = Course('tst9999', 'teste9999', '0000-00-00') self.course.store() length = cursor.execute('SELECT idLength FROM minitableLength where length="Semestral"') self.timePeriod = TimePeriod(1, 2014, 1) self.timePeriod.store() def create_professor_and_schedule(self): cursor = MySQLConnection() cursor.execute('INSERT INTO `minitableDayOfTheWeek` (dayOfTheWeek) VALUES ("Domingo"), ("Segunda"), ("Terça"), ("Quarta"), ("Quinta"), ("Sexta"), ("Sabado")') self.schedule = Schedule('Domingo', '14:00:00', 'weekly', '12:00:00') self.schedule.store() self.schedule = Schedule('Segunda', '19:00:00', 'weekly', '16:00:00') self.schedule.store() self.schedule = Schedule('Quarta', '16:00:00', 'weekly', '14:00:00') self.schedule.store() self.professor = Professor('Professor Teste') self.professor.store() self.second_professor = Professor('Professor Teste2') self.second_professor.store() def login_to_offer_page(self): open_page(self.browser, '/interface/', self.live_server_url) dropdown_timePeriod = self.browser.find_element_by_id('id_dropDownTimePeriod') dropdown_course = self.browser.find_element_by_id('id_dropDownCourse') select_timePeriod = Select(dropdown_timePeriod) select_timePeriod.select_by_value(str(self.timePeriod.idTimePeriod)) select_course = Select(dropdown_course) select_course.select_by_value(str(self.course.idCourse)) professor_interface = self.browser.find_element_by_link_text('Offer') professor_interface.click() self.assertIn('Interface - Offer', self.browser.title) def test_create_offer(self): self.login_to_offer_page() button_create_offer = self.browser.find_element_by_name('criar') button_create_offer.click() self.assertIn('Interface - Offer Create', self.browser.title) dropdown_professor = self.browser.find_element_by_id('id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id('id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id('id_numberOfRegistrations') input_numberOfRegistrations.send_keys('10') self.browser.find_element_by_id("id_listSchedules_0").click() self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_store = self.browser.find_element_by_name('Cadastrar') button_store.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T01') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "TEORICA") id_numberOfRegistrations = self.browser.find_element_by_id('numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '10') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertIn("Quarta 14:00 - 16:00", id_schedules.text) def test_edit_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_edit = self.browser.find_element_by_name('editar') button_edit.click() self.assertIn('Interface - Offer Edit', self.browser.title) dropdown_professor = self.browser.find_element_by_id('id_dropDownProfessor') select_professor = Select(dropdown_professor) select_professor.select_by_value(str(self.second_professor.idProfessor)) input_classNumber = self.browser.find_element_by_id('id_classNumber') input_classNumber.send_keys('1') dropdown_practical = self.browser.find_element_by_id('id_dropDownTeoricaPratica') select_practical = Select(dropdown_practical) select_practical.select_by_value('1') input_numberOfRegistrations = self.browser.find_element_by_id('id_numberOfRegistrations') input_numberOfRegistrations.send_keys('1') self.browser.find_element_by_id("id_listSchedules_1").click() self.browser.find_element_by_id("id_listSchedules_2").click() button_apply = self.browser.find_element_by_name('Aplicar') button_apply.click() self.assertIn('Interface - Offer Detail', self.browser.title) id_courseCode = self.browser.find_element_by_id('courseCode') self.assertEqual(id_courseCode.text, 'tst9999') id_name = self.browser.find_element_by_id('name') self.assertEqual(id_name.text, 'teste9999') id_professor_name = self.browser.find_element_by_id('professor_name') self.assertEqual(id_professor_name.text, 'Professor Teste2') id_timePeriod = self.browser.find_element_by_id('timePeriod') self.assertEqual(id_timePeriod.text, 'Primeiro semestre de 2014') id_classNumber = self.browser.find_element_by_id('classNumber') self.assertEqual(id_classNumber.text, 'T101') id_practical = self.browser.find_element_by_id('practical') self.assertEqual(id_practical.text, "PRATICA") id_numberOfRegistrations = self.browser.find_element_by_id('numberOfRegistrations') self.assertEqual(id_numberOfRegistrations.text, '101') id_schedules = self.browser.find_element_by_id('schedules') self.assertIn("Domingo 12:00 - 14:00", id_schedules.text) self.assertNotIn("Segunda 16:00 - 19:00", id_schedules.text) self.assertNotIn("Quarta 14:00 - 16:00", id_schedules.text) def test_delete_offer(self): timePeriod = TimePeriod.find()[0] course = Course.find()[0] first_professor = Professor.find()[0] schedules = Schedule.find() offer = Offer(timePeriod, course, 10, 0, first_professor) offer.setNumberOfRegistrations(10) offer.setSchedules(schedules) offer.store() open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertIn('Interface - Offer Detail', self.browser.title) button_delete = self.browser.find_element_by_name('deletar') button_delete.click() alert = self.browser.switch_to.alert alert.accept() self.assertIn('Interface', self.browser.title) open_page(self.browser, '/interface/offer/' + str(offer.idOffer), self.live_server_url) self.assertNotIn('Interface - Offer Detail', self.browser.title)