Example #1
0
    def page(self, course, msgs=None):
        """ Get all data and display the page """
        msgs = msgs if msgs else []

        user_input = self.get_input()
        data, classroom = self.get_submissions(
            course, user_input)  # ONLY classrooms user wants to query
        if len(data) == 0 and not self.show_collapse(user_input):
            msgs.append(_("No submissions found"))

        classrooms = self.user_manager.get_course_aggregations(
            course)  # ALL classrooms of the course
        users = self.get_users(course)  # All users of the course
        tasks = course.get_tasks()  # All tasks of the course

        statistics = None
        if user_input.stat != "no_stat":
            statistics = compute_statistics(
                tasks, data,
                True if "with_pond_stat" == user_input.stat else False)

        if "csv" in web.input():
            return make_csv(data)

        if "download" in web.input():
            # self._logger.info("Downloading %d submissions from course %s", len(data), course.get_id())
            web.header('Content-Type', 'application/x-gzip', unique=True)
            web.header('Content-Disposition',
                       'attachment; filename="submissions.tgz"',
                       unique=True)

            # Tweak if not using classrooms : classroom['students'] may content ungrouped users
            aggregations = dict([
                (username, aggregation if course.use_classrooms() or
                 (username in aggregation['groups'][0]["students"]) else None)
                for aggregation in classroom
                for username in aggregation["students"]
            ])

            download_type = web.input(
                download_type=self._valid_formats[0]).download_type
            if download_type not in self._valid_formats:
                download_type = self._valid_formats[0]
            return self.submission_manager.get_submission_archive(
                data, list(reversed(download_type.split('/'))), aggregations)

        if user_input.limit != '' and user_input.limit.isdigit():
            data = data[:int(user_input.limit)]

        if len(data) > self._trunc_limit:
            msgs.append(
                _("The result contains more than {0} submissions. The displayed submissions are truncated.\n"
                  ).format(self._trunc_limit))
            data = data[:self._trunc_limit]
        return self.template_helper.get_renderer().course_admin.submissions(
            course, tasks, users, classrooms, data, statistics, user_input,
            self._allowed_sort, self._allowed_sort_name, self._valid_formats,
            msgs, self.show_collapse(user_input))
Example #2
0
    def page(self, course, aggregationid, task):
        """ Get all data and display the page """
        aggregation = self.database.aggregations.find_one(
            {"_id": ObjectId(aggregationid)})

        data = list(
            self.database.submissions.find(
                {
                    "username": {
                        "$in": aggregation["students"]
                    },
                    "courseid": course.get_id(),
                    "taskid": task.get_id()
                }, {
                    "text": False,
                    "response_type": False,
                    "archive": False,
                    "input": False
                }).sort([("submitted_on", pymongo.DESCENDING)]))
        data = [
            dict(
                list(f.items()) +
                [("url", self.submission_url_generator(str(f["_id"])))])
            for f in data
        ]

        if "csv" in web.input():
            return make_csv(data)

        # Get best submissions (submission for evaluation)
        # Need this for statistics computation
        # Not really optimized for now...
        user_tasks = list(
            self.database.user_tasks.find(
                {
                    "username": {
                        "$in": aggregation["students"]
                    },
                    "courseid": course.get_id(),
                    "taskid": task.get_id()
                }, {
                    "submissionid": 1,
                    "_id": 0
                }))
        best_submissions_list = [u["submissionid"] for u in user_tasks
                                 ]  # list containing ids of best submissions
        for d in data:
            d["best"] = d[
                "_id"] in best_submissions_list  # mark best submissions

        statistics = compute_statistics(task, data)

        return self.template_helper.get_renderer(
        ).course_admin.aggregation_task(course, aggregation, task, data,
                                        statistics)
Example #3
0
    def page(self, course, msgs=None):
        """ Get all data and display the page """
        msgs = msgs if msgs else []

        user_input = self.get_input()
        data, limit, above_limit = self.submissions_from_user_input(
            course, user_input, msgs)  # ONLY audiences user wants to query
        if len(data) == 0 and not self.show_collapse(user_input):
            msgs.append(_("No submissions found"))

        users = self.get_users(course)  # All users of the course
        tasks = course.get_tasks()  # All tasks of the course

        statistics = None
        if user_input.stat != "no_stat":
            statistics = compute_statistics(
                tasks, data,
                True if "with_pond_stat" == user_input.stat else False)

        if "csv" in web.input():
            return make_csv(data)

        if "download" in web.input():
            download_type = web.input(
                download_type=self._valid_formats[0]).download_type
            if download_type not in self._valid_formats:
                download_type = self._valid_formats[0]

            archive, error = self.submission_manager.get_submission_archive(
                course, data,
                list(reversed(download_type.split('/'))) + ["submissionid"])
            if not error:
                # self._logger.info("Downloading %d submissions from course %s", len(data), course.get_id())
                web.header('Content-Type', 'application/x-gzip', unique=True)
                web.header('Content-Disposition',
                           'attachment; filename="submissions.tgz"',
                           unique=True)
                return archive
            else:
                msgs.append(
                    _("The following submission could not be prepared for download: {}"
                      ).format(error))

        if above_limit:
            msgs.append(
                _("The result contains more than {0} submissions. The displayed submissions are truncated. You can modify this value in the advanced query tab.\n"
                  ).format(limit))

        course_audiences = self.user_manager.get_course_audiences(course)
        return self.template_helper.get_renderer().course_admin.submissions(
            course, tasks, users, course_audiences, data, statistics,
            user_input, self._allowed_sort, self._allowed_sort_name,
            self._valid_formats, msgs, self.show_collapse(user_input))
