Skip to content

Instantly share code, notes, and snippets.

@moschlar
Created May 25, 2012 20:30
Show Gist options
  • Save moschlar/2790405 to your computer and use it in GitHub Desktop.
Save moschlar/2790405 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
from sauce.model import DBSession, Assignment
class SubmissionForm(twf.TableForm):
title = 'Submission'
language_options = [x for x in enumerate((u'Brainfuck', ))]
assignment_id = twf.HiddenField()
submission_id = twf.HiddenField()
filename = twf.TextField()
source = twf.TextArea(palceholder=u'Paste your source code here', css_class='span5', rows=8)
source_file = twf.FileField(css_class='span5')
language_id = twf.SingleSelectField(options=language_options)
# 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')]
def prepare(self):
super(SubmissionForm, self).prepare()
self.safe_modify('language_id')
self.language_id = self.language_id(options=[
(lang.id, lang.name)
for lang in DBSession.query(Assignment)\
.get(self.assignment_id.value).allowed_languages
])
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment