Skip to content

Instantly share code, notes, and snippets.

@ralphbean
Created May 25, 2012 20:40
Show Gist options
  • Save ralphbean/2790445 to your computer and use it in GitHub Desktop.
Save ralphbean/2790445 to your computer and use it in GitHub Desktop.
# -*- coding: utf-8 -*-
'''
Created on 17.03.2012
Ported to tw2 on 25.05.2012
@author: moschlar
'''
import tw2.core as twc
import tw2.forms as twf
language_options = [x for x in enumerate((u'Brainfuck', ))]
class language_id(twf.SingleSelectField):
options = language_options
def prepare(self):
self.options = [
(lang.id, lang.name)
for lang in DBSession.query(Assignment)\
.get(self.parent.assignment_id.value).allowed_languages
]
super(language_id, self).prepare()
class SubmissionForm(twf.TableForm):
title = 'Submission'
language_options = language_options
assignment_id = twf.HiddenField()
submission_id = twf.HiddenField()
filename = twf.TextField()
source = twf.TextArea(placeholder=u'Paste your source code here', css_class='span5', rows=8)
source_file = twf.FileField(css_class='span5')
language_id = language_id
# fields = [
# HiddenField('assignment_id'), HiddenField('submission_id'),
# TextField('filename', help_text=u'Filename (e.g. Classname.java for java programs)'),
# #Autosize('source', help_text=u'Paste your source code here'),
# Label(text='OR'),
# FileField('source_file', help_text=u'Upload your source code file here'),
# SingleSelectField('language_id', options=language_options, label_text='Language', help_text=u'Select the programming language for the source code'),
# SubmitButtonTable('buttons', label_text=u'', ),
# ]
submit_help = twf.Label(text=u'''
When you click "Test", your submission will be checked against the test cases
you see on the assignment page. You are only allowed to submit if these tests
have been run successful.
If you click "Finish", your submission will be closed (and will not be
editable any more) and will be verified with the test cases visible to
you and probably some more test cases your teacher provided.
When you click "Delete" your submission will be deleted.
''')
# Hide submit field
submit_text = None
# And use my own ones
buttons = [twf.SubmitButton('test', value='Test', css_class='btn btn-primary'),
twf.SubmitButton('submit', value='Submit', css_class='btn btn-success'),
twf.SubmitButton('reset', value='Delete', css_class='btn btn-danger')]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment