{ "info": { "author": "Andr\u00e9s Moya Vel\u00e1zquez", "author_email": "andres.moya@kaleidos.net", "bugtrack_url": null, "classifiers": [ "Development Status :: 5 - Production/Stable", "Framework :: Django", "Intended Audience :: Developers", "License :: OSI Approved :: BSD License", "Operating System :: OS Independent", "Programming Language :: Python", "Topic :: Internet :: WWW/HTTP" ], "description": "django-validated-file\n=====================\n\n.. image:: https://travis-ci.org/kaleidos/django-validated-file.png?branch=master\n :target: https://travis-ci.org/kaleidos/django-validated-file\n\n.. image:: https://coveralls.io/repos/kaleidos/django-validated-file/badge.png?branch=master\n :target: https://coveralls.io/r/kaleidos/django-validated-file?branch=master\n\n.. image:: https://pypip.in/v/django-validated-file/badge.png\n :target: https://crate.io/packages/django-validated-file\n\n.. image:: https://pypip.in/d/django-validated-file/badge.png\n :target: https://crate.io/packages/django-validated-file\n\n\nThis Django app adds a new field type, ValidatedFileField, that add the\ncapability of checking the document size and types the user may send.\n\nInstallation\n------------\n\n * Download and install package with python setup.py install.\n * Note that this package depends on python-magic (to check field types).\n * Add 'validatedfile' to your INSTALLED_APPS in settings.py.\n\nValidate single file\n--------------------\n\nCreate a model and add a field of type ValidatedFileField. You can add a maximum size in bytes\nand a list of valid mime types that will be allowed. The list of all mime types is available\nhere: http://www.iana.org/assignments/media-types/index.html::\n\n from django.db import models\n from validatedfile.fields import ValidatedFileField\n\n class TestModel(models.Model):\n the_file = ValidatedFileField(\n null = True,\n blank = True,\n upload_to = 'testfile',\n max_upload_size = 10240,\n content_types = ['image/png'])\n\nThe model can be used in forms or model forms like a normal FileField. If a user tries to upload\na file with too much size or without a valid type, a form validation error will occur.\n\n\nValidate quota usage\n--------------------\n\nThis example also checks the total size of all files uploaded by one user::\n\n (in models.py)\n\n from django.contrib.auth.models import User\n from django.db import models\n from validatedfile.fields import ValidatedFileField\n\n class TestModel(models.Model):\n user = models.ForeignKey(\n User,\n null = False,\n blank = False,\n related_name = 'test_models')\n the_file = ValidatedFileField(\n null = True,\n blank = True,\n upload_to = 'testfile',\n max_upload_size = 10240,\n content_types = ['image/png'])\n\n (in forms.py)\n\n from django import forms\n from validatedfile.fields import QuotaValidator\n from models.py import TestModel\n\n class TestModelForm(models.ModelForm):\n the_file = forms.FileField(\n required = True,\n validators = [QuotaValidator(max_usage = 102400)])\n\n class Meta:\n model = TestModel\n fields = ['the_file']\n\n def __init__(self, user, *args, **kwargs):\n super(TestModelForm, self).__init__(*args, **kwargs)\n self.user = user\n self.fields['the_file'].validators[0].update_quota(\n items = self.user.test_models.all(),\n attr_name = 'the_file',\n )\n\n def exceeds_quota(self):\n return self.fields['the_file'].validators[0].quota.exceeds()\n\n def save(self, *args, **kwargs):\n model = super(TestModelForm, self).save(commit = False)\n model.user = self.user\n model.save()\n\n\nNote on DOS attacks\n-------------------\n\nImportant note: the check of the file size is made by Django once the whole file has been uploaded\nto the server and stored in a temp directory (or in memory if the file is small). Thus, this is\nuseful to guarantee the quota of the users, for example, but will not stop an attacking user that\nwants to block the server by sending huge files (e. g. of several Gb).\n\nTo avoid this, you need to configure your front end to limit the size of uploaded files. How to do\nit depends on the software you are using. For example, if you use apache, you should use\n**LimitRequestBody** directive (http://httpd.apache.org/docs/2.2/mod/core.html#limitrequestbody).\n\nThis is a complementary measure, because you'll usually want normal users that exceed the size by a\nreasonable amount to get a friendly form validation message, while attacking users will see how their\nconnection is abruptly cut before the file finishes uploading. So the recommended setting is to give\n`max_upload_size` a small value (e.g. 5Mb) and `LimitRequestBody` a higher one (e.g. 100Mb).\n\n", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/kaleidos/django-validated-file", "keywords": "django,filefield,validation", "license": "BSD", "maintainer": null, "maintainer_email": null, "name": "django-validated-file", "package_url": "https://pypi.org/project/django-validated-file/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/django-validated-file/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/kaleidos/django-validated-file" }, "release_url": "https://pypi.org/project/django-validated-file/2.0.1/", "requires_dist": null, "requires_python": null, "summary": "This Django app adds a new field type, ValidatedFileField, that add the capability of checking the document size and types the user may send.", "version": "2.0.1" }, "last_serial": 1221642, "releases": { "1.0": [ { "comment_text": "", "digests": { "md5": "626179bf8cded8a79ecdd8cc0b2c8a7c", "sha256": "a9ee8cb92b0099017ae7dcece1cf95a8202265645efa4b664078be377fe2dfba" }, "downloads": -1, "filename": "django-validated-file-1.0.tar.gz", "has_sig": false, "md5_digest": "626179bf8cded8a79ecdd8cc0b2c8a7c", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7197, "upload_time": "2013-04-08T15:06:32", "url": "https://files.pythonhosted.org/packages/da/d4/c4a051f29851e648679931769dcf8cdec7bb38845552ea1efef8cb12ab90/django-validated-file-1.0.tar.gz" } ], "2.0": [ { "comment_text": "", "digests": { "md5": "f25434951080617918214fd41a10caab", "sha256": "0854447cedeeddfbe20cef75a83e1f3bf8bdf9b09520bbcc1953873e0ca536b7" }, "downloads": -1, "filename": "django-validated-file-2.0.tar.gz", "has_sig": false, "md5_digest": "f25434951080617918214fd41a10caab", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 7310, "upload_time": "2013-06-19T21:37:22", "url": "https://files.pythonhosted.org/packages/36/fd/44c29ba813ed90c42fca3e8d7ca15a3aae050c6efebfb66208026a839028/django-validated-file-2.0.tar.gz" } ], "2.0.1": [ { "comment_text": "", "digests": { "md5": "d40ee5b7d8a7eacd9d622f91683e9b1f", "sha256": "ed77cf26aa64447f118884ed74276302bd855bbef45d1e405fdb2a560538eee2" }, "downloads": -1, "filename": "django-validated-file-2.0.1.tar.gz", "has_sig": false, "md5_digest": "d40ee5b7d8a7eacd9d622f91683e9b1f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8033, "upload_time": "2014-09-12T08:22:13", "url": "https://files.pythonhosted.org/packages/8d/b1/30fcb9bea5a4be4220853f6b1ad5ef4f8bdd551e405070ce0259b28e7c0d/django-validated-file-2.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "d40ee5b7d8a7eacd9d622f91683e9b1f", "sha256": "ed77cf26aa64447f118884ed74276302bd855bbef45d1e405fdb2a560538eee2" }, "downloads": -1, "filename": "django-validated-file-2.0.1.tar.gz", "has_sig": false, "md5_digest": "d40ee5b7d8a7eacd9d622f91683e9b1f", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 8033, "upload_time": "2014-09-12T08:22:13", "url": "https://files.pythonhosted.org/packages/8d/b1/30fcb9bea5a4be4220853f6b1ad5ef4f8bdd551e405070ce0259b28e7c0d/django-validated-file-2.0.1.tar.gz" } ] }