Example #1
0
    def get(self):
        # First, check that the logged in user is an instructor
        instructor = utils.check_privilege(model.Role.instructor)
        if not instructor:
            # Send them home and short circuit all other logic
            return self.redirect('/')
        # end

        # Otherwise, create a logout url
        logout_url = users.create_logout_url(self.request.uri)
        # And get the course and section names from the page
        course_name = self.request.get('course')
        selected_section_name = self.request.get('section')
        # Grab all the courses and sections for the logged in instructor
        template_values = utils.get_template_all_courses_and_sections(
            instructor, course_name.upper(), selected_section_name.upper())
        logout_url = users.create_logout_url(self.request.uri)
        template_values['logouturl'] = logout_url
        if 'selectedSectionObject' in template_values:
            # If so, grab that section from the template values
            current_section = template_values['selectedSectionObject']
            if current_section.students:
                # template_values['students'] = current_section.students
                template_values['num_std'] = len(current_section.students)
            if current_section.rounds:
                template_values['rounds'] = current_section.rounds
            if current_section.groups:
                template_values['num_group'] = current_section.groups
        from src import config
        template_values['documentation'] = config.DOCUMENTATION
        template = utils.jinja_env().get_template(
            'instructor/show_responses.html')
        self.response.write(template.render(template_values))
Example #2
0
    def get(self):
        """
        HTTP GET method to retrieve the list of students from the datastore.
        """
        # First, check that the logged in user is an instructor
        instructor = utils.check_privilege(model.Role.instructor)
        if not instructor:
            # Send them home and short circuit all other logic
            return self.redirect('/')
        # end

        # Otherwise, create a logout url
        logout_url = users.create_logout_url(self.request.uri)
        # Get the course and section name from the webpage
        course_name = self.request.get('course')
        selected_section_name = self.request.get('section')
        # And start building the template values
        template_values = utils.get_template_all_courses_and_sections(instructor, course_name.upper(),
                                                                      selected_section_name.upper())
        template_values['logouturl'] = logout_url
        from src import config
        template_values['documentation'] = config.DOCUMENTATION
        # Set the template and render the page
        template = utils.jinja_env().get_template('instructor/list_students.html')
        self.response.write(template.render(template_values))
Example #3
0
    def get(self):
        """
        HTTP GET method to retrieve the responses.
        """
        # First, check that the logged in user is an instructor
        instructor = utils.check_privilege(model.Role.instructor)
        if not instructor:
            # Send them home and short circuit all other logic
            return self.redirect('/')
        # end

        # Create logout url
        logout_url = users.create_logout_url(self.request.uri)
        # And grab the course and section name from the page
        course_name = self.request.get('course')
        selected_section_name = self.request.get('section')
        # And grab all the other courses and sections for this instructor
        template_values = utils.get_template_all_courses_and_sections(
            instructor, course_name, selected_section_name)
        # Now check that the section from the webpage actually corresponded
        # to an actual section in this course, and that the template was set
        if 'selectedSectionObject' in template_values:
            # If so, grab that section from the template values
            current_section = template_values['selectedSectionObject']
            # And set the round
            template_values['round'] = current_section.rounds
            # Create a new dict for the responses
            resp = {}
            # And loop over the number of rounds (indexed at 1 for initial)
            for i in range(1, current_section.rounds + 1):
                # if seq. discussion and round==2, grab all the groups
                if not current_section.has_rounds and i == 2:
                    # extract all responses in each group
                    groups = model.Group.query(
                        ancestor=current_section.key).fetch()
                    all_seq_responses = []
                    for g in groups:
                        seq_responses = model.SeqResponse.query(
                            ancestor=g.key).order(
                                model.SeqResponse.index).fetch()
                        all_seq_responses += seq_responses
                    template_values['seq_responses'] = all_seq_responses
                else:
                    round_i = model.Round.get_by_id(i,
                                                    parent=current_section.key)
                    response = model.Response.query(
                        ancestor=round_i.key).fetch()
                    # response is a list of all the responses for the round i
                    if response:
                        resp[str(i)] = response
                    # Add the responses to the template values
                    template_values['responses'] = resp
        # end
        # And set the template and render the page
        template_values['logouturl'] = logout_url
        from src import config
        template_values['documentation'] = config.DOCUMENTATION
        template = utils.jinja_env().get_template('instructor/responses.html')
        self.response.write(template.render(template_values))
