Esempio n. 1
0
    def submit(self, *args, **kwargs):
        '''Create new submission for this assignment'''
        if 'manage' not in request.permissions and \
                request.user not in set(self.event.members) | set(self.event.tutorsandteachers):
            abort(403)
        if (not self.assignment.is_active and
                not request.allowance(self.assignment)):
            flash('This assignment is not active, you may not create a submission', 'warning')
            redirect(url(self.assignment.url))

        submission = Submission(
            assignment=self.assignment,
            filename=self.assignment.submission_filename or None,
            source=self.assignment.submission_template or None,
            language=self.assignment.allowed_languages[0] if self.assignment.allowed_languages else None,
            user=request.user,
            created=datetime.now(),
            modified=datetime.now(),
        )
        DBSession.add(submission)
        try:
            DBSession.flush()
        except SQLAlchemyError:
            DBSession.rollback()
            log.warn('Error creating new submission', exc_info=True)
            flash('Error creating new submission', 'error')
            redirect(url(self.assignment.url))
        else:
            redirect(url(submission.url + '/edit'))
Esempio n. 2
0
    def _judge_permissions(self):
        '''Check current users permissions for judging and generate appropriate warnings'''
        if not request.allowance(self.submission):
            abort(403)

        if self.assignment.is_active:
            flash('The assignment is still active, this submission could still be edited by the student.', 'warning')
Esempio n. 3
0
    def submit(self, *args, **kwargs):
        '''Create new submission for this assignment'''
        if 'manage' not in request.permissions and \
                request.user not in set(self.event.members) | set(self.event.tutorsandteachers):
            abort(403)
        if (not self.assignment.is_active
                and not request.allowance(self.assignment)):
            flash(
                'This assignment is not active, you may not create a submission',
                'warning')
            redirect(url(self.assignment.url))

        submission = Submission(
            assignment=self.assignment,
            filename=self.assignment.submission_filename or None,
            source=self.assignment.submission_template or None,
            language=self.assignment.allowed_languages[0]
            if self.assignment.allowed_languages else None,
            user=request.user,
            created=datetime.now(),
            modified=datetime.now(),
        )
        DBSession.add(submission)
        try:
            DBSession.flush()
        except SQLAlchemyError:
            DBSession.rollback()
            log.warn('Error creating new submission', exc_info=True)
            flash('Error creating new submission', 'error')
            redirect(url(self.assignment.url))
        else:
            redirect(url(submission.url + '/edit'))
Esempio n. 4
0
    def _judge_permissions(self):
        '''Check current users permissions for judging and generate appropriate warnings'''
        if not request.allowance(self.submission):
            abort(403)

        if self.assignment.is_active:
            flash('The assignment is still active, this submission could still be edited by the student.', 'warning')
Esempio n. 5
0
        def menu_submissions(assignment, active=None):
            # The hardest part are the submissions
            submissions = assignment.submissions_by_user(request.user,
                                                         team=True)
            if submissions.count() > 0:
                s, ss = [], []
                groups = groupby(submissions.all(), lambda s: s.user)
                for (user, subm) in groups:
                    if user == request.user:
                        ss.extend(list(subm))
                    else:
                        s.append((user.display_name, list(subm)))
                submissions = ss + s
            else:
                submissions = [(u'No Submissions', [])]

            event = assignment.sheet.event
            if request.allowance(event):
                # Which lessons are we talking about?
                lessons = [
                    l for l in event.lessons
                    if request.user in l.tutors or request.user in
                    event.teachers or 'manage' in request.permissions
                ]
                if lessons:
                    l = []
                    for lesson in lessons:
                        l.append(
                            Dummy(
                                name=u'Lesson %d: %s' %
                                (lesson.lesson_id, lesson.name),
                                url=event.url +
                                '/lessons/%d/submissions/sheet/%d/assignment/%d'
                                % (lesson.lesson_id, assignment.sheet.sheet_id,
                                   assignment.assignment_id)))
                    submissions.append(('Lessons', l))

                submissions.append((u'Similarity', [
                    Dummy(name=u'Table',
                          url=assignment.url + '/similarity/table'),
                    Dummy(name=u'List',
                          url=assignment.url + '/similarity/list'),
                    Dummy(name=u'Dendrogram',
                          url=assignment.url + '/similarity/dendrogram')
                ]))

            return menu_generic('Submissions', submissions, active)
