Beispiel #1
0
 class subject(twf.TableLayout):
     id = twf.HiddenField()
     code = twf.TextField(validator=twc.StringLengthValidator(max=31))
     firstname = twf.TextField(
         label="First Name",
         validator=twc.StringLengthValidator(max=63))
     lastname = twf.TextField(
         label="Last Name", validator=twc.StringLengthValidator(max=63))
     dob = twf.TextField(
         label="Date of Birth",
         validator=twc.DateTimeValidator(format="%m/%d/%Y"))
Beispiel #2
0
    class child(twf.TableForm):
        action = 'post_edit'
        id = twf.HiddenField()
        subject = twf.LabelField()
        exam = twf.LabelField()
        timestamp = twf.LabelField()
        notes = twf.TextArea(validator=twc.StringLengthValidator(max=2048),
                             rows=10,
                             cols=40)

        class operator(twf.TableLayout):
            uid = twf.SingleSelectField(label="SUNetID",
                                        options=twc.Deferred(user_list),
                                        validator=twc.Any(
                                            twc.StringLengthValidator(min=0,
                                                                      max=0),
                                            UserExists()))

        class subject(twf.TableLayout):
            id = twf.HiddenField()
            code = twf.TextField(validator=twc.StringLengthValidator(max=31))
            firstname = twf.TextField(
                label="First Name",
                validator=twc.StringLengthValidator(max=63))
            lastname = twf.TextField(
                label="Last Name", validator=twc.StringLengthValidator(max=63))
            dob = twf.TextField(
                label="Date of Birth",
                validator=twc.DateTimeValidator(format="%m/%d/%Y"))
Beispiel #3
0
 class operator(twf.TableLayout):
     uid = twf.SingleSelectField(label="SUNetID",
                                 options=twc.Deferred(user_list),
                                 validator=twc.Any(
                                     twc.StringLengthValidator(min=0,
                                                               max=0),
                                     UserExists()))
Beispiel #4
0
    def testAnyValidator(self):
        v = Any(twc.StringLengthValidator(min=5, max=6),
                twc.IpAddressValidator,
                required=True)

        self.assert_(v.required)
        try:
            v.to_python("20")
            self.assert_(False)
        except ValidationError as ve:
            self.assert_(
                ("valid IP" in ve.message and "at least 5" in ve.message),
                ve.message)

        try:
            v.to_python("xxxxxxxxxx")
            self.assert_(False)
        except ValidationError as ve:
            self.assert_(
                ("valid IP" in ve.message and "longer than 6" in ve.message),
                ve.message)

        try:
            v.to_python("xxxxx")
            self.assert_(True)
        except ValidationError as ve:
            self.assert_(False)

        try:
            v.to_python("127.0.0.1")
            self.assert_(True)
        except ValidationError as ve:
            self.assert_(False)
Beispiel #5
0
    def testAllValidator(self):
        v = All(twc.StringLengthValidator(min=9, max=9),
                twc.IpAddressValidator,
                required=True)

        self.assert_(v.required)
        try:
            v.validate_python("127.0.0.10")
            self.assert_(False)
        except ValidationError, ve:
            self.assert_(("longer than 9" in ve.message), ve.message)
Beispiel #6
0
    def testAllValidator(self):
        v = All(twc.StringLengthValidator(min=9, max=9),
                twc.IpAddressValidator,
                required=True)

        self.assert_(v.required)
        try:
            v.to_python("127.0.0.10")
            self.assert_(False)
        except ValidationError as ve:
            self.assert_(("longer than 9" in ve.message), ve.message)

        try:
            v.to_python("0.0.0.0")
            self.assert_(False)
        except ValidationError as ve:
            self.assert_(("valid IP" not in ve.message and "9" in ve.message),
                         ve.message)

        try:
            v.to_python("12345678")
            self.assert_(False)
        except ValidationError as ve:
            self.assert_(("valid IP" in ve.message and "9" in ve.message),
                         ve.message)

        try:
            v.to_python("123456789")
            self.assert_(False)
        except ValidationError as ve:
            self.assert_(("valid IP" in ve.message and "9" not in ve.message),
                         ve.message)

        try:
            v.to_python("127.0.0.1")
            self.assert_(True)
        except ValidationError as ve:
            self.assert_(False, ve.message)
