Skip to content

Commit c6045a6

Browse files
committed
Include locale in build package
1 parent 728132d commit c6045a6

File tree

17 files changed

+634
-0
lines changed

17 files changed

+634
-0
lines changed

MANIFEST.in

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
include README.rst
2+
include validatedfile/locale/*/LC_MESSAGES/*
3+

build/lib.linux-x86_64-2.7/testing/__init__.py

Whitespace-only changes.
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
import os
2+
3+
PROJECT_ROOT = os.path.dirname(os.path.realpath(__file__))
4+
5+
DEBUG = True
6+
7+
AUTHNET_LOGIN_ID = ''
8+
AUTHNET_TRANSACTION_KEY = ''
9+
10+
DATABASES = {
11+
'default': {
12+
'ENGINE': 'django.db.backends.sqlite3'
13+
},
14+
}
15+
16+
SECRET_KEY = 'm+qa*7_8t-=17zt_)9gi)4g%6w*v$xxkh6rwrys*bn9su+5%du'
17+
18+
INSTALLED_APPS = [
19+
'django.contrib.admin',
20+
'django.contrib.admindocs',
21+
'django.contrib.auth',
22+
'django.contrib.contenttypes',
23+
'django.contrib.messages',
24+
'django.contrib.sessions',
25+
'django.contrib.sites',
26+
'django.contrib.staticfiles',
27+
28+
'validatedfile',
29+
'validatedfile.tests',
30+
]
31+
32+
LANGUAGE_CODE = 'en'
33+
34+
LOGIN_URL = '/accounts/login/'
35+
36+
MANAGERS = []
37+
38+
MIDDLEWARE_CLASSES = [
39+
'django.contrib.sessions.middleware.SessionMiddleware',
40+
'django.contrib.auth.middleware.AuthenticationMiddleware',
41+
'django.contrib.messages.middleware.MessageMiddleware',
42+
'django.middleware.common.CommonMiddleware',
43+
]
44+
45+
ROOT_URLCONF = 'testing.urls'
46+
47+
SITE_ID = 1
48+
49+
TEMPLATE_DIRS = [os.path.join(os.path.dirname(__file__), 'templates')]
50+
51+
USE_I18N = True
52+
53+
MEDIA_ROOT = os.path.join(PROJECT_ROOT, 'media')
54+
55+
MEDIA_URL = '/media/'
56+
Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,6 @@
1+
# -*- coding:utf-8 -*-
2+
from django.conf.urls.defaults import patterns, url, include
3+
4+
urlpatterns = patterns('',
5+
)
6+
Lines changed: 76 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,76 @@
1+
__version__ = (0, 0, 1, "final", 0)
2+
3+
from django.db import models
4+
from django import forms
5+
from django.template.defaultfilters import filesizeformat
6+
from django.utils.translation import ugettext as _
7+
8+
import magic
9+
10+
class ValidatedFileField(models.FileField):
11+
def __init__(self, *args, **kwargs):
12+
self.content_types = kwargs.pop("content_types", [])
13+
self.max_upload_size = kwargs.pop("max_upload_size", 0)
14+
super(ValidatedFileField, self).__init__(*args, **kwargs)
15+
16+
def clean(self, *args, **kwargs):
17+
data = super(ValidatedFileField, self).clean(*args, **kwargs)
18+
file = data.file
19+
20+
if self.content_types:
21+
content_type_headers = getattr(file, 'content_type', '')
22+
23+
mg = magic.Magic(mime = True)
24+
content_type_magic = mg.from_buffer(file.read(1024))
25+
file.seek(0)
26+
27+
if not content_type_headers in self.content_types or not content_type_magic in self.content_types:
28+
raise forms.ValidationError(_('Files of type %(type)s are not supported.') % {'type': content_type_magic})
29+
30+
if self.max_upload_size:
31+
if file._size > self.max_upload_size:
32+
raise forms.ValidationError(_('Files of size greater than %(max_size)s are not allowed. Your file is %(current_size)s') %
33+
{'max_size': filesizeformat(self.max_upload_size),
34+
'current_size': filesizeformat(file._size)})
35+
36+
return data
37+
38+
39+
class FileQuota(object):
40+
41+
def __init__(self, max_usage = -1):
42+
self.current_usage = 0
43+
self.max_usage = max_usage
44+
45+
def update(self, items, attr_name):
46+
self.current_usage = 0
47+
for item in items:
48+
the_file = getattr(item, attr_name, None)
49+
if the_file:
50+
self.current_usage += the_file.size
51+
52+
def exceeds(self, size = 0):
53+
if self.max_usage >= 0:
54+
return (self.current_usage + size > self.max_usage)
55+
else:
56+
return False
57+
58+
def near_limit(self, limit_threshold = 0.8):
59+
return (float(self.current_usage) / float(self.max_usage)) > limit_threshold
60+
61+
62+
class QuotaValidator(object):
63+
64+
def __init__(self, max_usage):
65+
self.quota = FileQuota(max_usage)
66+
67+
def update_quota(self, items, attr_name):
68+
self.quota.update(items, attr_name)
69+
70+
def __call__(self, file):
71+
file_size = file.size
72+
if self.quota.exceeds(file_size):
73+
raise forms.ValidationError(_('Please keep the total uploaded files under %(total_size)s. With this file, the total would be %(exceed_size)s.' %
74+
{'total_size': filesizeformat(self.quota.max_usage),
75+
'exceed_size': filesizeformat(self.quota.current_usage + file_size)}))
76+
Binary file not shown.
Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: PACKAGE VERSION\n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"POT-Creation-Date: 2012-05-14 06:40-0500\n"
12+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14+
"Language-Team: LANGUAGE <[email protected]>\n"
15+
"Language: \n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=UTF-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
20+
#: __init__.py:28
21+
#, python-format
22+
msgid "Files of type %(type)s are not supported."
23+
msgstr ""
24+
25+
#: __init__.py:32
26+
#, python-format
27+
msgid ""
28+
"Files of size greater than %(max_size)s are not allowed. Your file is "
29+
"%(current_size)s"
30+
msgstr ""
31+
32+
#: __init__.py:73
33+
#, python-format
34+
msgid ""
35+
"Please keep the total uploaded files under %(total_size)s. With this file, "
36+
"the total would be %(exceed_size)s."
37+
msgstr ""
Binary file not shown.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
# SOME DESCRIPTIVE TITLE.
2+
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
3+
# This file is distributed under the same license as the PACKAGE package.
4+
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
5+
#
6+
#, fuzzy
7+
msgid ""
8+
msgstr ""
9+
"Project-Id-Version: PACKAGE VERSION\n"
10+
"Report-Msgid-Bugs-To: \n"
11+
"POT-Creation-Date: 2012-05-14 06:40-0500\n"
12+
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
13+
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
14+
"Language-Team: LANGUAGE <[email protected]>\n"
15+
"Language: \n"
16+
"MIME-Version: 1.0\n"
17+
"Content-Type: text/plain; charset=UTF-8\n"
18+
"Content-Transfer-Encoding: 8bit\n"
19+
"Plural-Forms: nplurals=2; plural=(n != 1)\n"
20+
21+
#: __init__.py:28
22+
#, python-format
23+
msgid "Files of type %(type)s are not supported."
24+
msgstr "No se admiten archivos de tipo %(type)s."
25+
26+
#: __init__.py:32
27+
#, python-format
28+
msgid ""
29+
"Files of size greater than %(max_size)s are not allowed. Your file is "
30+
"%(current_size)s"
31+
msgstr ""
32+
"No se admiten archivos más grandes que %(max_size)s. El archivo subido ocupa "
33+
"%(current_size)s"
34+
35+
#: __init__.py:73
36+
#, python-format
37+
msgid ""
38+
"Please keep the total uploaded files under %(total_size)s. With this file, "
39+
"the total would be %(exceed_size)s."
40+
msgstr ""
41+
"Por favor, no puedes subir ficheros por un total mayor que %(total_size)s. "
42+
"Con este fichero se llegaría a %(exceed_size)s."

build/lib.linux-x86_64-2.7/validatedfile/models.py

Whitespace-only changes.

0 commit comments

Comments
 (0)