Example #1
0
    def index(self, page=1, *args, **kwargs):
        '''Assignment detail page'''

        values = []

        if request.user:
            c.table = SubmissionTable(DBSession)

            values = SubmissionTableFiller(DBSession).get_value(
                assignment_id=self.assignment.id,
                user_id=request.user.id,
            )

            teams = set()
            for lesson in self.assignment.sheet.event.lessons:
                teams |= set(lesson.teams)
            teams &= set(request.user.teams)

            teammates = set()
            for team in teams:
                teammates |= set(team.members)
            teammates.discard(request.user)

            for teammate in teammates:
                values.extend(SubmissionTableFiller(DBSession).get_value(
                    assignment_id=self.assignment.id,
                    user_id=teammate.id,
                ))

        lexer_name = self.assignment.allowed_languages[0].lexer_name \
            if len(self.assignment.allowed_languages) == 1 else ''
        c.pygmentize = Pygmentize(lexer_name=lexer_name)

        return dict(page='assignments', event=self.event, assignment=self.assignment, values=values)
Example #2
0
    def __init__(self, *args, **kw):
        # /event/url/submissions
        self.event = kw.get('event', None)
        # /event/url/lesson/id/submissions
        self.lesson = kw.get('lesson', None)
        # /event/url/sheet/id/assignment/id/submissions
        self.assignment = kw.get('assignment', None)
        # /event/url/sheet/id/submissions
        self.sheet = kw.get('sheet', None)
        if self.event:
            pass
        elif self.lesson:
            self.event = self.lesson.event
        elif self.assignment:
            self.event = self.assignment.sheet.event
        elif self.sheet:
            self.event = self.sheet.event
        else:
            log.warn('SubmissionController without any filter')
            flash('You can not view Submissions without any constraint.', 'error')
            abort(400)

        # Allow access for event teacher and lesson teacher
        self.allow_only = Any(
            has('teachers', self.event),
            has('tutors', self.lesson),
#             has_teacher(self.event),
#             has_teachers(self.event),
#             has_teacher(self.lesson),
            has_permission('manage'),
            msg=u'You have no permission to manage this Lesson'
        )

        self.table = SubmissionTable(DBSession)
        self.table_filler = SubmissionTableFiller(DBSession, lesson=self.lesson)
Example #3
0
    def index(self, page=1):
        '''Submission listing page'''

        #TODO: Ugly and stolen from controllers.user

        c.table = SubmissionTable(DBSession)

        teammates = set()
        for team in request.user.teams:
            teammates |= set(team.students)
        teammates.discard(request.user)

        values = SubmissionTableFiller(DBSession).get_value(user_id=request.user.id)

        for teammate in teammates:
            values.extend(SubmissionTableFiller(DBSession).get_value(user_id=teammate.id))

        return dict(page='submissions', view=None, user=request.user, values=values)
Example #4
0
    def index(self):
        #TODO: Ugly.

        memberships = defaultdict(list)

        if request.user:
            memberships['teams'] = request.user.teams
            memberships['lessons'] = request.user._lessons
            memberships['tutored_lessons'] = request.user.tutored_lessons
            #memberships['events'] = request.user.events

        c.table = SubmissionTable(DBSession)

        #        events = set((event for event in memberships['events']))
        #        events |= set((lesson.event for lesson in memberships['lessons']))
        #        events |= set((team.lesson.event for team in memberships['teams']))
        #
        #        for event in events:
        #            for sheet in event.sheets:
        #                for assignment in sheet.assignments:
        #                    pass

        teammates = set()
        for team in memberships['teams']:
            teammates |= set(team.students)
        teammates.discard(request.user)

        values = SubmissionTableFiller(DBSession).get_value(
            user_id=request.user.id)

        for teammate in teammates:
            values.extend(
                SubmissionTableFiller(DBSession).get_value(
                    user_id=teammate.id))

        return dict(page='user',
                    user=request.user,
                    values=values,
                    memberships=memberships)
Example #5
0
    def index(self, page=1, *args, **kwargs):
        '''Assignment detail page'''

        values = []

        if request.user:
            c.table = SubmissionTable(DBSession)

            values = SubmissionTableFiller(DBSession).get_value(
                assignment_id=self.assignment.id,
                user_id=request.user.id,
            )

            teams = set()
            for lesson in self.assignment.sheet.event.lessons:
                teams |= set(lesson.teams)
            teams &= set(request.user.teams)

            teammates = set()
            for team in teams:
                teammates |= set(team.members)
            teammates.discard(request.user)

            for teammate in teammates:
                values.extend(
                    SubmissionTableFiller(DBSession).get_value(
                        assignment_id=self.assignment.id,
                        user_id=teammate.id,
                    ))

        lexer_name = self.assignment.allowed_languages[0].lexer_name \
            if len(self.assignment.allowed_languages) == 1 else ''
        c.pygmentize = Pygmentize(lexer_name=lexer_name)

        return dict(page='assignments',
                    event=self.event,
                    assignment=self.assignment,
                    values=values)
Example #6
0
    def index(self, page=1, *args, **kwargs):
        '''Submission listing page'''

        c.table = SubmissionTable(DBSession)

        #TODO: Ugly and stolen from controllers.user