Example #4
0
 def get(self):
     """
     HTTP GET method to retrieve the list of instructors currently added to the app.
     """
     user = users.get_current_user()
     if user:
         logout_url = users.create_logout_url(self.request.uri)
         from src import config
         template_values = {
             'documentation': config.DOCUMENTATION,
             'logouturl': logout_url
         }
         instructors = model.Instructor.query().fetch()
         if instructors:
             template_values['instructors'] = instructors
         template = utils.jinja_env().get_template('admin.html')
     else:
         login_url = users.create_login_url(self.request.uri)
         template_values = {
             'loginurl': login_url
         }
         template = utils.jinja_env().get_template('login.html')
     self.response.write(template.render(template_values))
Example #5
0
    def get(self):
        """
        HTTP GET Method to render the ``/groups`` page for the logged in Instructor.

        """
        # First, check that the logged in user is an instructor
        instructor = utils.check_privilege(model.Role.instructor)
        if not instructor:
            # Send them home and short circuit all other logic
            return self.redirect('/')
        # end

        # Otherwise, create a logout url
        logout_url = users.create_logout_url(self.request.uri)
        # And get the course and section names from the page
        course_name = self.request.get('course')
        selected_section_name = self.request.get('section')
        # Grab all the courses and sections for the logged in instructor
        template_values = utils.get_template_all_courses_and_sections(instructor,
                                                                      course_name.upper(),
                                                                      selected_section_name.upper())
        # Now check that the section from the webpage actually corresponded
        # to an actual section in this course, and that the template was set
        if 'selectedSectionObject' in template_values:
            # If so, grab that section from the template values
            current_section = template_values['selectedSectionObject']
            # Check that the current section has at least one round
            if current_section.rounds > 0:

                # Grab the responses from the initial question
                response = model.Response.query(
                    ancestor=model.Round.get_by_id(1, parent=current_section.key).key).fetch()

                no_answer_students = []
                # And loop over the students in this section
                for stu in current_section.students:
                    flag = True
                    # Loop over the responses
                    for res in response:
                        # And check when the response matches the student
                        if res.student == stu.email:
                            # And set the group of the response to the
                            # group of the student who made that response
                            res.group = stu.group
                            flag = False
                            # end
                    # end
                    if flag:
                        no_answer_students.append(stu)
                # end
                # Add the responses and current group to the template values
                template_values['no_answer_students'] = no_answer_students
                template_values['responses'] = response
                template_values['group'] = current_section.groups
                # end
        # end
        # Set the template and render the page
        template_values['logouturl'] = logout_url
        from src import config
        template_values['documentation'] = config.DOCUMENTATION
        template = utils.jinja_env().get_template('instructor/groups.html')
        self.response.write(template.render(template_values))
Example #6
0
    def get(self):
        instructor_tmp = utils.check_privilege(model.Role.instructor)
        instructor = model.Instructor.get_by_id(instructor_tmp.email)
        course = model.Course.get_by_id(instructor.export_course,
                                        parent=instructor.key)
        section = model.Section.get_by_id(course.export_section,
                                          parent=course.key)
        students = section.students
        selector = section.export_info
        selector = selector.split()
        count = 0
        export_rounds = {}
        # print selector
        while count < len(selector):
            if int(selector[count]) in export_rounds.keys():
                export_rounds[int(selector[count])].append(
                    int(selector[count + 1]))
            else:
                export_rounds[int(selector[count])] = []
                export_rounds[int(selector[count])].append(
                    int(selector[count + 1]))
            count += 2
        # print export_rounds
        rounds = model.Round.query(ancestor=section.key).fetch()
        template_values = {}
        output_students = []
        output_seq_rounds = {}
        output_options = {}
        output_comments = {}
        output_responses = {}
        output_summary = {}
        # export_rounds contain {key, value}, where key is student and value is round
        for i in export_rounds.keys():
            output_students.append(students[i])
            output_seq_rounds[students[i].email] = []
            output_options[students[i].email] = []
            output_comments[students[i].email] = []
            output_responses[students[i].email] = []
            output_summary[students[i].email] = []
            for j in export_rounds[i]:
                output_seq_rounds[students[i].email].append(j)
                flag = False
                if section.has_rounds:  # TODO Also for last and first round in seq
                    responses = model.Response.query(
                        ancestor=rounds[j - 1].key).fetch()
                    for resp in responses:
                        utils.log('resp = ' + str(resp))
                        if resp.student == students[i].email:
                            output_options[students[i].email].append(
                                resp.option)
                            output_comments[students[i].email].append(
                                resp.comment)
                            output_responses[students[i].email].append(
                                resp.response)
                            output_summary[students[i].email].append(
                                resp.summary)
                            flag = True
                    if not flag:
                        output_options[students[i].email].append('NA')
                        output_comments[students[i].email].append('NA')
                        output_responses[students[i].email].append('NA')
                        output_summary[students[i].email].append('NA')
                else:
                    responses = model.SeqResponse.query(
                        ancestor=rounds[j - 1].key).fetch()
                    utils.log('responses = ' + str(responses))
                    for resp in responses:
                        utils.log('resp = ' + str(resp))
                        if resp.author == students[i].email:
                            output_options[students[i].email].append('NA')
                            output_comments[students[i].email].append(
                                resp.text)
                            output_responses[students[i].email].append('NA')
                            output_summary[students[i].email].append('NA')
                            flag = True
                        if not flag:
                            output_options[students[i].email].append('NA')
                            output_comments[students[i].email].append('NA')
                            output_responses[students[i].email].append('NA')
                            output_summary[students[i].email].append('NA')

        template_values['students'] = output_students
        template_values['seq_rounds'] = output_seq_rounds
        template_values['comments'] = output_comments
        template_values['responses'] = output_responses
        template_values['option'] = output_options
        template_values['summary'] = output_summary
        template = utils.jinja_env().get_template(
            'instructor/show_html_responses.html')
        self.response.write(template.render(template_values))
