class ResetVoteForm(Form): uuid = UUIDField(label="Ticket UUID") def clean_uuid(self): uuid_value = self.cleaned_data['uuid'] if not Ticket.objects.filter(spent=True, uuid=uuid_value).exists(): raise ValidationError("Incorrect UUID") return uuid_value
class RegistrationStep2UrlForm(Form): """ Only required for URL validation """ reg = UUIDField(required=True, widget=HiddenInput()) key = CharField(max_length=500, min_length=250, required=True, widget=HiddenInput())
class ImageUploadForm(Form): files = FileField(widget=ClearableFileInput(attrs={'multiple': True})) album = ModelChoiceField( queryset=Album.objects.all(), required=False, ) # because select doesn't have html readonly attribute # https://stackoverflow.com/questions/368813/html-form-readonly-select-tag-input hidden_album_id = UUIDField( widget=HiddenInput(), required=False, )
class DeviceRegisterForm(DeviceUpdateForm): config_uuid = UUIDField() field_order = ['config_uuid'] def clean_config_uuid(self): config_uuid = self.cleaned_data['config_uuid'] if Config.objects.filter(id=config_uuid).exists() == False: raise ValidationError( 'UUID does not correspond to a valid device configuration') return config_uuid def __init__(self, *args, **kwargs): super(DeviceRegisterForm, self).__init__(*args, **kwargs) self.helper = FormHelper() self.helper.form_method = 'post' self.helper.form_class = 'form-horizontal' self.helper.add_input( Submit('submit', 'Submit', css_class='btn-primary'))
class AuthApiKeyForm(Form): apikey = UUIDField(label='Apikey', help_text='Enter you apikey as username') def __init__(self, *args, **kwargs): self.request = kwargs.pop('request') super(AuthApiKeyForm, self).__init__(*args, **kwargs) def clean(self): data = self.cleaned_data user = authenticate(key=data.get('apikey')) if not user: raise ValidationError('invalid api key') if not user.is_staff or user.dmt_user < 1: raise ValidationError('permission denied') login(self.request, user) return data
def test_clean_value_with_dashes(self): field = UUIDField() value = field.clean("550e8400-e29b-41d4-a716-446655440000") self.assertEqual(value, uuid.UUID("550e8400e29b41d4a716446655440000"))
def test_uuidfield_2(self): field = UUIDField(required=False) value = field.clean('') self.assertIsNone(value)
class SendMissionForm(Form): robot_uuid = UUIDField() mission_id = IntegerField()
def test_uuidfield_4(self): field = UUIDField() value = field.prepare_value( uuid.UUID('550e8400e29b41d4a716446655440000')) self.assertEqual(value, '550e8400e29b41d4a716446655440000')
def test_uuidfield_3(self): field = UUIDField() with self.assertRaises(ValidationError) as cm: field.clean('550e8400') self.assertEqual(cm.exception.messages[0], 'Enter a valid UUID.')
def test_clean_value_with_dashes(self): field = UUIDField() value = field.clean('550e8400-e29b-41d4-a716-446655440000') self.assertEqual(value, uuid.UUID('550e8400e29b41d4a716446655440000'))
def test_uuidfield_4(self): field = UUIDField() value = field.prepare_value( uuid.UUID("550e8400e29b41d4a716446655440000")) self.assertEqual(value, "550e8400-e29b-41d4-a716-446655440000")
def test_uuidfield_4(self): field = UUIDField() value = field.prepare_value(uuid.UUID('550e8400e29b41d4a716446655440000')) self.assertEqual(value, '550e8400e29b41d4a716446655440000')
def test_uuidfield_2(self): field = UUIDField(required=False) value = field.clean('') self.assertEqual(value, None)
def test_uuidfield_1(self): field = UUIDField() value = field.clean('550e8400e29b41d4a716446655440000') self.assertEqual(value, uuid.UUID('550e8400e29b41d4a716446655440000'))
def test_uuidfield_3(self): field = UUIDField() with self.assertRaisesMessage(ValidationError, 'Enter a valid UUID.'): field.clean('550e8400')
def test_uuidfield_2(self): field = UUIDField(required=False) self.assertIsNone(field.clean("")) self.assertIsNone(field.clean(None))
def test_uuidfield_3(self): field = UUIDField() with self.assertRaisesMessage(ValidationError, "Enter a valid UUID."): field.clean("550e8400")
def test_uuidfield_2(self): field = UUIDField(required=False) value = field.clean("") self.assertIsNone(value)
def test_uuidfield_1(self): field = UUIDField() value = field.clean("550e8400e29b41d4a716446655440000") self.assertEqual(value, uuid.UUID("550e8400e29b41d4a716446655440000"))
class KnotForm(Form): cloud = ChoiceField(choices=((1,'Meshblu'), (2,'Fiware'))) servername = CharField(label='Hostname', max_length=100) port = IntegerField(max_value=0xffff) uuid = UUIDField() token = CharField(label='Token', max_length=100)