-
Notifications
You must be signed in to change notification settings - Fork 83
Validation improvements #321
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Changes from 1 commit
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -1,7 +1,15 @@ | ||
| from django.db import models | ||
|
|
||
| from django.db.models.signals import pre_save | ||
| from django.dispatch import receiver | ||
|
|
||
| class IdeModel(models.Model): | ||
| class Meta: | ||
| abstract = True | ||
| app_label = "ide" | ||
|
|
||
|
|
||
| @receiver(pre_save) | ||
| def pre_save_full_clean_handler(sender, instance, *args, **kwargs): | ||
| """ Force IdeModels to call full_clean before save """ | ||
| if isinstance(instance, IdeModel): | ||
| instance.full_clean() |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,35 @@ | ||
| from django.core.validators import RegexValidator | ||
|
|
||
|
|
||
| class RegexHolder(object): | ||
| regex_dictionary = { | ||
| # Match major[.minor], where major and minor are numbers between 0 and 255 with no leading 0s | ||
| 'sdk_version': r'^(0|[1-9]\d?|1\d{2}|2[0-4]\d|25[0-5])(\.(0|[1-9]\d?|1\d{2}|2[0-4]\d|25[0-5]))?$', | ||
|
|
||
| # Match major.minor.0, where major and minor are numbers between 0 and 255 with no leading 0s | ||
| 'semver': r'^(0|[1-9]\d?|1\d{2}|2[0-4]\d|25[0-5])\.(0|[1-9]\d?|1\d{2}|2[0-4]\d|25[0-5])\.0$', | ||
|
|
||
| # Match a string of letters and numbers separated with underscores but not starting with a digit | ||
| 'c_identifier': r'^([a-zA-Z_][_a-zA-Z\d]*)$', | ||
|
||
|
|
||
| # Match a C identifier optionally followed by an [array index] | ||
| 'c_identifier_with_index': r'^([a-zA-Z_][_a-zA-Z\d]*)(?:\[(\d+)\])?$', | ||
|
|
||
| # Match a UUID4 | ||
| 'uuid': r'^[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-4[0-9a-fA-F]{3}-[89abAB][0-9a-fA-F]{3}-[0-9a-fA-F]{12}$', | ||
|
|
||
| # Match a valid resource file name | ||
| 'resource_file_name': r'^[/a-zA-Z0-9_(). -]+$', | ||
|
|
||
| # Match a valid c/h/js file name | ||
| 'source_file_name': r'^[/a-zA-Z0-9_.-]+\.(c|h|js)$' | ||
| } | ||
|
|
||
| def validator(self, key, message): | ||
| return [RegexValidator(self.regex_dictionary[key], message=message)] | ||
|
|
||
| def __getattr__(self, key): | ||
| return self.regex_dictionary[key.lower()] | ||
|
|
||
|
|
||
| regexes = RegexHolder() | ||
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This isn't quite right; resource IDs are prefixed and so don't have the usual start-of-identifier rules.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Fixed