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

Commit

Permalink
Show scaffold on judgement, too
Browse files Browse the repository at this point in the history
  • Loading branch information
moschlar committed Jan 9, 2015
1 parent 87e1629 commit 8ecde1c
Show file tree
Hide file tree
Showing 5 changed files with 95 additions and 49 deletions.
1 change: 1 addition & 0 deletions sauce/templates/submission_judge.mak
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
<%inherit file="local:templates.submission" />
<%namespace file="local:templates.submission" import="details" />

## TODO: Make full=false work with correct line numbers
${details(submission, full=False)}

<h2>Judgement</h2>
Expand Down
40 changes: 31 additions & 9 deletions sauce/widgets/judgement.py
Original file line number Diff line number Diff line change
Expand Up @@ -29,15 +29,17 @@
import tw2.dynforms as twdf
import tw2.bootstrap.forms as twbf

from sauce.widgets.lib import ays_js
from sauce.widgets.widgets import SmallTextField, LargeSourceEditor, AdvancedWysihtml5
from sauce.widgets.lib import ays_js, make_cm_line_number_update_func, make_ays_init, make_cm_changes_save
from sauce.widgets.widgets import MyHorizontalLayout, SmallTextField, LargeSourceEditor, AdvancedWysihtml5, SourceDisplay
from sauce.widgets.validators import FloatValidator, BleachValidator


class JudgementForm(twbf.HorizontalForm, twdf.CustomisedTableForm):

title = 'Judgement'

child = MyHorizontalLayout

assignment_id = twbf.HiddenField(validator=twc.IntValidator)
submission_id = twbf.HiddenField(validator=twc.IntValidator)

Expand All @@ -48,13 +50,17 @@ class annotations(twdf.GrowingGridLayout):
comment = AdvancedWysihtml5(
placeholder=u'Comment on the above source code',
)

scaffold_head = SourceDisplay()
corrected_source = LargeSourceEditor(
placeholder=u'Correct the above source code',
help_text=u'It is currently not possible for you to run the test cases '
'with this corrected source code. Sorry!',
validator=twc.StringLengthValidator(strip=False),
fullscreen=True,
)
scaffold_foot = SourceDisplay()

