Ejemplo n.º 1
0
    def post(self):
        # Insert or update personality
        words = self.request.get("personality_words").split(",")
        if app_datastore.user_exists(self.session['student_id']):
            app_datastore.insert_or_update_personality(self.session['student_id'], words)

        # Redirect to Snapshot
        self.redirect(app_domain + "snapshot")
Ejemplo n.º 2
0
    def post(self):
        # Insert or update education
        best_modules = self.request.get("modules").split(",,")
        if app_datastore.user_exists(self.session['student_id']):
            app_datastore.insert_or_update_education(self.session['student_id'], best_modules)

        # Redirect to Experience questionnaire
        self.redirect(app_domain + "experience")
Ejemplo n.º 3
0
    def post(self):
        # Insert or update aspirations
        aspirations = self.request.get("aspirations").split(",")
        if app_datastore.user_exists(self.session['student_id']):
            app_datastore.insert_or_update_aspirations(self.session['student_id'], aspirations)

        # Redirect to Education questionnaire
        self.redirect(app_domain + "education")
Ejemplo n.º 4
0
    def post(self):
        # Insert or update experience
        skills = self.request.get("skills").split(",,")
        interests = self.request.get("interests").split(",,")
        involvements = self.request.get("involvements").split(",,")
        advices = self.request.get("advices").split(",,")
        if app_datastore.user_exists(self.session['student_id']):
            app_datastore.insert_or_update_experience(self.session['student_id'], skills, interests, involvements, advices)

        # Redirect to Personality questionnaire
        self.redirect(app_domain + "personality")
