def get_teachers_list_classes_in_month(self, year, month): """ :param year: int :param month: int :return: dict(teacher_id=[classes]) """ from openstudio.os_class_schedule import ClassSchedule from general_helpers import get_last_day_month ids = self.get_teacher_ids() start_date = datetime.date(year, month, 1) last_day = get_last_day_month(start_date) data = {} for teID in ids: teID = int(teID) data[teID] = {} data[teID]['classes'] = {} data[teID]['classes_count'] = 0 for each_day in range(1, last_day.day + 1): # list days day = datetime.date(year, month, each_day) weekday = day.isoweekday() class_schedule = ClassSchedule(date=day, filter_id_teacher=int(teID)) rows = class_schedule.get_day_rows() data[teID]['classes'][day] = rows data[teID]['classes_count'] += len(rows) return data
def classes(): """ Function returns a list of classes today """ locID = request.vars['locID'] # Set today while looking at configured timezone now = pytz.utc.localize(datetime.datetime.now()) tz = pytz.timezone(TIMEZONE) local_dt = now.astimezone(tz) today = datetime.date(local_dt.year, local_dt.month, local_dt.day) date_formatted = today.strftime(DATE_FORMAT) date = datestr_to_python(DATE_FORMAT, date_formatted) pretty_date = date.strftime('%B %d, %Y') location = db.school_locations(locID) # go_back response.back = A(SPAN(_class='glyphicon glyphicon-chevron-left'), _href=URL('index'), _class='pull-right') response.title = location.Name response.subtitle = SPAN(T('Classes'), ' ', ' ', pretty_date) response.view = 'selfcheckin/default.html' response.logout = get_logout() cs = ClassSchedule(date, filter_id_school_location=locID) rows = cs.get_day_rows() header = THEAD(TR( TH(T('Time')), TH(T('Class type')), TH(), )) table = TABLE(header, _class='table table-striped table-hover') for i, row in enumerate(rows): repr_row = list(rows[i:i + 1].render())[0] time = repr_row.classes.Starttime + ' - ' + repr_row.classes.Endtime link = os_gui.get_button('noicon', URL('checkin', vars={ 'clsID': row.classes.id, 'date': date_formatted }), title=T("Go to check-in"), _class='pull-right') tr = TR(TD(time), TD(repr_row.classes.school_classtypes_id), TD(link)) table.append(tr) return dict(content=table, logout=get_logout())
def get_classes(): """ List upcoming classes for today :return: """ date_received = request.vars['date'] date = datestr_to_python("%Y-%m-%d", date_received) set_headers() from openstudio.os_class_schedule import ClassSchedule cs = ClassSchedule(date, # filter_starttime_from=time_from ) return dict(classes=cs.get_day_list())
def classes_get_day(date, filter_id_school_classtype, filter_id_school_location, filter_id_school_level, filter_id_teacher): """ :param weekday: ISO weekday (1-7) :return: List of classes for day """ from openstudio.os_class_schedule import ClassSchedule cs = ClassSchedule(date, filter_id_school_classtype=filter_id_school_classtype, filter_id_school_location=filter_id_school_location, filter_id_school_level=filter_id_school_level, filter_id_teacher=filter_id_teacher, filter_public=True, sorting='starttime') return cs.get_day_list()
def my_classes(): """ creates page that displays the classes tought montlhy :return: """ response.title = T("Employee Portal") response.subtitle = SPAN(T("My classes"), XML(' • ')) response.view = 'ep/only_content.html' if session.ep_my_classes_month is None or session.ep_my_classes_year is None: session.ep_my_classes_year = TODAY_LOCAL.year session.ep_my_classes_month = TODAY_LOCAL.month table = TABLE(_class='table table-hover') table.append( THEAD( TR( TH(), TH(T('Date')), TH(T('Time')), TH(T('Location')), TH(T('Class Type')), TH(), #sub requested #TH(), # actions ))) date = datetime.date(session.ep_my_classes_year, session.ep_my_classes_month, 1) last_day = get_last_day_month(date) for each_day in range(1, last_day.day + 1): # list days day = datetime.date(session.ep_my_classes_year, session.ep_my_classes_month, each_day) class_schedule = ClassSchedule(date=day, filter_id_teacher=auth.user.id) rows = class_schedule.get_day_rows() for i, row in enumerate(rows): repr_row = list(rows[i:i + 1].render())[0] result = class_schedule._get_day_row_status(row) status_marker = result['marker'] button = '' sub_requested = '' if day >= TODAY_LOCAL: open_class = db.classes_otc(classes_id=row.classes.id, ClassDate=day, Status='open') if not open_class: button = os_gui.get_button('noicon', URL('request_sub', vars={ 'clsID': row.classes.id, 'date': day, 'teachers_id': auth.user.id }), title='Find sub', _class='pull-right', btn_class='btn-success') else: sub_requested = os_gui.get_label('primary', T("Sub requested")) button = os_gui.get_button( 'noicon', URL('cancel_request_sub', vars={'cotcID': open_class.id}), title='Cancel', _class='pull-right', btn_class='btn-warning') tr = TR( TD(status_marker, _class='td_status_marker'), TD(day.strftime(DATE_FORMAT)), TD(repr_row.classes.Starttime, '- ', repr_row.classes.Endtime), TD(repr_row.classes.school_locations_id), TD(repr_row.classes.school_classtypes_id), TD(sub_requested), TD(button)) table.append(tr) form_subtitle = get_form_subtitle(session.ep_my_classes_month, session.ep_my_classes_year, request.function, _class='col-md-8') response.subtitle.append(form_subtitle['subtitle']) month_chooser = form_subtitle['month_chooser'] current_month = form_subtitle['current_month'] header_tools = month_chooser + current_month return dict(header_tools=header_tools, content=table)
def staff_holidays_set_status(sthID, status, apply_teacher2): """ This function sets the status for classes during a teachers' holiday """ from openstudio.os_shift import Shift holiday = db.teachers_holidays(sthID) teachers_id = holiday.auth_teacher_id startdate = holiday.Startdate enddate = holiday.Enddate # Find classes delta = datetime.timedelta(days=1) current_date = startdate changed = 0 while current_date <= enddate: # find all classes for teacher and set them as open weekday = current_date.isoweekday() cs = ClassSchedule(current_date, filter_id_teacher=teachers_id) rows = cs.get_day_rows() for row in rows: cotcID = row.classes_otc.id if cotcID: record = db.classes_otc(cotcID) if not record is None: # final check to see if we really get something from the db # we have a record if status != 'normal': record.Status = status record.update_record() else: """ if the status is normal: check if there are any other changes otherwise just delete. """ change = False fields = [ record.school_locations_id, record.school_classtypes_id, record.Starttime, record.Endtime, record.auth_teacher_id, record.auth_teacher_id2, record.Description ] for field in fields: if not field is None or field == '': change = True if not change: query = (db.classes_otc.id == cotcID) result = db(query).delete() elif status != 'normal': # no record found, insert one (status normal doesn't need a record) db.classes_otc.insert(classes_id=row.classes.id, ClassDate=current_date, Status=status) # Shift status staff_schedule = StaffSchedule(current_date, filter_id_employee=teachers_id) shifts = staff_schedule.get_day_list(show_id=True) for shift in shifts: shift = Shift(shift['id'], current_date) # apply new status if status == 'normal': shift.set_status_normal() elif status == 'open': shift.set_status_open() elif status == 'cancelled': shift.set_status_cancelled() current_date += delta session.flash = T("Changed class statuses")
def _schedule_get(year, week, sorting, TeacherID, ClassTypeID, LocationID, LevelID): # classes data = dict() data['classes'] = dict() for day in range(1, 8): date = iso_to_gregorian(int(year), int(week), int(day)) class_schedule = ClassSchedule(date, filter_id_school_classtype=ClassTypeID, filter_id_school_location=LocationID, filter_id_school_level=LevelID, filter_id_teacher=TeacherID, filter_public=True, sorting=sorting) key = str(NRtoDay(day)) class_data = dict(classes=class_schedule.get_day_list(), date=date) data['classes'][key] = class_data # Teachers and classtypes this week teacher_ids_this_week = [] classtype_ids_this_week = [] location_ids_this_week = [] weekdays = [ T('Monday'), T('Tuesday'), T('Wednesday'), T('Thursday'), T('Friday'), T('Saturday'), T('Sunday') ] for weekday in weekdays: for cls in data['classes'][weekday]['classes']: # check teachers if 'TeacherID' in cls and cls[ 'TeacherID'] not in teacher_ids_this_week: teacher_ids_this_week.append(cls['TeacherID']) if 'TeacherID2' in cls and cls[ 'TeacherID2'] not in teacher_ids_this_week: teacher_ids_this_week.append(cls['TeacherID2']) # check classtypes if 'ClassTypeID' in cls and cls[ 'ClassTypeID'] not in classtype_ids_this_week: classtype_ids_this_week.append(cls['ClassTypeID']) # check locations if 'LocationID' in cls and cls[ 'LocationID'] not in location_ids_this_week: location_ids_this_week.append(cls['LocationID']) # Define caching caching = (cache.ram, 120) if web2pytest.is_running_under_test(request, request.application): caching = None # ClassTypes classtypes = [] query = (db.school_classtypes.Archived == False) & \ (db.school_classtypes.AllowAPI == True) & \ (db.school_classtypes.id.belongs(classtype_ids_this_week)) rows = db(query).select(db.school_classtypes.id, db.school_classtypes.Name, db.school_classtypes.Color, db.school_classtypes.Link, db.school_classtypes.Description, db.school_classtypes.thumbsmall, db.school_classtypes.thumblarge, orderby=db.school_classtypes.Name, cache=caching) for row in rows: thumblarge_url = '' thumbsmall_url = '' if row.thumblarge: thumblarge_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumblarge, extension='')) if row.thumbsmall: thumbsmall_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumbsmall, extension='')) classtypes.append( dict( id=row.id, Name=row.Name, Color=row.Color, Link=row.Link, LinkThumbSmall=thumbsmall_url, LinkThumbLarge=thumblarge_url, Description=row.Description, )) data['classtypes'] = classtypes # Teachers query = (db.auth_user.trashed == False) & \ (db.auth_user.teacher == True) & \ (db.auth_user.id.belongs(teacher_ids_this_week)) teachers = [] rows = db(query).select(db.auth_user.id, db.auth_user.full_name, db.auth_user.teacher_role, db.auth_user.teacher_bio, db.auth_user.teacher_bio_link, db.auth_user.teacher_website, db.auth_user.thumbsmall, db.auth_user.thumblarge, orderby=db.auth_user.full_name, cache=caching) for row in rows: name = row.full_name thumblarge_url = '' thumbsmall_url = '' if row.thumblarge: thumblarge_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumblarge, extension='')) if row.thumbsmall: thumbsmall_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumbsmall, extension='')) teachers.append( dict( id=row.id, name=name, # for legacy purposes. Was the only one with name. Role=row.teacher_role, LinkToBio=row.teacher_bio_link, Bio=row.teacher_bio, Website=row.teacher_website, LinkThumbLarge=thumblarge_url, LinkThumbSmall=thumbsmall_url, Name=name)) data['teachers'] = teachers # Locations query = (db.school_locations.AllowAPI == True) & \ (db.school_locations.Archived == False) & \ (db.school_locations.id.belongs(location_ids_this_week)) rows = db(query).select(db.school_locations.id, db.school_locations.Name, db.school_locations.Address, db.school_locations.Color, cache=caching).as_list() data['locations'] = rows # Practice levels query = (db.school_levels.Archived == False) rows = db(query).select(db.school_levels.id, db.school_levels.Name, db.school_levels.Color, cache=caching).as_list() data['levels'] = rows return data
def schedule_get_days(): """ """ # forget session session.forget(response) # check extension result = call_check_extension() if result['error']: return result['error_msg'] else: response.view = result['view'] # check vars try: date_format = '%Y-%m-%d' user = request.vars['user'] key = request.vars['key'] date_start = request.vars['date_start'] date_start = datetime.datetime.strptime(date_start, date_format) date_start = datetime.date(date_start.year, date_start.month, date_start.day) date_end = request.vars['date_end'] date_end = datetime.datetime.strptime(date_end, date_format) date_end = datetime.date(date_end.year, date_end.month, date_end.day) if date_start > date_end: return T("date_end has to be bigger then date_start") except: return T("Missing value: user, key, date_start and date_end are \ required values, one or more was missing in your request. \ (Date format: yyyy-mm-dd)") # check auth auth_result = do_auth(user, key) if not auth_result['authenticated']: return auth_result['message'] # check for TeacherID TeacherID = None if 'TeacherID' in request.vars: TeacherID = int(request.vars['TeacherID']) # check for ClassTypeID ClassTypeID = None if 'ClassTypeID' in request.vars: ClassTypeID = int(request.vars['ClassTypeID']) # check for LocationID LocationID = None if 'LocationID' in request.vars: LocationID = int(request.vars['LocationID']) # check for LevelID LevelID = None if 'LevelID' in request.vars: LevelID = int(request.vars['LevelID']) # check for SortBy sorting = 'location' if 'SortBy' in request.vars: if request.vars['SortBy'] == 'time': sorting = 'starttime' current_date = date_start delta = datetime.timedelta(days=1) data = {} data['schedule'] = [] while current_date <= date_end: classes = [] class_schedule = ClassSchedule( current_date, filter_id_school_classtype=ClassTypeID, filter_id_school_location=LocationID, filter_id_school_level=LevelID, filter_id_teacher=TeacherID, filter_public=True, sorting=sorting, ) # Don't cache when running tests or when day == today if web2pytest.is_running_under_test( request, request.application) or current_date == TODAY_LOCAL: classes = class_schedule.get_day_list() else: cache_key = 'openstudio_api_schedule_get_days_' + str(current_date) + '_' + \ 'sorting_' + sorting + '_' + \ 'TeacherID_' + str(TeacherID) + '_' + \ 'ClassTypeID_' + str(ClassTypeID) + '_' + \ 'LocationID_' + str(LocationID) + '_' + \ 'LevelID_' + str(LevelID) classes = cache.ram(cache_key, lambda: class_schedule.get_day_list(), time_expire=CACHE_LONG) data['schedule'].append({'classes': classes, 'date': current_date}) current_date += delta # Define caching caching = (cache.ram, 120) if web2pytest.is_running_under_test(request, request.application): caching = None teacher_ids = [] classtype_ids = [] location_ids = [] level_ids = [] for day in data['schedule']: for cls in day['classes']: # check teachers if 'TeacherID' in cls and cls['TeacherID'] not in teacher_ids: teacher_ids.append(cls['TeacherID']) if 'TeacherID2' in cls and cls['TeacherID2'] not in teacher_ids: teacher_ids.append(cls['TeacherID2']) # check classtypes if 'ClassTypeID' in cls and cls['ClassTypeID'] not in classtype_ids: classtype_ids.append(cls['ClassTypeID']) # check locations if 'LocationID' in cls and cls['LocationID'] not in location_ids: location_ids.append(cls['LocationID']) # check levels if 'LevelID' in cls and cls['LevelID'] not in level_ids: level_ids.append(cls['LevelID']) # ClassTypes classtypes = [] query = (db.school_classtypes.Archived == False) & \ (db.school_classtypes.AllowAPI == True) & \ (db.school_classtypes.id.belongs(classtype_ids)) rows = db(query).select(db.school_classtypes.id, db.school_classtypes.Name, db.school_classtypes.Color, db.school_classtypes.Link, db.school_classtypes.Description, db.school_classtypes.thumbsmall, db.school_classtypes.thumblarge, orderby=db.school_classtypes.Name, cache=caching) for row in rows: thumblarge_url = '' thumbsmall_url = '' if row.thumblarge: thumblarge_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumblarge, extension='')) if row.thumbsmall: thumbsmall_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumbsmall, extension='')) classtypes.append( dict( id=row.id, Name=row.Name, Link=row.Link, Color=row.Color, LinkThumbSmall=thumbsmall_url, LinkThumbLarge=thumblarge_url, Description=row.Description, )) data['classtypes'] = classtypes # Teachers query = (db.auth_user.trashed == False) & \ (db.auth_user.teacher == True) & \ (db.auth_user.id.belongs(teacher_ids)) teachers = [] rows = db(query).select(db.auth_user.id, db.auth_user.full_name, db.auth_user.teacher_role, db.auth_user.teacher_bio, db.auth_user.teacher_bio_link, db.auth_user.teacher_website, db.auth_user.thumbsmall, db.auth_user.thumblarge, orderby=db.auth_user.full_name, cache=caching) for row in rows: name = row.full_name thumblarge_url = '' thumbsmall_url = '' if row.thumblarge: thumblarge_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumblarge, extension='')) if row.thumbsmall: thumbsmall_url = '%s://%s%s' % ( request.env.wsgi_url_scheme, request.env.http_host, URL('default', 'download', args=row.thumbsmall, extension='')) teachers.append( dict( id=row.id, name=name, # for legacy purposes. Was the only one with name. Role=row.teacher_role, LinkToBio=row.teacher_bio_link, Bio=row.teacher_bio, Website=row.teacher_website, LinkThumbLarge=thumblarge_url, LinkThumbSmall=thumbsmall_url, Name=name)) data['teachers'] = teachers # Locations query = (db.school_locations.AllowAPI == True) & \ (db.school_locations.Archived == False) & \ (db.school_locations.id.belongs(location_ids)) rows = db(query).select(db.school_locations.id, db.school_locations.Name, db.school_locations.Address, db.school_locations.Color, cache=caching).as_list() data['locations'] = rows # Practice levels query = (db.school_levels.Archived == False) & \ (db.school_levels.id.belongs(level_ids)) rows = db(query).select(db.school_levels.id, db.school_levels.Name, db.school_levels.Color, cache=caching).as_list() data['levels'] = rows ## allow all domains to request this resource ## Only enable when you really need it, server side implementation is recommended. # response.headers["Access-Control-Allow-Origin"] = "*" return dict(data=data)