Example #7
0
    def render_template(self, student, section):
        # update the database to the current round based on time
        database_round = utils.get_current_round(section)
        # Get the requested round number from the page
        current_round = self.request.get('round')
        # Now check that the round number passed in actually exists, and set
        # the requested round number appropriately if not
        if current_round:
            requested_round_number = int(current_round)
        else:
            requested_round_number = section.current_round
        # end

        # Grab the requested round
        requested_round = model.Round.get_by_id(requested_round_number, parent=section.key)
        # And check that it's not null
        if not requested_round:
            # Error if so
            self.redirect('/error?code=104')
        else:
            # Otherwise we need to set up our template values, create empty dict
            template_values = {}
            # Grab the deadline from the requested round
            deadline = requested_round.deadline
            # And the current time
            current_time = datetime.datetime.now()
            # And check if we're dealing with an expired round
            if deadline < current_time or requested_round_number < section.current_round:
                # Set the template value if so
                template_values['expired'] = True
            # end
            # Check if we're on the last round
            if requested_round.is_quiz and requested_round_number > 1:
                template_values['last_round'] = True
            # end
            # Now, just grab all the other generic values we need directly
            # template_values['deadline'] = datetime.datetime.strptime(requested_round.deadline, '%Y-%m-%dT%H:%M')
            template_values['deadline'] = requested_round.deadline
            template_values['sectionKey'] = self.request.get('section')
            template_values['rounds'] = section.current_round
            template_values['num_total_rounds'] = section.rounds
            template_values['show_name'] = not section.is_anonymous

            # Send round names
            if section.has_rounds:
                if section.rounds > 3:
                    disc_round_names = ['Round ' + str(i) for i in range(1, section.rounds - 2)] + ['Latest Posts']
                else:
                    disc_round_names = ['Round 1']
            else:
                disc_round_names = ['Discussion']

            round_names = ['Initial Submission'] + disc_round_names + ['Final Submission']
            template_values['round_names'] = round_names

            logout_url = users.create_logout_url(self.request.uri)
            template_values['logouturl'] = logout_url
            from src import config
            template_values['documentation'] = config.DOCUMENTATION
            template_values['curr_page'] = requested_round_number

            # Now we need to check if it's the initial or summary question
            if requested_round.is_quiz:
                # And set template values for quiz round
                quiz_view_template(student, requested_round, template_values)
                # And set the right template
                template = utils.jinja_env().get_template('students/round.html')
            else:
                # Otherwise, set up template values for appropriate discussion round
                if section.has_rounds:
                    self.discussion_view_template(student, section, requested_round_number, template_values)
                    # And set the right template
                    template = utils.jinja_env().get_template('students/discussion.html')
                else:
                    self.seq_discussion_view_template(student, section, template_values)
                    template_values['description'] = requested_round.description
                    template = utils.jinja_env().get_template('students/seq_discussion.html')
            # end
            # Now, render it.
            self.response.write(template.render(template_values))
