def student_Deploy_Upload(requests, course_title): response = {} try: processLogin.studentVerification(requests) if requests.method == "GET": student_Deploy_Base(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', response) accountNum = requests.POST.get("accountNum") #string of account number ipAddress = requests.POST.get("ipaddress") #string of IP address requests.POST = requests.POST.copy() requests.POST['course_title'] = course_title if accountNum != "": student_Deploy_AddAccount(requests) if ipAddress != "": try: student_Deploy_AddIP(requests) requests.session['newIP'] = ipAddress return student_Monitor_Base(requests) except: traceback.print_exc() return student_Deploy_Base(requests)
def student_Deploy_Standard_Base(requests, response=None): if response == None: response = {'student_Deploy_Base': 'active'} try: processLogin.studentVerification(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', response) if requests.method == 'GET': course_title = requests.GET.get('course_title') else: course_title = requests.POST.get('course_title') try: classObj = utilities.getStudentClassObject(requests, course_title) credentialsObj = classObj.awscredential team_number = classObj.team_number if team_number != None: team_members = Class.objects.filter( course_section=classObj.course_section).filter( team_number=team_number) for team_member in team_members: if team_member.awscredential == None: team_member.awscredential = credentialsObj team_member.save() response['account_number'] = '' response['servers'] = [] response['servers_count'] = 0 response['course_title'] = course_title response[ 'course_section_id'] = classObj.course_section.course_section_id if credentialsObj != None: account_number = credentialsObj.account_number response['account_number'] = account_number response['servers'] = utilities.getAllServers(account_number) response['servers_count'] = len(response['servers']) except Exception as e: traceback.print_exc() response[ 'error_message'] = 'Error during retrieval of information (Student Deploy Standard): ' + str( e.args[0]) return render( requests, "Module_TeamManagement/Student/ITOpsLabStudentDeployStd.html", response) return render( requests, "Module_TeamManagement/Student/ITOpsLabStudentDeployStd.html", response)
def student_Monitor_Base(requests): response = {"student_Monitor_Base": "active"} try: processLogin.studentVerification(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', {}) response['server_ip'] = requests.GET.get('server_ip') if requests.method == 'GET': course_title = requests.GET.get('course_title') else: course_title = requests.POST.get('course_title') try: response['server_status'] = [] response['webapp_status'] = [] response['webapp_metric'] = {} response['course_title'] = course_title studentClassObj = utilities.getStudentClassObject( requests, course_title) AWS_Credentials = studentClassObj.awscredential team_number = studentClassObj.team_number if AWS_Credentials != None: account_number = AWS_Credentials.account_number if response['server_ip'] == None: servers = utilities.getAllServers(account_number) if len(servers) > 0: response['server_ip'] = servers[0]['server_ip'] if response['server_ip'] != None: response = utilities.getMonitoringStatus( account_number, team_number, response) response = utilities.getMetric(response['server_ip'], response) tz = pytz.timezone('Asia/Singapore') response['last_updated'] = str(datetime.datetime.now(tz=tz))[:19] except Exception as e: traceback.print_exc() response[ 'error_message'] = 'Error during retrieval of information (Student Monitoring): ' + str( e.args[0]) return render( requests, "Module_TeamManagement/Student/ITOpsLabStudentMonitor.html", response) return render(requests, "Module_TeamManagement/Student/ITOpsLabStudentMonitor.html", response)
def student_Deploy_Base(requests): response = {'student_Deploy_Base': 'active'} try: processLogin.studentVerification(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', response) if requests.method == 'GET': course_title = requests.GET.get('course_title') else: course_title = requests.POST.get('course_title') coursesec = "" student_email = requests.user.email coursesec = requests.session['courseList_updated'][course_title]['id'] class_studentObj = Class.objects.filter(student=student_email).get( course_section=coursesec) try: awsAccountNumber = class_studentObj.awscredential response[ 'submittedAccNum'] = awsAccountNumber # Could be None or aws credentials object except: response['submittedAccNum'] = None try: awsAccountNumber = class_studentObj.awscredential awsImageList = awsAccountNumber.imageDetails.all( ) # Could be None or aws image object Currently take first accountNumber = awsAccountNumber.account_number consistent = False for image in awsImageList: if accountNumber in image.sharedAccNum: response['awsImage'] = image response['approvalStatus'] = True consistent = True break if consistent != True: response['awsImage'] = None response['approvalStatus'] = False except: response['awsImage'] = None response['approvalStatus'] = False response["studentDeployBase"] = "active" response["course_title"] = course_title return render(requests, "Module_TeamManagement/Student/ITOpsLabStudentDeploy.html", response)
def student_Stats(requests): ''' Check if user is authenticated aka session ''' context = {} # Redirect user to login page if not authorized and student try: processLogin.studentVerification(requests) except: logout(requests) return render(requests,'Module_Account/login.html',context) context = {"stud_stats" : "active"} return render(requests,"Module_TeamManagement/Student/studentStatistics.html",context)
def student_Team(requests): context = {} # Redirect user to login page if not authorized and student try: processLogin.studentVerification(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', context) context = {"student_Team": "active", 'course': {}} studentList = [] module = requests.GET.get('module') student_email = requests.user.email if student_email == None: context['message'] = 'Please specify a username' return render(requests, "Module_TeamManagement/Student/studentTeam.html", context) studentObj = Student.objects.get(email=student_email) classObj = Class.objects.all().filter( student=studentObj, course_section=module ) #Will return queryset containing 1 row unless has multiple teams in same class for enrolled_class in classObj: #Should contain 1 row if enrolled_class.team_number != None: team_list = Class.objects.all().filter( team_number=enrolled_class.team_number).filter( course_section=enrolled_class.course_section) for student_class_model in team_list: studentList.append(student_class_model.student ) #List containing student models context['team'] = studentList context['teamno'] = enrolled_class.team_number # Reads web scrapper results trailResults = utilities.populateTrailheadInformation( requests, student_email) context.update(trailResults) context['module'] = classObj[0].course_section.course_section_id context['user'] = studentObj context['message'] = 'Successful retrieval of student\'s team' #print(context) return render(requests, "Module_TeamManagement/Student/studentTeam.html", context)
def student_Deploy_AddIP(requests): response = {} try: processLogin.studentVerification(requests) if requests.method == "GET": response['error_message'] = "Wrong entry to form" return render( requests, "Module_TeamManagement/Student/ITOpsLabStudentDeploy.html", response) except: logout(requests) return render(requests, 'Module_Account/login.html', response) utilities.addAWSKeys(requests) utilities.addServerDetails(requests=requests)
def student_Deploy_AddAccount(requests): response = {} try: processLogin.studentVerification(requests) if requests.method == "GET": response['error_message'] = "Wrong entry to form" return render( requests, "Module_TeamManagement/Student/ITOpsLabStudentDeploy.html", response) except: logout(requests) return render(requests, 'Module_Account/login.html', response) utilities.addAWSCredentials( requests) #creates an incomplete account object
def aboutCloudtopus(requests): context={} userEmail = requests.user.email try: processLogin.studentVerification(requests) context['userTypeExtension'] = "Module_TeamManagement/Student/studentBase.html" except: try: processLogin.InstructorVerification(requests) context['userTypeExtension'] = "Module_TeamManagement/Instructor/instructorBase.html" except: logout(requests) return render(requests, 'Module_Account/login.html', response) return render(requests,"Module_TeamManagement/aboutCloudtopus.html",context)
def home(requests): context = {} # Redirect user to login page if not authorized and student try: processLogin.studentVerification(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', context) context["home"] = "active" requests.session['userType'] = "Student" student_email = requests.user.email all_SocialAccount = SocialAccount.objects.all() for each_SocialAccount in all_SocialAccount: data = each_SocialAccount.extra_data if data['email'] == student_email: requests.session['user_picture'] = data['picture'] requests.session['user_name'] = data['name'].replace('_', '').strip() # Populates the info for the side nav bar for instructor utilities.populateRelevantCourses(requests, studentEmail=student_email) # Reads web scrapper results trailResults = utilities.populateTrailheadInformation( requests, student_email) context.update(trailResults) # Get number of weeks since school term start and reamining weeks till school term ends past_weeks, remaining_weeks = utilities.getRemainingWeeks() if past_weeks != None and remaining_weeks != None: context['past_weeks'] = past_weeks context['remaining_weeks'] = remaining_weeks context['progress'] = (past_weeks / (past_weeks + remaining_weeks)) * 100 else: context['past_weeks'] = 0 context['remaining_weeks'] = 0 context['progress'] = 0 return render(requests, "Module_TeamManagement/Student/studentHome.html", context)
def test_student_verification(self): self.student = Student.objects.create(email="*****@*****.**",username ="******",firstname="Martin",lastname="Teo") request = self.factory.get('/home/') request.user = self.student try: processLogin.studentVerification(request) response = True except: response = False self.assertTrue(response) request.user = None try: processLogin.studentVerification(request) response = True except: response = False self.assertFalse(response) Student.objects.all().delete()
def student_Deploy_Standard_AddAccount(requests): response = {'student_Deploy_Standard_AddAccount': 'active'} try: processLogin.studentVerification(requests) except: logout(requests) return render(requests, 'Module_Account/login.html', response) new_account_number = None if requests.POST.get( 'new_account_number') == '' else requests.POST.get( 'new_account_number') old_account_number = None if requests.POST.get( 'old_account_number') == '' else requests.POST.get( 'old_account_number') course_section_id = requests.POST.get('course_section_id') new_account_number = new_account_number.strip() #print('New account number: ' + str(new_account_number)) #print('Old account number: ' + str(old_account_number)) #print('Course Section ID: ' + str(course_section_id)) try: if new_account_number == None: raise Exception('Please enter a valid account number') if new_account_number != old_account_number: try: new_credentialsObj = AWS_Credentials.objects.create( account_number=new_account_number) new_credentialsObj.save() except: student_classObjs = Class.objects.filter( student=requests.user.email) student_account_list = [] for student_classObj in student_classObjs: if student_classObj.awscredential != None: student_account_list.append( student_classObj.awscredential.account_number) if new_account_number in student_account_list: new_credentialsObj = AWS_Credentials.objects.get( account_number=new_account_number) else: new_credentialsObj = AWS_Credentials.objects.get( account_number=new_account_number) #raise Exception('That account number is already in use, please use a different one') if old_account_number != None: querySet = Class.objects.filter( awscredential=old_account_number) for studentClassObj in querySet: studentClassObj.awscredential = new_credentialsObj studentClassObj.save() serverObjs = Server_Details.objects.filter( account_number=old_account_number) for serverObj in serverObjs: serverObj.delete() old_credentialsObj = AWS_Credentials.objects.get( account_number=old_account_number) old_credentialsObj.delete() else: team_members = utilities.getTeamMembersClassQuerySet(requests) for team_member in team_members: team_member.awscredential = new_credentialsObj team_member.save() else: raise Exception( 'New account number is the same as the old account number. Please state a different account number.' ) except Exception as e: traceback.print_exc() response[ 'error_message'] = 'Error during validating of new account number (Student Deploy Standard): ' + str( e.args[0]) return student_Deploy_Standard_Base(requests, response) response[ 'message'] = 'Account number have been successfully added into the system.' return student_Deploy_Standard_Base(requests, response)