Skip to content
This repository has been archived by the owner on Jun 18, 2020. It is now read-only.

Commit

Permalink
Fix Exceptions
Browse files Browse the repository at this point in the history
  • Loading branch information
moschlar committed Apr 5, 2016
1 parent 44e9c46 commit f55128f
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 15 deletions.
18 changes: 10 additions & 8 deletions sauce/model/assignment.py
Expand Up @@ -39,6 +39,9 @@
__all__ = ('Assignment', 'Sheet')


class ScaffoldException(Exception): pass


# secondary table for many-to-many relation
language_to_assignment = Table('language_to_assignment', metadata,
Column('language_id', Integer, ForeignKey('languages.id'), primary_key=True),
Expand Down Expand Up @@ -127,7 +130,7 @@ def clone(self, i=0, recursive=True):
a.assignment_id = i + 1 # TODO: Not uniqueness-safe
a.allowed_languages = [l for l in self.allowed_languages]
if recursive:
a.tests = [t.clone(i=i) for i, t in enumerate(self.tests)]
a.tests = [t.clone(i=j) for j, t in enumerate(self.tests)]
return a

#----------------------------------------------------------------------------
Expand Down Expand Up @@ -251,21 +254,20 @@ def strip_scaffold(self, full_source):
:type full_source: str
:rtype: str
:raises ScaffoldException: if full_source is not exactly surrounded by scaffold_{head,foot}
'''
source_lines = full_source.splitlines()

if self.submission_scaffold_head:
for a, b in zip(self.submission_scaffold_head_lines, source_lines):
for i, (a, b) in enumerate(zip(self.submission_scaffold_head_lines, source_lines)):
if a != b:
print a, b # TODO
raise Exception, 'scaffold_head' # TODO
raise ScaffoldException('scaffold_head', i, a, b)
source_lines = source_lines[self.submission_scaffold_head_lines_len:]

if self.submission_scaffold_foot:
for a, b in zip(reversed(self.submission_scaffold_foot_lines), reversed(source_lines)):
for i, (a, b) in enumerate(zip(reversed(self.submission_scaffold_foot_lines), reversed(source_lines))):
if a != b:
print a, b # TODO
raise Exception, 'scaffold_foot' # TODO
raise ScaffoldException('scaffold_foot', i, a, b)
source_lines = source_lines[:-self.submission_scaffold_foot_lines_len]

return '\n'.join(source_lines)
Expand Down Expand Up @@ -344,7 +346,7 @@ def clone(self, i=0, recursive=True):
if attr.key != 'id'))
s.sheet_id = i + 1 # TODO: Not uniqueness-safe
if recursive:
s.assignments = [a.clone(i=i, recursive=recursive) for i, a in enumerate(self.assignments)]
s.assignments = [a.clone(i=j, recursive=recursive) for j, a in enumerate(self.assignments)]
return s

#----------------------------------------------------------------------------
Expand Down
2 changes: 1 addition & 1 deletion sauce/model/event.py
Expand Up @@ -145,7 +145,7 @@ def clone(self, i=0, recursive=True,
if lessons:
e.lessons = [l.clone(i=i, teams=teams) for l in self.lessons]
if recursive:
e.sheets = [s.clone(i=i, recursive=recursive) for i, s in enumerate(self.sheets)]
e.sheets = [s.clone(i=j, recursive=recursive) for j, s in enumerate(self.sheets)]
return e

#----------------------------------------------------------------------------
Expand Down
3 changes: 0 additions & 3 deletions sauce/widgets/lib.py
Expand Up @@ -77,9 +77,6 @@ def make_cm_line_number_update_func(**kwargs):

def make_cm_readonly_lines_func(value, **kwargs):
'''
# TODO: Comment does not apply anymore
We use .split('\n') instead of .splitlines() because their behaviour
differs when the last character is \n.
:type value: sauce.model.submission.Submission
'''
Expand Down
9 changes: 6 additions & 3 deletions sauce/widgets/submission.py
Expand Up @@ -51,12 +51,15 @@
class SubmissionValidator(twc.Validator):

def _validate_python(self, data, state=None):
''':type data: dict'''
'''
:type data: dict
:type: sauce.model.Assignment
:type: sauce.model.Submission
'''
controller = request.controller_state.controller
assignment = controller.assignment
''':type: sauce.model.Assignment'''
submission = controller.submission
''':type: sauce.model.Submission'''

language = data['language']
if language not in assignment.allowed_languages:
Expand Down

0 comments on commit f55128f

Please sign in to comment.