Example #8
0
    def get(self):
        """
        HTTP GET method to retrieve the rounds.
        """
        # First, check that the logged in user is an instructor
        instructor = utils.check_privilege(model.Role.instructor)
        if not instructor:
            # Send them home and short circuit all other logic
            return self.redirect('/')
        # end

        # Now create a logout url
        logout_url = users.create_logout_url(self.request.uri)
        # Grab the course and section name from the webpage
        course_name = self.request.get('course')
        selected_section_name = self.request.get('section')
        # And get all the courses and sections for this instructor
        template_values = utils.get_template_all_courses_and_sections(
            instructor, course_name.upper(), selected_section_name.upper())
        # Add the name of the current/local timezone to the template.
        template_values['tz'] = utils.tzname()
        # Now check that the section from the webpage actually corresponded
        # to an actual section in this course, and that the template was set
        if 'selectedSectionObject' in template_values:
            # If so, grab that section from the template values
            current_section = template_values['selectedSectionObject']
            # Set the current active round
            template_values['activeRound'] = current_section.current_round
            # Send the current time stamp back to the view to do comparisons with
            template_values['now'] = datetime.datetime.now()
            # And grab all the rounds for this section
            # rounds = model.Round.query(ancestor=current_section.key).filter(model.Round.type != 4).fetch()
            rounds = model.Round.fetch_real_rounds(current_section.key)
            # Double check that there are actually rounds already created
            if rounds:
                # And set the template values
                template_values['rounds'] = rounds
                # Create an empty list to hold the discussion rounds
                discussion_rounds = []
                # And loop over all of the rounds for this section
                for r in rounds:
                    # Set the initial question
                    if r.number == 1:
                        template_values['initialQuestion'] = r
                    elif r.is_quiz:
                        # And if not the lead-in question, but still a quiz
                        # it must be the summary round
                        template_values['summaryQuestion'] = r
                    else:
                        # Otherwise, it's just a discussion round
                        discussion_rounds.append(r)
                        # end
                # end
                # Set the discussion round template values
                template_values['discussionRounds'] = discussion_rounds
            # end
            # Check to see if the summary round was set in the template
            if 'summaryQuestion' in template_values:
                # If so, set the next round to the total number of rounds
                template_values['nextRound'] = current_section.rounds
            else:
                # Otherwise, it must be set to the number of rounds plus
                # one (to account for the eventual summary round)
                template_values['nextRound'] = current_section.rounds + 1
                # end
                template_values['anon'] = current_section.is_anonymous
                template_values['round_structure'] = current_section.has_rounds

        # end
        # Set the template and render the page
        template_values['logouturl'] = logout_url
        from src import config
        template_values['documentation'] = config.DOCUMENTATION
        template = utils.jinja_env().get_template('instructor/rounds.html')
        self.response.write(template.render(template_values))
Example #9
0
    def get(self):
        """
        HTTP GET method to retrieve the group responses.
        """
        # First, check that the logged in user is an instructor
        instructor = utils.check_privilege(model.Role.instructor)
        if not instructor:
            # Send them home and short circuit all other logic
            return self.redirect('/')
        # end

        # TODO: Display seq. responses, like in response.py

        # Otherwise, create a logout url
        logout_url = users.create_logout_url(self.request.uri)
        # And get the course and section name from the page
        course_name = self.request.get('course')
        selected_section_name = self.request.get('section')
        # And grab the other courses and sections from this instructor
        template_values = utils.get_template_all_courses_and_sections(
            instructor, course_name, selected_section_name)
        # Now check that the section from the webpage actually corresponded
        # to an actual section in this course, and that the template was set
        if 'selectedSectionObject' in template_values:
            # If so, grab the current section from the template values
            current_section = template_values['selectedSectionObject']
            # Set the rounds and groups
            template_values['round'] = current_section.rounds
            template_values['groups'] = current_section.groups
            # And check that groups have actually been assigned
            if current_section.groups > 0:
                # Create a new dict for responses
                resp = {}
                # Loop over the groups (indexed by 1)
                for g in range(1, current_section.groups + 1):
                    # And loop over the rounds (indexed by 1)
                    for r in range(1, current_section.rounds + 1):
                        # Now set an empty list for each group and round
                        resp['group_' + str(g) + '_' + str(r)] = []
                        # end
                # end
                # Loop over the number of rounds (indexed by 1)
                for r in range(1, current_section.rounds + 1):
                    # Grab the responses for that round from the db
                    responses = model.Response.query(
                        ancestor=model.Round.get_by_id(r, parent=current_section.key).key).fetch()
                    # Double check that the responses actually exist
                    if responses:
                        # And loop over the responses
                        for res in responses:
                            # And loop over the students in this section
                            for s in current_section.students:
                                # Check that the email of the student
                                # and the email of the response match
                                # and that the student is in a group
                                if s.email == res.student and s.group != 0:
                                    # Set the alias of the response
                                    res.alias = s.alias
                                    # Append the response to the appropriate
                                    # group and round
                                    resp['group_' + str(s.group) + '_' + str(r)].append(res)
                                    break
                                    # end
                                    # end
                                    # end
                                    # end
                # end
                # And set the template values for all the responses
                template_values['responses'] = resp
                # end
        # end
        # And set the template and render the page
        template_values['logouturl'] = logout_url
        from src import config
        template_values['documentation'] = config.DOCUMENTATION
        template = utils.jinja_env().get_template('instructor/groups_responses.html')
        self.response.write(template.render(template_values))