def calculate_page_info(offset, total_students):
 if ((not (isinstance(offset, int) or offset.isdigit())) or (int(offset) < 0) or (int(offset) >= total_students)):
  offset = 0
 else:
  offset = int(offset)
 next_offset = (offset + MAX_STUDENTS_PER_PAGE_GRADE_BOOK)
 previous_offset = (offset - MAX_STUDENTS_PER_PAGE_GRADE_BOOK)
 page_num = ((offset / MAX_STUDENTS_PER_PAGE_GRADE_BOOK) + 1)
 total_pages = (int(math.ceil((float(total_students) / MAX_STUDENTS_PER_PAGE_GRADE_BOOK))) or 1)
 if ((previous_offset < 0) or (offset == 0)):
  previous_offset = None
 if (next_offset >= total_students):
  next_offset = None
 return {'previous_offset': previous_offset, 'next_offset': next_offset, 'page_num': page_num, 'offset': offset, 'total_pages': total_pages}

def calculate_page_info ( offset , total_students ) : if ( ( not ( isinstance ( offset , int ) or offset . isdigit ( ) ) ) or ( int ( offset ) < 0 ) or ( int ( offset ) >= total_students ) ) : offset = 0 else : offset = int ( offset ) next_offset = ( offset + MAX_STUDENTS_PER_PAGE_GRADE_BOOK ) previous_offset = ( offset - MAX_STUDENTS_PER_PAGE_GRADE_BOOK ) page_num = ( ( offset / MAX_STUDENTS_PER_PAGE_GRADE_BOOK ) + 1 ) total_pages = ( int ( math . ceil ( ( float ( total_students ) / MAX_STUDENTS_PER_PAGE_GRADE_BOOK ) ) ) or 1 ) if ( ( previous_offset < 0 ) or ( offset == 0 ) ) : previous_offset = None if ( next_offset >= total_students ) : next_offset = None return { 'previous_offset' : previous_offset , 'next_offset' : next_offset , 'page_num' : page_num , 'offset' : offset , 'total_pages' : total_pages }
takes care of sanitizing the offset of current page also calculates offsets for next and previous page and information like total number of pages and current page number .