Permalink
Browse files

adding support for (django.contrib.)staticfiles

  • Loading branch information...
1 parent 6b8591f commit 76611f60c417a43f750c5bfb0e4fb4d80fa19d06 @slafs slafs committed Jan 23, 2012
Showing with 39 additions and 3 deletions.
  1. +2 −0 MANIFEST.in
  2. +7 −0 README.md
  3. +6 −0 pyuploadcare/dj/conf.py
  4. +24 −3 pyuploadcare/dj/forms.py
View
@@ -0,0 +1,2 @@
+recursive-include pyuploadcare/dj/static *
+
View
@@ -21,6 +21,13 @@ As soon as you get your API keys, add them to your Django settings file:
'secret': '***'
}
+If you don't want to use hosted assets (from static.uploadcare.com) you
+must add 'pyuploadcare.dj' to INSTALLED_APPS setting and add
+
+ PYUPLOADCARE_USE_HOSTED_ASSETS = False
+
+somewhere in the settings file.
+
You're all set now!
Adding a UploadCare file field to your model is really simple. Like that:
View
@@ -0,0 +1,6 @@
+#TODO: make this compatible with django-appconf
+
+from django.conf import settings
+
+USE_HOSTED_ASSETS = getattr(settings, 'PYUPLOADCARE_USE_HOSTED_ASSETS', True)
+
View
@@ -1,16 +1,37 @@
from django.forms import Field, TextInput, Media
from django.conf import settings
from django.utils.safestring import mark_safe
-from django.utils.translation import ugettext as _
+from django.utils.translation import ugettext as _, get_language
+from pyuploadcare.dj.conf import USE_HOSTED_ASSETS
+
+UPLOADCARE_JS = 'http://static.uploadcare.com/assets/uploaders/line-widget.%(lang)s.js'
+UPLOADCARE_LOCAL_JS = 'uploadcare/assets/uploaders/line-widget.%(lang)s.js'
+
+AVAIL_ASSET_LANG = ('en', 'ru', 'pl')
+
+def get_asset_lang():
+ '''returns a dict with one key: "lang" '''
+ lang = get_language()
+ if lang.startswith('en'):
+ lang = lang[:2]
+
+ if not lang in AVAIL_ASSET_LANG:
+ lang = 'en'
+
+ BASE_ASSET_URL = UPLOADCARE_JS
+ if not USE_HOSTED_ASSETS:
+ BASE_ASSET_URL = UPLOADCARE_LOCAL_JS
+
+ return BASE_ASSET_URL % {'lang' : lang}
-UPLOADCARE_JS = 'http://static.uploadcare.com/assets/uploaders/line-widget.en.js'
class FileWidget(TextInput):
input_type = 'hidden'
class Media:
- js = (UPLOADCARE_JS,)
+ js = (get_asset_lang(),)
+
def __init__(self, attrs=None):
from pyuploadcare.dj import UploadCare

0 comments on commit 76611f6

Please sign in to comment.