grade = SmallTextField(
placeholder=u'Grade this submission',
validator=FloatValidator,
Expand Down Expand Up @@ -87,17 +93,33 @@ def validate(cls, params, state=None):
return result

def prepare(self):
self.safe_modify('source')
try:
self.safe_modify('corrected_source')
self.child.c.corrected_source.mode = self.value.submission.language.lexer_name
except AttributeError:
pass
try:
self.value.scaffold_head = self.value.submission.scaffold_head
self.safe_modify('scaffold_head')
self.child.c.scaffold_head.mode = self.value.submission.language.lexer_name
self.child.c.scaffold_head.no_display = not self.value.submission.scaffold_show
except AttributeError: # pragma: no cover
pass
try:
self.value.scaffold_foot = self.value.submission.scaffold_foot
self.safe_modify('scaffold_foot')
self.child.c.scaffold_foot.mode = self.value.submission.language.lexer_name
self.child.c.scaffold_foot.no_display = not self.value.submission.scaffold_show
except AttributeError: # pragma: no cover
pass

super(JudgementForm, self).prepare()

# TODO: Are-you-sure hook for Wysihtml5
self.add_call(twj.jQuery(twc.js_symbol('document')).ready(twc.js_symbol(u'''\
function () {
$("%(form)s").areYouSure();
$("%(corrected_source)s + .CodeMirror")[0].CodeMirror.on('changes', function(instance) { instance.save(); });
}''' % {'form': self.selector or 'Form', 'corrected_source': self.child.c.corrected_source.selector})))
self.add_call(make_cm_line_number_update_func(
scaffold_head=self.child.c.scaffold_head.selector,
source=self.child.c.corrected_source.selector,
scaffold_foot=self.child.c.scaffold_foot.selector))

self.add_call(make_ays_init(form=self.selector or 'Form'))

self.add_call(make_cm_changes_save(source=self.child.c.corrected_source.selector))
45 changes: 45 additions & 0 deletions sauce/widgets/lib.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,8 +25,53 @@
import tw2.core as twc
import tw2.jquery as twj




ays_js = twc.JSLink(
link='/javascript/jquery.are-you-sure.js',
resources=[twj.jquery_js],
location='headbottom',
)


def make_ays_init(**kwargs):
return twj.jQuery(twc.js_symbol('document')).ready(twc.js_symbol(u'''\
function () {
$("%(form)s").areYouSure();
}''' % kwargs))


# TODO: Are-you-sure hook for Wysihtml5


def make_cm_changes_save(**kwargs):
return twj.jQuery(twc.js_symbol('document')).ready(twc.js_symbol(u'''\
function () {
$("%(source)s + .CodeMirror")[0].CodeMirror.on('changes', function(instance) { instance.save(); });
}''' % kwargs))


def make_cm_line_number_update_func(**kwargs):
return twj.jQuery(twc.js_symbol('document')).ready(twc.js_symbol(u'''\
function () {
var cm_head = $("%(scaffold_head)s + .CodeMirror")[0].CodeMirror;
var cm_source = $("%(source)s + .CodeMirror")[0].CodeMirror;
var cm_foot = $("%(scaffold_foot)s + .CodeMirror")[0].CodeMirror;
var cm_head_cnt = cm_head.getDoc().lineCount();
var cm_source_doc = cm_source.getDoc();
function updateFootFirstLineNumber(instance, changeObj) {
var lines = cm_head_cnt + cm_source_doc.lineCount() + 1;
cm_foot.setOption('firstLineNumber', lines);
}
// Initially set firstLineNumber for source
cm_source.setOption('firstLineNumber', cm_head_cnt + 1);
// Initially set firstLineNumber for scaffold_foot
updateFootFirstLineNumber();
cm_source.on('changes', updateFootFirstLineNumber);
}''' % kwargs))
48 changes: 8 additions & 40 deletions sauce/widgets/submission.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,8 +41,8 @@
except ImportError: # pragma: no cover
from tw2.forms.bootstrap import SingleSelectField as _SingleSelectField

from sauce.widgets.lib import ays_js
from sauce.widgets.widgets import MediumTextField, MediumMixin, LargeSourceEditor, SourceDisplay, SimpleWysihtml5
from sauce.widgets.lib import ays_js, make_cm_line_number_update_func, make_ays_init, make_cm_changes_save
from sauce.widgets.widgets import MyHorizontalLayout, MediumTextField, MediumMixin, LargeSourceEditor, SourceDisplay, SimpleWysihtml5
from sauce.model import Language, Assignment

log = logging.getLogger(__name__)
Expand Down Expand Up @@ -114,14 +114,6 @@ class LanguageSelectField(MediumMixin, _SingleSelectField):
validator = twsa.RelatedValidator(entity=Language)


class MyHorizontalLayout(twbf.HorizontalLayout):

@property
def children_non_hidden(self):
return [c for c in super(MyHorizontalLayout, self).children_non_hidden
if not getattr(c, 'no_display', None)]


class SubmissionForm(twbf.HorizontalForm):

title = 'Submission'
Expand Down Expand Up @@ -178,47 +170,23 @@ def prepare(self):
try:
self.safe_modify('scaffold_head')
self.child.c.scaffold_head.mode = self.value.language.lexer_name
# self.child.c.scaffold_head.filename = self.value.filename
self.child.c.scaffold_head.no_display = not self.value.scaffold_show
except AttributeError: # pragma: no cover
pass
try:
self.safe_modify('scaffold_foot')
self.child.c.scaffold_foot.mode = self.value.language.lexer_name
# self.child.c.scaffold_foot.filename = self.value.filename
self.child.c.scaffold_foot.no_display = not self.value.scaffold_show
except AttributeError: # pragma: no cover
pass

super(SubmissionForm, self).prepare()

self.add_call(twj.jQuery(twc.js_symbol('document')).ready(twc.js_symbol(u'''\
function () {
var cm_head = $("%(scaffold_head)s + .CodeMirror")[0].CodeMirror;
var cm_source = $("%(source)s + .CodeMirror")[0].CodeMirror;
var cm_foot = $("%(scaffold_foot)s + .CodeMirror")[0].CodeMirror;
var cm_head_cnt = cm_head.getDoc().lineCount();
var cm_source_doc = cm_source.getDoc();
function updateFootFirstLineNumber(instance, changeObj) {
var lines = cm_head_cnt + cm_source_doc.lineCount() + 1;
cm_foot.setOption('firstLineNumber', lines);
}
// Initially set firstLineNumber for source
cm_source.setOption('firstLineNumber', cm_head_cnt + 1);
// Initially set firstLineNumber for scaffold_foot
updateFootFirstLineNumber();
self.add_call(make_cm_line_number_update_func(
scaffold_head=self.child.c.scaffold_head.selector,
source=self.child.c.source.selector,
scaffold_foot=self.child.c.scaffold_foot.selector))

cm_source.on('changes', updateFootFirstLineNumber);
}''' % {'scaffold_head': self.child.c.scaffold_head.selector,
'source': self.child.c.source.selector,
'scaffold_foot': self.child.c.scaffold_foot.selector})))
self.add_call(make_ays_init(form=self.selector or 'Form'))

self.add_call(twj.jQuery(twc.js_symbol('document')).ready(twc.js_symbol(u'''\
function () {
$("%(form)s").areYouSure();
$("%(source)s + .CodeMirror")[0].CodeMirror.on('changes', function(instance) { instance.save(); });
}''' % {'form': self.selector or 'Form', 'source': self.child.c.source.selector})))
self.add_call(make_cm_changes_save(source=self.child.c.source.selector))
10 changes: 10 additions & 0 deletions sauce/widgets/widgets.py
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@


__all__ = [
'MyHorizontalLayout',
'AdvancedWysihtml5',
'SimpleWysihtml5',
'SourceDisplay',
Expand All @@ -31,6 +32,15 @@
]


class MyHorizontalLayout(twb.HorizontalLayout):

@property
def children_non_hidden(self):
return [c for c in super(MyHorizontalLayout, self).children_non_hidden
if not getattr(c, 'no_display', None)]



class LargeMixin(object):
css_class = 'span8'

Expand Down

0 comments on commit 8ecde1c

Please sign in to comment.