def resendForm(studentId, newBlankFormIds): blankFormIds = map(lambda form: FormsDOM.getBlankFormId(form), studentsDOM.getForms(studentId)) uniqueBlankFormIds = set(blankFormIds) parentIds = studentsDOM.getParents(studentId) formIds = [] additionalBlankForms = [] for newBlankFormId in newBlankFormIds: if newBlankFormId not in uniqueBlankFormIds: for parentId in parentIds: currID = FormsDOM.createForm(newBlankFormId, None, None, True, False, [], parentId) formIds.append(currID) additionalBlankForms.append(newBlankFormId) for formId in formIds: studentsDOM.addNewFormId(studentId, formId) # return parentIds return parentIds
def getStudentProfileForm(): studentID = ObjectId(request.json['student_id']) form_id = ObjectId(request.json['form_id']) form_data = FormsDOM.getFormData(ObjectId(form_id)) blank_form_id = FormsDOM.getBlankFormId(form_id) blank_form_data = blankFormsDOM.getFormData(blank_form_id) parent_id = FormsDOM.getInfo(form_id, 'parent_id') parent_profile = parentsDOM.getParentProfile(parent_id) cleaned_parent_profile = {} cleaned_parent_profile['first_name'] = parent_profile['first_name'] cleaned_parent_profile['last_name'] = parent_profile['last_name'] cleaned_parent_profile['email'] = parent_profile['email'] form_info = {} form_info['name'] = blankFormsDOM.getFormName(blank_form_id) form_info['last_updated'] = FormsDOM.getLastUpdated(form_id) form_info['completed'] = FormsDOM.isComplete(form_id) isAuthorizedBool = isAuthorized(get_token_auth_header(), ['developer', 'admin']) return { 'form_data': form_data, 'blank_form_data': blank_form_data, 'basic_info': studentsDOM.getBasicInfo(studentID), 'parent_profile': cleaned_parent_profile, 'form_info': form_info, 'isAuthorized': isAuthorizedBool, }
def getStudentForms(): student_id = ObjectId(request.json['student_id']) curr_link = request.json['parent_key'] try: parentId = parentsDOM.get(currLink=curr_link) except AssertionError as e: raise AuthError({'wrong link': True}, 401) if studentsDOM.isArchived(student_id): raise AuthError({'archived': True}, 401) if parentsDOM.isExpired(parent_id): emailParent(parent_id, '', 'Your updated link is below:') raise AuthError({'expired': True}, 426) form_ids = studentsDOM.getAllFormIds(student_id) form_data = [] for id in form_ids: if parent_id == FormsDOM.getParentId(id): blank_form_data = FormsDOM.getBlankFormId( id) # will assert if formid does not exist form_data.append({ 'form_id': str(id), 'form_name': FormsDOM.getFormName(id), 'last_updated': FormsDOM.getLastUpdated(id), 'last_viewed': FormsDOM.getLastViewed(id), 'completed': FormsDOM.isComplete(id) }) return { 'form_data': form_data, 'student_info': studentsDOM.getBasicInfo(student_id), }
def getStudents(): blankFormIds = list( map(lambda currForm: ObjectId(currForm['id']), request.json['blankForms'])) noBlankFormFilter = len( blankFormIds) == 0 # hoping caching will reduce complexity students = studentsDOM.getStudents() studentsWithForms = [] for student in students: if noBlankFormFilter: forms_completed = 0 for form in student['form_ids']: if FormsDOM.isComplete(form): forms_completed += 1 student['forms_completed'] = str(forms_completed) + "/" + str( len(student['form_ids'])) student['completion_rate'] = forms_completed / len( student['form_ids']) del student['form_ids'] studentsWithForms.append(student) else: forms_completed = 0 forms_available = 0 for form in student['form_ids']: currFormBlankFormId = FormsDOM.getBlankFormId(form) if currFormBlankFormId in blankFormIds: if (FormsDOM.isComplete(form)): forms_completed += 1 forms_available += 1 if forms_available > 0: student['forms_completed'] = str(forms_completed) + "/" + str( forms_available) student['completion_rate'] = forms_completed / forms_available del student['form_ids'] studentsWithForms.append(student) return { 'students': studentsWithForms, 'authorized': isAuthorized(get_token_auth_header(), ['developer', 'admin']), 'forms': blankFormsDOM.getAll(), }
def getForm(): curr_link = request.json['curr_link'] try: parentId = parentsDOM.get(currLink=curr_link) except AssertionError as e: raise AuthError({'wrong link': True}, 401) if parentsDOM.isExpired(parent_id): emailParent(parent_id, '', 'Your updated link is below:') raise AuthError({'expired': True}, 426) form_id = ObjectId(request.json['form_id']) blank_form_id = FormsDOM.getBlankFormId(form_id) blank_form_data = blankFormsDOM.getFormData(blank_form_id) form_data = FormsDOM.getFormData(form_id) return { 'blank_form_data': blank_form_data, 'form_data': form_data, 'submitted': form_data != [], }