#         teammates = set()
#         for team in request.user.teams:
#             teammates |= set(team.students)
#         teammates.discard(request.user)

        values = SubmissionTableFiller(DBSession).get_value(user_id=request.user.id)

#         for teammate in teammates:
#             values.extend(SubmissionTableFiller(DBSession).get_value(user_id=teammate.id))

        return dict(page='submissions', view=None, user=request.user, values=values)
Example #7
0
class SubmissionsController(TGController):

    def __init__(self, *args, **kw):
        # /event/url/submissions
        self.event = kw.get('event', None)
        # /event/url/lesson/id/submissions
        self.lesson = kw.get('lesson', None)
        # /event/url/sheet/id/assignment/id/submissions
        self.assignment = kw.get('assignment', None)
        # /event/url/sheet/id/submissions
        self.sheet = kw.get('sheet', None)
        if self.event:
            pass
        elif self.lesson:
            self.event = self.lesson.event
        elif self.assignment:
            self.event = self.assignment.sheet.event
        elif self.sheet:
            self.event = self.sheet.event
        else:
            log.warn('SubmissionController without any filter')
            flash('You can not view Submissions without any constraint.', 'error')
            abort(400)

        # Allow access for event teacher and lesson teacher
        self.allow_only = Any(
            has('teachers', self.event),
            has('tutors', self.lesson),
#             has_teacher(self.event),
#             has_teachers(self.event),
#             has_teacher(self.lesson),
            has_permission('manage'),
            msg=u'You have no permission to manage this Lesson'
        )

        self.table = SubmissionTable(DBSession)
        self.table_filler = SubmissionTableFiller(DBSession, lesson=self.lesson)

    def _before(self, *args, **kw):
        '''Prepare tmpl_context with navigation menus'''
        if self.assignment:
            c.sub_menu = menu(self.assignment, True)
        elif self.sheet:
            c.sub_menu = menu(self.sheet, True)
        elif self.event:
            c.sub_menu = menu(self.event, True)

    @expose('sauce.templates.submissions')
    def _default(self, *args, **kw):
        #TODO: This filtering really needs to be rewritten!
        filters = dict(zip(args[::2], args[1::2]))
        real_filters = dict(assignment_id=set(), user_id=set())

        if self.assignment:
            real_filters['assignment_id'] = self.assignment.id
        else:
            sheet = None
            if self.sheet:
                sheet = self.sheet
            elif 'sheet' in filters:
                try:
                    s = int(filters['sheet'])
                    sheet = DBSession.query(Sheet).filter_by(event_id=self.event.id)\
                        .filter_by(sheet_id=s).one()
                except NoResultFound:
                    pass
            if sheet:
                if 'assignment' in filters:
                    try:
                        a = int(filters['assignment'])
                        a_id = DBSession.query(Assignment.id).filter_by(sheet_id=sheet.id)\
                            .filter_by(assignment_id=a).one().id
                        real_filters['assignment_id'] |= set((a_id, ))
                    except NoResultFound:
                        pass
                else:
                    real_filters['assignment_id'] |= set((a.id for a in sheet.assignments))

        if self.event:
            # Dirty, dirty hack to properly filter assignments by event
            if real_filters['assignment_id']:
                # Only allow filters by assignments from the set event
                real_filters['assignment_id'] &= set((a.id for s in self.event.sheets for a in s.assignments))
            else:
                # Simply filter by assignments for this event
                real_filters['assignment_id'] = set((a.id for s in self.event.sheets for a in s.assignments))

        if 'lesson' in filters:
            try:
                l = int(filters['lesson'])
                q1 = DBSession.query(User.id).join(lesson_members).filter_by(lesson_id=l)
                q2 = DBSession.query(User.id).join(team_members).join(Team).filter_by(lesson_id=l)
                students = q1.union(q2)
                real_filters['user_id'] |= set((s.id for s in students))
            except SQLAlchemyError:
                pass
        if 'team' in filters:
            try:
                students = DBSession.query(User.id).join(team_members)\
                    .filter_by(team_id=int(filters['team'])).join(Team)
                if self.lesson:
                    students = students.filter_by(lesson_id=self.lesson.id)
                else:
                    #students = students.filter(Team.lesson_id.in_(l.id for l in self.event.lessons))
                    students = students.join(Team.lesson).filter_by(event_id=self.event.id)
                real_filters['user_id'] |= set((s.id for s in students))
            except SQLAlchemyError:
                pass
        if 'user' in filters:
            try:
                user_id = DBSession.query(User.id).filter_by(id=int(filters['user'])).one().id
                real_filters['user_id'] |= set((user_id, ))
            except NoResultFound:
                pass

        # Cleanup filters for performancy
        definite_filters = dict()
        for (k, v) in real_filters.iteritems():
            if v:
                if isinstance(v, (list, tuple, set)) and len(v) == 1:
                    definite_filters[k] = v.pop()
                else:
                    definite_filters[k] = v

        c.table = self.table
        values = self.table_filler.get_value(filters=definite_filters)
        return dict(page='event', view=None, values=values)