Ejemplo n.º 5
0
    def get(self):
        urlfetch.set_default_fetch_deadline(10)

        # Retrieve token
        if self.session.get('is_valid') != True:
            self.session['ivle_token'] = self.request.get('token')
            self.session['is_valid'] = json.load(urllib2.urlopen('https://ivle.nus.edu.sg/api/Lapi.svc/Validate?APIKey=' + ivle_api_key + '&Token=' + self.session.get('ivle_token')))['Success']
        
        # If the user is authenticated and token is not empty
        if self.session.get('is_valid') == True and self.session.get('ivle_token') != '':

            # Initialise values
            aspirations_completed = False
            education_completed = False
            experience_completed = False
            personality_completed = False
            aspirations_html = ''
            best_modules_html = ''
            interests_html = ''
            skills_and_knowledge_html = ''
            strengths_at_work_html = ''
            involvements_html = ''
            emotions_html = ''
            strengths_as_a_friend_html = ''
            personality_best_html = ''
            advice_html = ''
            social_networks_html=''

            # If the user's session is new
            if app_datastore.user_exists(self.session.get('student_id')) == False:

                # Retrieve profile information from IVLE and remember for the current browser session
                student_profile_object = json.load(urllib2.urlopen('https://ivle.nus.edu.sg/api/Lapi.svc/Profile_View?APIKey=' + ivle_api_key + '&AuthToken=' + self.session.get('ivle_token')))['Results'][0]
                self.session['student_id'] = student_profile_object['UserID']
                self.session['student_name'] = student_profile_object['Name']
                self.session['student_email'] = student_profile_object['Email']
                self.session['student_matriculation_year'] = student_profile_object['MatriculationYear']
                self.session['student_first_major'] = student_profile_object['FirstMajor']
                self.session['student_second_major'] = student_profile_object['SecondMajor']
                self.session['student_faculty'] = student_profile_object['Faculty']
                self.session['log_identity'] = self.session.get('student_name') + " (" + self.session.get('student_id') + ")" 

                logging.debug(self.session.get('log_identity') + " has logged in")

            # If the user exists in the datastore
            if app_datastore.user_exists(self.session['student_id']):

                # Update the email session variable if there is a different email in the datastore than in IVLE
                if (app_datastore.get_user(self.session['student_id']).email != self.session['student_email']):
                    self.session['student_email'] = app_datastore.get_user(self.session['student_id']).email

                # Describe existing aspirations
                try:
                    aspirations = app_datastore.get_aspirations(self.session['student_id']).aspirations
                    aspirations_completed = app_datastore.get_aspirations(self.session['student_id']).completed
                    number_of_aspirations = len(aspirations)
                    aspiration_id = 1
                    for aspiration in aspirations:
                        if aspiration[0] in "aeiou":
                            aspirations_html += "an "
                        else:
                            aspirations_html += "a "
                        aspirations_html += aspiration
                        if aspiration_id + 1 < number_of_aspirations:
                            aspirations_html += ", "
                        elif aspiration_id + 1 == number_of_aspirations:
                            aspirations_html += " or "
                        aspiration_id += 1
                except Exception:
                    pass

                # Describe existing best modules
                try:
                    best_modules = app_datastore.get_education(self.session['student_id']).best_modules
                    education_completed = app_datastore.get_education(self.session['student_id']).completed
                    number_of_best_modules = len(best_modules)
                    if number_of_best_modules > 3:
                        remaining_best_module_count = number_of_best_modules - 3
                        best_module_id_1 = randint(0, number_of_best_modules-1)
                        best_module_id_2 = best_module_id_1
                        while (best_module_id_2 == best_module_id_1):
                            best_module_id_2 = randint(0, number_of_best_modules-1)
                        best_module_id_3 = best_module_id_1
                        while (best_module_id_3 == best_module_id_1 or best_module_id_3 == best_module_id_2):
                            best_module_id_3 = randint(0, number_of_best_modules-1)
                        best_modules_html = best_modules[best_module_id_1] + ", " + best_modules[best_module_id_2] + ", " + best_modules[best_module_id_3] + " and " + str(remaining_best_module_count) + " other module"
                        if remaining_best_module_count > 1:
                            best_modules_html += "s"
                    else:
                        i = 1
                        for best_module in best_modules:
                            best_modules_html += best_module
                            if i + 1 < number_of_best_modules:
                                best_modules_html += ", "
                            elif i + 1 == number_of_best_modules:
                                best_modules_html += " and "
                            i += 1
                except Exception:
                    pass

                # Describe existing interests
                try:
                    interests = app_datastore.get_experience(self.session['student_id']).interests
                    experience_completed = app_datastore.get_experience(self.session['student_id']).completed
                    if len(interests) > 3:
                        remaining_interest_count = len(interests) - 3
                        interest_id_1 = randint(0, len(interests)-1)
                        interest_id_2 = interest_id_1
                        while (interest_id_2 == interest_id_1):
                            interest_id_2 = randint(0, len(interests)-1)
                        interest_id_3 = interest_id_1
                        while (interest_id_3 == interest_id_1 or interest_id_3 == interest_id_2):
                            interest_id_3 = randint(0, len(interests)-1)
                        interests_html = interests[interest_id_1] + ", " + interests[interest_id_2] + ", " + interests[interest_id_3] + " and " + str(remaining_interest_count) + " other interest"
                        if remaining_interest_count > 1:
                            interests_html += "s"
                    else:
                        i = 1
                        for interest in interests:
                            interests_html += interest
                            if i + 1 < len(interests):
                                interests_html += ", "
                            elif i + 1 == len(interests):
                                interests_html += " and "
                            i += 1
                except Exception:
                    pass


                # Describe existing skills
                try:
                    sk = app_datastore.get_experience(self.session['student_id']).skills_and_knowledge
                    experience_completed = app_datastore.get_experience(self.session['student_id']).completed
                    if len(sk) > 3:
                        remaining_sk_count = len(sk) - 3
                        sk_id_1 = randint(0, len(sk)-1)
                        sk_id_2 = sk_id_1
                        while (sk_id_2 == sk_id_1):
                            sk_id_2 = randint(0, len(sk)-1)
                        sk_id_3 = sk_id_1
                        while (sk_id_3 == sk_id_1 or sk_id_3 == sk_id_2):
                            sk_id_3 = randint(0, len(sk)-1)
                        skills_and_knowledge_html = sk[sk_id_1] + ", " + sk[sk_id_2] + ", " + sk[sk_id_3] + " and " + str(remaining_sk_count) + " other skill"
                        if remaining_sk_count > 1:
                            skills_and_knowledge_html += "s"
                    else:
                        i = 1
                        for skill_or_knowledge in sk:
                            skills_and_knowledge_html += skill_or_knowledge
                            if i + 1 < len(sk):
                                skills_and_knowledge_html += ", "
                            elif i + 1 == len(sk):
                                skills_and_knowledge_html += " and "
                            i += 1
                except Exception:
                    pass

                # Describe and two strengths at work
                try:
                    personality_completed = app_datastore.get_personality(self.session['student_id']).completed
                    trait1 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[0]
                    trait2 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[1]
                    phrase1 = four_temperaments.get_random_at_work(trait1)
                    phrase2 = four_temperaments.get_random_at_work(trait2)
                    strengths_at_work_html = phrase1 + " and " + phrase2
                except Exception:
                    pass

                # Describe existing involvements
                try:
                    involvements = app_datastore.get_experience(self.session['student_id']).involvements
                    experience_completed = app_datastore.get_experience(self.session['student_id']).completed
                    if len(involvements) > 3:
                        remaining_involvement_count = len(involvements) - 3
                        involvement_id_1 = randint(0, len(involvements)-1)
                        involvement_id_2 = involvement_id_1
                        while (involvement_id_2 == involvement_id_1):
                            involvement_id_2 = randint(0, len(involvements)-1)
                        involvement_id_3 = involvement_id_1
                        while (involvement_id_3 == involvement_id_1 or involvement_id_3 == involvement_id_2):
                            involvement_id_3 = randint(0, len(involvements)-1)
                        involvements_html = involvements[involvement_id_1] + ", " + involvements[involvement_id_2] + ", " + involvements[involvement_id_3] + " and " + str(remaining_involvement_count) + " other involvement"
                        if remaining_involvement_count > 1:
                            involvements_html += "s"
                    else:
                        i = 1
                        for involvement in involvements:
                            involvements_html += involvement
                            if i + 1 < len(involvements):
                                involvements_html += ", "
                            elif i + 1 == len(involvements):
                                involvements_html += " or "
                            i += 1
                except Exception:
                    pass

                # Describe any two emotions
                try:
                    personality_completed = app_datastore.get_personality(self.session['student_id']).completed
                    trait1 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[0]
                    trait2 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[1]
                    phrase1 = four_temperaments.get_random_emotion(trait1)
                    phrase2 = four_temperaments.get_random_emotion(trait2)
                    emotions_html = phrase1 + " and " + phrase2
                except Exception:
                    pass

                # Describe any two strengths as a friend
                try:
                    personality_completed = app_datastore.get_personality(self.session['student_id']).completed
                    trait1 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[0]
                    trait2 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[1]
                    phrase1 = four_temperaments.get_random_as_a_friend(trait1)
                    phrase2 = four_temperaments.get_random_as_a_friend(trait2)
                    strengths_as_a_friend_html = phrase1 + " and " + phrase2
                except Exception:
                    pass

                # Describe any best from each dominant trait in terms of personality. There are only two dominant traits out of four.
                try:
                    personality_completed = app_datastore.get_personality(self.session['student_id']).completed
                    trait1 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[0]
                    trait2 = app_datastore.get_personality(self.session['student_id']).two_dominant_temperaments_both[1]
                    phrase1 = four_temperaments.get_random_best_in(trait1)
                    phrase2 = four_temperaments.get_random_best_in(trait2)
                    personality_best_html = phrase1 + " and " + phrase2
                except Exception:
                    pass

                # Describe any one existing advice
                try:
                    advice_html = app_datastore.get_random_advice(self.session['student_id'])
                    experience_completed = app_datastore.get_experience(self.session['student_id']).completed
                except Exception:
                    pass

                # List social networks in bullet points
                try:
                    social_networks_obj = app_datastore.get_user(self.session['student_id']).social_networks
                    for link in social_networks_obj:
                        social_networks_html+="<a href=http://" + link + "><li>http://" + link + "</li></a>"
                except Exception:
                    pass

            # else if the user is new
            else:

                # Register into the datastore
                app_datastore.insert_user(student_profile_object)
                logging.debug(self.session.get('log_identity') + " registered.")
                
            template_values = {
                # Jumbotron
                'student_name': self.session.get('student_name'),
                'student_email': self.session.get('student_email'),
                'matriculation_year': self.session.get('student_matriculation_year'),
                'first_major': self.session.get('student_first_major'),
                'second_major': self.session.get('student_second_major'),
                'faculty': self.session.get('student_faculty'),
                # Summary
                'aspirations_completed': aspirations_completed,
                'education_completed': education_completed,
                'experience_completed': experience_completed,
                'personality_completed': personality_completed,
                'best_modules': best_modules_html,
                'aspirations': aspirations_html.lower(),
                'interests': interests_html.lower(),
                'skills': skills_and_knowledge_html.lower(),
                'two_emotions_from_two_traits': emotions_html,
                'two_strengths_from_two_traits_at_work': strengths_at_work_html,
                'involvements': involvements_html,
                'two_stengths_from_two_traits_as_a_friend': strengths_as_a_friend_html,
                'two_best_from_two_traits': personality_best_html,
                'advice': advice_html,
                # Sidebar
                'gender': app_datastore.get_user(self.session['student_id']).gender,
                'country': app_datastore.get_user(self.session['student_id']).country,
                'date_of_birth': app_datastore.get_user(self.session['student_id']).date_of_birth,
                'website': app_datastore.get_user(self.session['student_id']).website,
                'social_networks': social_networks_html
            }

            template = jinja_environment.get_template('snapshot.html')
            self.response.out.write(template.render(template_values))
        else:
            self.redirect(app_domain)