Beispiel #7
0
 class child(twf.TableForm):
     action = 'post_edit'
     id = twf.HiddenField()
     series = twf.LabelField()
     acq = twf.LabelField()
     description = twf.TextArea(validator=twc.StringLengthValidator(
         max=255))
     notes = twf.LabelField()
     psd = twf.LabelField()
     physio_flag = twf.LabelField()
     tr = twf.LabelField()
     te = twf.LabelField()
     flip_angle = twf.LabelField()
     num_timepoints = twf.LabelField()
     num_slices = twf.LabelField()
     protocol_name = twf.LabelField()
     scan_type = twf.LabelField()
     num_bands = twf.LabelField()
     prescribed_duration = twf.LabelField()
     mm_per_vox = twf.LabelField()
     fov = twf.LabelField()
     acquisition_matrix = twf.LabelField()
     phase_encode_undersample = twf.LabelField()
     slice_encode_undersample = twf.LabelField()
Beispiel #8
0
class JudgementForm(twbf.HorizontalForm, twdf.CustomisedTableForm):

    title = 'Judgement'

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

    class annotations(twdf.GrowingGridLayout):
        line = twbf.TextField(validator=twc.IntValidator, css_class='span1')
        comment = twbf.TextField(validator=twc.StringLengthValidator,
                                 css_class='span6')

    comment = LargeTextArea(
        placeholder=u'Comment on the above source code',
        validator=twc.StringLengthValidator,
        rows=6,
    )
    corrected_source = SourceEditor(
        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),
        css_class='span8',
        cols=80,
        rows=24)
    grade = SmallTextField(
        placeholder=u'Grade this submission',
        validator=FloatValidator,
    )
    buttons = [
        twbf.SubmitButton('save_draft',
                          name='save_draft',
                          value='Save as draft',
                          css_class='btn'),
        twbf.SubmitButton('save_publish',
                          name='save_publish',
                          value='Save and publish'),
    ]

    @classmethod
    def validate(cls, params, state=None):
        result = super(JudgementForm, cls).validate(params, state=state)

        # Preserve which button was clicked
        save_draft = params.get('save_draft', None)
        save_publish = params.get('save_publish', None)
        if save_draft and save_publish:
            raise twc.validation.ValidationError('save_draft and save_publish')
        elif save_draft:
            result['public'] = False
        elif save_publish:
            result['public'] = True

        return result

    def prepare(self):
        self.safe_modify('source')
        try:
            self.child.c.corrected_source.mode = self.value.submission.language.lexer_name
        except AttributeError:
            pass
        super(JudgementForm, self).prepare()
Beispiel #9
0
 class child(twf.TableForm):
     action = 'post_edit'
     id = twf.HiddenField()
     owner = twf.SingleSelectField(options=twc.Deferred(get_owners), validator=twc.Required)
     name = twf.TextField(validator=twc.All(twc.StringLengthValidator(min=1), ExperimentDoesntExist('owner')))
     timestamp = twf.LabelField()
Beispiel #10
0
 class child(twf.TableLayout):
     owner = twf.SingleSelectField(options=twc.Deferred(get_owners), validator=twc.Required)
     name = twf.TextField(validator=twc.All(twc.StringLengthValidator(min=1), ExperimentDoesntExist('owner')))
Beispiel #11
0
 class child(twf.TableForm):
     action = 'post_edit'
     uid = twf.LabelField(label='SUNet ID', validator=None)
     firstname = twf.TextField(label='First Name', validator=twc.StringLengthValidator(min=1))
     lastname = twf.TextField(label='Last Name', validator=twc.StringLengthValidator(min=1))
Beispiel #12
0
 class child(twf.TableLayout):
     uid = twf.TextField(label='SUNet ID', validator=twc.StringLengthValidator(min=1))