-
Notifications
You must be signed in to change notification settings - Fork 16
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added restricted form field, cleaned example application
- Loading branch information
Showing
14 changed files
with
145 additions
and
80 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,3 +1,4 @@ | ||
include README.md | ||
include LICENSE | ||
include MANIFEST.in | ||
recursive-include chamber *.py *.txt *.html *.po *.mo *.xml *.xslt *.xsl *.js *.sass *.css *.png *.jpg *.jpeg *.gif |
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 |
---|---|---|
@@ -0,0 +1,53 @@ | ||
import mimetypes | ||
|
||
import magic # pylint: disable=E0401 | ||
|
||
from django.core.exceptions import ValidationError | ||
from django.utils.translation import ugettext | ||
from django.template.defaultfilters import filesizeformat | ||
|
||
|
||
class RestrictedFileValidator: | ||
|
||
def __init__(self, max_upload_size): | ||
self.max_upload_size = max_upload_size | ||
|
||
def __call__(self, data): | ||
if data.size > self.max_upload_size: | ||
raise ValidationError( | ||
ugettext('Please keep filesize under {max}. Current filesize {current}').format( | ||
max=filesizeformat(self.max_upload_size), | ||
current=filesizeformat(data.size) | ||
) | ||
) | ||
else: | ||
return data | ||
|
||
|
||
class AllowedContentTypesByFilenameFileValidator: | ||
|
||
def __init__(self, content_types): | ||
self.content_types = content_types | ||
|
||
def __call__(self, data): | ||
extension_mime_type = mimetypes.guess_type(data.name)[0] | ||
|
||
if extension_mime_type not in self.content_types: | ||
raise ValidationError(ugettext('Extension of file name is not allowed')) | ||
|
||
return data | ||
|
||
|
||
class AllowedContentTypesByContentFileValidator: | ||
|
||
def __init__(self, content_types): | ||
self.content_types = content_types | ||
|
||
def __call__(self, data): | ||
with magic.Magic(flags=magic.MAGIC_MIME_TYPE) as m: | ||
mime_type = m.id_buffer(data.file.read(1024)) | ||
data.file.seek(0) | ||
if mime_type not in self.content_types: | ||
raise ValidationError(ugettext('File content was evaluated as not supported file type')) | ||
|
||
return data |
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
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
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
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
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,10 +1,11 @@ | ||
Django==1.11 | ||
Django==2.0 | ||
diff-match-patch==20110725.1 | ||
django-germanium==2.0.5 | ||
django-germanium==2.1.0 | ||
six==1.10.0 | ||
coverage==4.0.2 | ||
pyprind==2.9.9 | ||
coveralls==1.1 | ||
filemagic==1.6 | ||
unidecode==0.4.20 | ||
pillow==4.1.1 | ||
-e ../ |
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