Example #4
0
    def page(self, course, msgs=None):
        """ Get all data and display the page """
        msgs = msgs if msgs else []
        
        user_input = self.get_input()
        data, classroom = self.get_submissions(course, user_input)  # ONLY classrooms user wants to query
        if len(data) == 0 and not self.show_collapse(user_input):
            msgs.append(_("No submissions found"))

        classrooms = self.user_manager.get_course_aggregations(course)  # ALL classrooms of the course
        users = self.get_users(course)  # All users of the course
        tasks = course.get_tasks()  # All tasks of the course

        statistics = None
        if user_input.stat != "no_stat":
            statistics = compute_statistics(tasks, data, True if "with_pond_stat" == user_input.stat else False)

        if "csv" in web.input():
            return make_csv(data)
                        
        if "download" in web.input():
            # self._logger.info("Downloading %d submissions from course %s", len(data), course.get_id())
            web.header('Content-Type', 'application/x-gzip', unique=True)
            web.header('Content-Disposition', 'attachment; filename="submissions.tgz"', unique=True)

            # Tweak if not using classrooms : classroom['students'] may content ungrouped users
            aggregations = dict([(username,
                                  aggregation if course.use_classrooms() or (
                                  username in aggregation['groups'][0]["students"]) else None
                                  ) for aggregation in classroom for username in aggregation["students"]])

            download_type = web.input(download_type=self._valid_formats[0]).download_type
            if download_type not in self._valid_formats:
                download_type = self._valid_formats[0]
            return self.submission_manager.get_submission_archive(data, list(reversed(download_type.split('/'))), aggregations)

        if user_input.limit != '' and user_input.limit.isdigit():
            data = data[:int(user_input.limit)]
            
        if len(data) > self._trunc_limit:
            msgs.append(_("The result contains more than {0} submissions. The displayed submissions are truncated.\n").format(self._trunc_limit))
            data = data[:self._trunc_limit]
        return self.template_helper.get_renderer().course_admin.submissions(course, tasks, users, classrooms, data, statistics, user_input, self._allowed_sort, self._allowed_sort_name, self._valid_formats, msgs, self.show_collapse(user_input))
Example #5
0
    def page(self, course, msgs=None):
        """ Get all data and display the page """
        msgs = msgs if msgs else []

        user_input = self.get_input()
        data, audience = self.get_submissions(
            course, user_input)  # ONLY audiences user wants to query
        if len(data) == 0 and not self.show_collapse(user_input):
            msgs.append(_("No submissions found"))

        course_audiences = self.user_manager.get_course_audiences(
            course)  # ALL audiences of the course
        audiences_id = [audience["_id"] for audience in course_audiences]
        audiences_list = list(
            self.database.audiences.aggregate([{
                "$match": {
                    "_id": {
                        "$in": audiences_id
                    }
                }
            }, {
                "$unwind": "$students"
            }, {
                "$project": {
                    "audience": "$_id",
                    "students": 1
                }
            }]))
        audiences = {
            audience["_id"]: audience
            for audience in course_audiences
        }
        audiences = {
            d["students"]: audiences[d["audience"]]
            for d in audiences_list
        }

        users = self.get_users(course)  # All users of the course
        tasks = course.get_tasks()  # All tasks of the course

        statistics = None
        if user_input.stat != "no_stat":
            statistics = compute_statistics(
                tasks, data,
                True if "with_pond_stat" == user_input.stat else False)

        if "csv" in web.input():
            return make_csv(data)

        if "download" in web.input():
            download_type = web.input(
                download_type=self._valid_formats[0]).download_type
            if download_type not in self._valid_formats:
                download_type = self._valid_formats[0]

            archive, error = self.submission_manager.get_submission_archive(
                data, list(reversed(download_type.split('/'))), audiences)
            if not error:
                # self._logger.info("Downloading %d submissions from course %s", len(data), course.get_id())
                web.header('Content-Type', 'application/x-gzip', unique=True)
                web.header('Content-Disposition',
                           'attachment; filename="submissions.tgz"',
                           unique=True)
                return archive
            else:
                msgs.append(
                    _("The following submission could not be prepared for download: {}"
                      ).format(error))

        if user_input.limit != '' and user_input.limit.isdigit():
            data = data[:int(user_input.limit)]

        if len(data) > self._trunc_limit:
            msgs.append(
                _("The result contains more than {0} submissions. The displayed submissions are truncated.\n"
                  ).format(self._trunc_limit))
            data = data[:self._trunc_limit]
        return self.template_helper.get_renderer().course_admin.submissions(
            course, tasks, users, course_audiences, data, statistics,
            user_input, self._allowed_sort, self._allowed_sort_name,
            self._valid_formats, msgs, self.show_collapse(user_input))