Esempio n. 6
0
    def submit(self):
        '''Create new submission for this assignment'''
        if not self.assignment.is_active and \
                not request.allowance(self.assignment):
            flash('This assignment is not active, you may not create a submission', 'warning')
            redirect(url(self.assignment.url))

        submission = Submission(assignment=self.assignment, user=request.user,
                                created=datetime.now())
        DBSession.add(submission)
        try:
            DBSession.flush()
        except SQLAlchemyError:
            DBSession.rollback()
            log.warn('Error creating new submission', exc_info=True)
            flash('Error creating new submission', 'error')
            redirect(url(self.assignment.url))
        else:
            redirect(url(submission.url + '/edit'))
Esempio n. 7
0
File: menu.py Progetto: Ayutac/SAUCE
        def menu_submissions(assignment, active=None):
            # The hardest part are the submissions
            submissions = assignment.submissions_by_user(request.user, team=True)
            if submissions.count() > 0:
                s = []
                groups = groupby(submissions.all(), lambda s: s.user)
                for (user, subm) in groups:
                    if user == request.user:
                        s.insert(0, (user.display_name, list(subm)))
                    else:
                        s.append((user.display_name, list(subm)))
                submissions = s
            else:
                submissions = [(request.user.display_name, [Dummy(name='No Submissions', url='#')])]

            event = assignment.sheet.event
            if request.allowance(event):
                # Which lessons are we talking about?
                lessons = [l for l in event.lessons
                    if request.user in l.tutors
                        or request.user in event.teachers
                        or 'manage' in request.permissions]
                if lessons:
                    l = []
                    for lesson in lessons:
                        l.append(Dummy(name=u'Lesson %d: %s' % (lesson.lesson_id, lesson.name),
                            url=event.url + '/lessons/%d/submissions/sheet/%d/assignment/%d'
                                % (lesson.lesson_id, assignment.sheet.sheet_id, assignment.assignment_id)))
                    if request.user in event.teachers or 'manage' in request.permissions:
                        l.append(Dummy(name=u'All Submissions', url=assignment.url + '/submissions'))
                    submissions.append(('Lessons', l))

                submissions.append((u'Similarity', [
                    Dummy(name=u'Table', url=assignment.url + '/similarity/table'),
                    Dummy(name=u'List', url=assignment.url + '/similarity/list'),
                    Dummy(name=u'Dendrogram', url=assignment.url + '/similarity/dendrogram')
                ]))

            return menu_generic('Submissions', submissions, active)
Esempio n. 8
0
    def submit(self):
        '''Create new submission for this assignment'''
        if not self.assignment.is_active and \
                not request.allowance(self.assignment):
            flash(
                'This assignment is not active, you may not create a submission',
                'warning')
            redirect(url(self.assignment.url))

        submission = Submission(assignment=self.assignment,
                                user=request.user,
                                created=datetime.now())
        DBSession.add(submission)
        try:
            DBSession.flush()
        except SQLAlchemyError:
            DBSession.rollback()
            log.warn('Error creating new submission', exc_info=True)
            flash('Error creating new submission', 'error')
            redirect(url(self.assignment.url))
        else:
            redirect(url(submission.url + '/edit'))
Esempio n. 9
0
 def delete(self):
     subm_id = self.submission.id
     subm_url = self.submission.url
     try:
         if (getattr(request, 'user', None) == self.submission.user or
                 request.allowance(self.submission)):
             DBSession.delete(self.submission)
             DBSession.flush()
         else:
             #abort(403)
             flash('You have no permission to delete this Submission', 'warning')
             redirect(url(self.submission.url + '/show'))
     except SQLAlchemyError:
         DBSession.rollback()
         log.warn('Submission %d could not be deleted', self.submission.id, exc_info=True)
         flash('Submission could not be deleted', 'error')
         redirect(url(self.submission.url + '/show'))
     else:
         flash('Submission %d deleted' % (subm_id), 'ok')
         if request.referer and not subm_url in request.referer:
             # Most likely coming from the submission overview page
             redirect(request.referer)
         else:
             redirect(url(self.assignment.url))
Esempio n. 10
0
 def delete(self, *args, **kwargs):
     subm_id = self.submission.id
     subm_url = self.submission.url
     try:
         if (getattr(request, 'user', None) == self.submission.user or
                 request.allowance(self.submission)):
             DBSession.delete(self.submission)
             DBSession.flush()
         else:
             #abort(403)
             flash('You have no permission to delete this Submission', 'warning')
             redirect(url(self.submission.url + '/show'))
     except SQLAlchemyError:
         DBSession.rollback()
         log.warn('Submission %r could not be deleted', self.submission, exc_info=True)
         flash('Submission could not be deleted', 'error')
         redirect(url(self.submission.url + '/show'))
     else:
         flash('Submission %d deleted' % (subm_id), 'ok')
         if request.referer and not subm_url in request.referer:
             # Most likely coming from the submission overview page
             redirect(request.referer)
         else:
             redirect(url(self.assignment.url))