def GET(self): if session.user is None: web.seeother('/') elif session.user.position.title in ['Counselor', 'Head Counselor']: data = web.input() try: num = int(data['num']) date = iso_to_date(data['date']) student_id = int(data['student']) type = int(data['type']) except ValueError: return render.message(session.user, 'Invalid GET Parameters!') db_session = DBSession() counselor = db_session.query(Counselor).filter_by(id = session.user.id).one() try: period = db_session.query(Period).filter_by(num = num, date = date).one() student = db_session.query(Student).filter_by(id = student_id).one() interview_type = db_session.query(InterviewType).filter_by(id = type).one() except NoResultsFound: return render.message(session.user, 'No such period, interview type, or student!') if interview_type.name == 'Followup Interview': # A followup interview natures_of_problem = db_session.query(NatureOfProblemType) main_form = self.followup_form(natures_of_problem) elif interview_type.name == 'Routine Interview': # routine interview main_form = self.routine_form else: # other interview, which we have no form for yet... main_form = self.other_form return render.create_notation(main_form, self.hidden_forms(period, student, interview_type), self.button_form)
def GET(self): if session.user is None: web.seeother('/') elif session.user.position.title in ['Counselor', 'Head Counselor']: data = web.input() db_session = DBSession() try: date = iso_to_date(data['date']) num = int(data['num']) except ValueError: return render.message(session.user, 'stop tampering with my GET parameters!') period = db_session.query(Period).filter_by(date = date, num = num).one() counselor = db_session.query(Counselor).filter_by(id = session.user.id).one() handled_section_ids = db_session.query(Section.id).filter_by(counselor_id = counselor.id) students = db_session.query(Student).filter(Student.section_id.in_(handled_section_ids)).join(Student.section) interview_types = db_session.query(InterviewType) if 'letter' in data: students = students.filter(Student.last_name.like(data['letter'] + '%')) elif 'year' in data: students = students.filter(Section.year == int(data['year'])) elif 'section' in data: students = students.filter(Section.year == int(data['section'][0]), Section.name == data['section'][1]) students = students.order_by(Student.section_id, Student.last_name) return render.choosing(session.user, students, date.isoformat(), num, interview_types, str)
def GET(self): if session.user is None: web.seeother('/') elif session.user.position.title in ['Counselor', 'Head Counselor']: data = web.input() try: student_id = int(data['id']) date = iso_to_date(data['date']) num = int(data['num']) interview_type_id = int(data['interview_type']) except ValueError: return render.message(session.user, 'Don\'t mess with my GET parameters!') db_session = DBSession() period = db_session.query(Period).filter_by(date = date, num = num).one() interview_type = db_session.query(InterviewType).filter_by(id = interview_type_id).one() counselor = db_session.query(Counselor).filter_by(id = session.user.id).one() student = db_session.query(Student).filter_by(id = student_id).one() # check if a counselor has already scheduled something for this date, # or if student is already scheduled for that date counselor_already_scheduled = db_session.query(ScheduleEntry).filter_by(period = period, counselor = counselor).first() student_already_scheduled_this_date = db_session.query(ScheduleEntry).filter_by(period = period, student = student).first() if counselor_already_scheduled or student_already_scheduled_this_date: web.seeother('/editweekly') else: sched = ScheduleEntry() sched.period = period sched.type = interview_type sched.counselor = counselor sched.student = student db_session.add(sched) db_session.commit() web.seeother('/editweekly')
def get_current_status_string(self, country): try: status = self.get_country_all_status(country) yesterday, today = status[0], status[1] date = iso_to_date(today["Date"]) status_as_string = f""" Last available data is from {date} 📆 _COVID-19 Report for {today["Country"]}_ {FLAGS.get(today["Country"], "")} {get_virus_emoji(today["Active"])} There are {today["Active"]} active cases in {today["Country"]}, {self.get_active_cases_trend(today["Active"], yesterday["Active"])} Confirmed cases: {today["Confirmed"]} (+{today["Confirmed"] - yesterday["Confirmed"]}) Deaths: {today["Deaths"]} (+{today["Deaths"] - yesterday["Deaths"]}) Recovered: {today["Recovered"]} (+{today["Recovered"] - yesterday["Recovered"]}) _Hint: you can also try /report {today["Country"]} for more info_ """ except: status_as_string = ( "Didn't find anything. Is the *name of the country* correctly spelled?" ) return status_as_string
def GET(self): if session.user is None: web.seeother('/') elif session.user.position.title in ['Counselor', 'Head Counselor']: data = web.input() try: date = iso_to_date(data['date']) num = int(data['num']) except ValueError: return render.message(session.user, 'Naughty. Try entering a legal number, please.') db_session = DBSession() entry = db_session.query(ScheduleEntry).join(Period).\ filter(Period.num == num, Period.date == date).\ filter(ScheduleEntry.counselor_id == session.user.id).first() if entry: db_session.delete(entry) db_session.commit() web.seeother('/editweekly') else: return render.message(session.user, 'No permission to delete student, or no such date/period.')
def POST(self): data = web.input() db_session = DBSession() period_id = int(data['period_id']) student_id = int(data['student_id']) interview_type_id = int(data['interview_type']) main_form = None interview_type = db_session.query(InterviewType).filter_by(id = interview_type_id).one() interview = Interview() interview.type = interview_type interview.counselor_id = session.user.id interview.period_id = period_id interview.student_id = student_id latest_interview_id = db_session.query(Interview).order_by(Interview.id).all() interview.id = 1 + latest_interview_id[-1].id if latest_interview_id else 0 date = iso_to_date(data['date']) student_id = int(data['student']) student = db_session.query(Student).filter_by(id = student_id).one() if interview_type.name == 'Routine Interview': rform = self.routine_form num = int(data['num']) period = db_session.query(Period).filter(Period.num == num, Period.date == date).one() if not rform.validates(): return render.create_notation(rform,self.hidden_forms(period, student, interview_type), self.button_form) routine = RoutineInterview() routine.general_mental_ability = data['General Mental Ability'] routine.academic_history = data['Academic History'] routine.family_relationship = data['Family Relationship'] routine.personal_emotional = data['Personal/Emotional'] routine.peer_relationship = data['Peer Relationship'] routine.goals = data['Goals/Motivation'] routine.recommendation = data['Recommendation'] routine.id = interview.id db_session.add(routine) elif interview_type.name == 'Followup Interview': natures_of_problem = db_session.query(NatureOfProblemType) fform = self.followup_form(natures_of_problem) num = int(data['num']) period = db_session.query(Period).filter_by(num = num, date = date).one() if not fform.validates(): return render.create_notation(fform,self.hidden_forms(period, student, interview_type), self.button_form) followup = FollowupInterview() followup.nature_of_problem_id = int(data['Nature of problem']) followup.comments = data['Comments'] followup.planned_intervention = data['Planned Intervention'] followup.id = interview.id db_session.add(followup) elif interview_type.name == 'Other': other = OtherInterview() other.content = data['Content'] period = db_session.query(Period).filter_by(num = num, date = date).one() num = int(data['num']) other.id = interview.id db_session.add(other) db_session.add(interview) db_session.commit() return render.message(session.user, 'Interview conducted!')