| 8 | |
| 9 | |
| 10 | class SqlField(CharField): |
| 11 | |
| 12 | def validate(self, value): |
| 13 | """ |
| 14 | Ensure that the SQL passes the blacklist. |
| 15 | |
| 16 | :param value: The SQL for this Query model. |
| 17 | """ |
| 18 | super().validate(value) |
| 19 | query = Query(sql=value) |
| 20 | |
| 21 | passes_blacklist, failing_words = query.passes_blacklist() |
| 22 | |
| 23 | error = MSG_FAILED_BLACKLIST % ", ".join( |
| 24 | failing_words) if not passes_blacklist else None |
| 25 | |
| 26 | if error: |
| 27 | raise ValidationError( |
| 28 | error, |
| 29 | code="InvalidSql" |
| 30 | ) |
| 31 | |
| 32 | |
| 33 | class QueryForm(ModelForm): |