-
Notifications
You must be signed in to change notification settings - Fork 95
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
5a1363c
commit 74c1ac1
Showing
4 changed files
with
39 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,19 @@ | ||
from django import forms | ||
from django.core import validators | ||
|
||
|
||
class NullCharField(forms.CharField): | ||
""" Disables the ProhibitNullCharactersValidator, so we can clean it later on. """ | ||
def __init__(self, *args, **kwargs): | ||
super(NullCharField, self).__init__(*args, **kwargs) | ||
self.validators.remove(validators.ProhibitNullCharactersValidator()) | ||
|
||
|
||
class DsmrReadingForm(forms.Form): | ||
telegram = forms.CharField() | ||
telegram = NullCharField() | ||
|
||
def clean_telegram(self): | ||
""" Since we allow null characters, we should strip them right away. """ | ||
telegram = self.cleaned_data['telegram'] | ||
telegram = telegram.strip('\x00') | ||
return telegram |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters