Permalink
Browse files

move branches/filebrowser_3_1 to trunk/filebrowser;

new release is done!!!
  • Loading branch information...
fetzig committed May 28, 2010
1 parent 13297cd commit 71f562026cf85d8733511e0446809ed1ef8bc943
Showing with 0 additions and 18,063 deletions.
  1. +0 −24 filebrowser/LICENSE
  2. 0 filebrowser/__init__.py
  3. +0 −203 filebrowser/base.py
  4. +0 −30 filebrowser/decorators.py
  5. +0 −123 filebrowser/fields.py
  6. +0 −63 filebrowser/forms.py
  7. +0 −370 filebrowser/functions.py
  8. BIN filebrowser/locale/ca/LC_MESSAGES/django.mo
  9. +0 −328 filebrowser/locale/ca/LC_MESSAGES/django.po
  10. BIN filebrowser/locale/de/LC_MESSAGES/django.mo
  11. +0 −384 filebrowser/locale/de/LC_MESSAGES/django.po
  12. BIN filebrowser/locale/es/LC_MESSAGES/django.mo
  13. +0 −328 filebrowser/locale/es/LC_MESSAGES/django.po
  14. BIN filebrowser/locale/fr/LC_MESSAGES/django.mo
  15. +0 −336 filebrowser/locale/fr/LC_MESSAGES/django.po
  16. BIN filebrowser/locale/it/LC_MESSAGES/django.mo
  17. +0 −356 filebrowser/locale/it/LC_MESSAGES/django.po
  18. BIN filebrowser/locale/nl/LC_MESSAGES/django.mo
  19. +0 −319 filebrowser/locale/nl/LC_MESSAGES/django.po
  20. BIN filebrowser/locale/ru/LC_MESSAGES/django.mo
  21. +0 −394 filebrowser/locale/ru/LC_MESSAGES/django.po
  22. BIN filebrowser/locale/sr/LC_MESSAGES/django.mo
  23. +0 −376 filebrowser/locale/sr/LC_MESSAGES/django.po
  24. BIN filebrowser/locale/sr_Latn/LC_MESSAGES/django.mo
  25. +0 −376 filebrowser/locale/sr_Latn/LC_MESSAGES/django.po
  26. BIN filebrowser/locale/zh_CN/LC_MESSAGES/django.mo
  27. +0 −370 filebrowser/locale/zh_CN/LC_MESSAGES/django.po
  28. BIN filebrowser/locale/zh_TW/LC_MESSAGES/django.mo
  29. +0 −370 filebrowser/locale/zh_TW/LC_MESSAGES/django.po
  30. 0 filebrowser/management/__init__.py
  31. 0 filebrowser/management/commands/__init__.py
  32. +0 −44 filebrowser/management/commands/version_generator.py
  33. +0 −195 filebrowser/media/filebrowser/css/filebrowser.css
  34. BIN filebrowser/media/filebrowser/img/filebrowser_icon_delete.gif
  35. BIN filebrowser/media/filebrowser/img/filebrowser_icon_delete_hover.gif
  36. BIN filebrowser/media/filebrowser/img/filebrowser_icon_rename.gif
  37. BIN filebrowser/media/filebrowser/img/filebrowser_icon_rename_hover.gif
  38. BIN filebrowser/media/filebrowser/img/filebrowser_icon_select.gif
  39. BIN filebrowser/media/filebrowser/img/filebrowser_icon_select_disabled.gif
  40. BIN filebrowser/media/filebrowser/img/filebrowser_icon_select_hover.gif
  41. BIN filebrowser/media/filebrowser/img/filebrowser_icon_show.gif
  42. BIN filebrowser/media/filebrowser/img/filebrowser_icon_show_hover.gif
  43. BIN filebrowser/media/filebrowser/img/filebrowser_icon_showversions.gif
  44. BIN filebrowser/media/filebrowser/img/filebrowser_icon_showversions_hover.gif
  45. BIN filebrowser/media/filebrowser/img/filebrowser_type_.gif
  46. BIN filebrowser/media/filebrowser/img/filebrowser_type_audio.gif
  47. BIN filebrowser/media/filebrowser/img/filebrowser_type_code.gif
  48. BIN filebrowser/media/filebrowser/img/filebrowser_type_document.gif
  49. BIN filebrowser/media/filebrowser/img/filebrowser_type_folder.gif
  50. BIN filebrowser/media/filebrowser/img/filebrowser_type_image.gif
  51. BIN filebrowser/media/filebrowser/img/filebrowser_type_video.gif
  52. BIN filebrowser/media/filebrowser/img/icon-fb-preview-hover.png
  53. BIN filebrowser/media/filebrowser/img/icon-fb-preview.png
  54. BIN filebrowser/media/filebrowser/img/icon-fb-view-image-hover.png
  55. BIN filebrowser/media/filebrowser/img/icon-pulldown-actions-active.png
  56. BIN filebrowser/media/filebrowser/img/icon-pulldown-actions-hover.png
  57. BIN filebrowser/media/filebrowser/img/icon-pulldown-actions.png
  58. BIN filebrowser/media/filebrowser/img/icon-showversions.png
  59. +0 −42 filebrowser/media/filebrowser/js/AddFileBrowser.js
  60. +0 −24 filebrowser/media/filebrowser/js/FB_CKEditor.js
  61. +0 −32 filebrowser/media/filebrowser/js/FB_FileBrowseField.js
  62. +0 −28 filebrowser/media/filebrowser/js/FB_TinyMCE.js
  63. +0 −75 filebrowser/media/filebrowser/js/TinyMCEAdmin.js
  64. BIN filebrowser/media/filebrowser/uploadify/Uploadify v2.1.0 Manual.pdf
  65. BIN filebrowser/media/filebrowser/uploadify/cancel.png
  66. +0 −35 filebrowser/media/filebrowser/uploadify/check.php
  67. +0 −98 filebrowser/media/filebrowser/uploadify/com/adobe/air/logging/FileTarget.as
  68. +0 −127 filebrowser/media/filebrowser/uploadify/com/adobe/crypto/HMAC.as
  69. +0 −281 filebrowser/media/filebrowser/uploadify/com/adobe/crypto/MD5.as
  70. +0 −402 filebrowser/media/filebrowser/uploadify/com/adobe/crypto/MD5Stream.as
  71. +0 −271 filebrowser/media/filebrowser/uploadify/com/adobe/crypto/SHA1.as
  72. +0 −257 filebrowser/media/filebrowser/uploadify/com/adobe/crypto/SHA224.as
  73. +0 −261 filebrowser/media/filebrowser/uploadify/com/adobe/crypto/SHA256.as
  74. +0 −114 filebrowser/media/filebrowser/uploadify/com/adobe/crypto/WSSEUsernameToken.as
  75. +0 −63 filebrowser/media/filebrowser/uploadify/com/adobe/errors/IllegalStateError.as
  76. +0 −47 filebrowser/media/filebrowser/uploadify/com/adobe/fileformats/vcard/Address.as
  77. +0 −39 filebrowser/media/filebrowser/uploadify/com/adobe/fileformats/vcard/Email.as
  78. +0 −39 filebrowser/media/filebrowser/uploadify/com/adobe/fileformats/vcard/Phone.as
  79. +0 −54 filebrowser/media/filebrowser/uploadify/com/adobe/fileformats/vcard/VCard.as
  80. +0 −246 filebrowser/media/filebrowser/uploadify/com/adobe/fileformats/vcard/VCardParser.as
  81. +0 −39 filebrowser/media/filebrowser/uploadify/com/adobe/images/BitString.as
  82. +0 −648 filebrowser/media/filebrowser/uploadify/com/adobe/images/JPGEncoder.as
  83. +0 −141 filebrowser/media/filebrowser/uploadify/com/adobe/images/PNGEncoder.as
  84. +0 −55 filebrowser/media/filebrowser/uploadify/com/adobe/net/DynamicURLLoader.as
  85. +0 −76 filebrowser/media/filebrowser/uploadify/com/adobe/net/IURIResolver.as
  86. +0 −196 filebrowser/media/filebrowser/uploadify/com/adobe/net/MimeTypeMap.as
  87. +0 −2,466 filebrowser/media/filebrowser/uploadify/com/adobe/net/URI.as
  88. +0 −139 filebrowser/media/filebrowser/uploadify/com/adobe/net/URIEncodingBitmap.as
  89. +0 −198 filebrowser/media/filebrowser/uploadify/com/adobe/net/proxies/RFC2817Socket.as
  90. +0 −34 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/Database.as
  91. +0 −39 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/Definition.as
  92. +0 −328 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/Dict.as
  93. +0 −28 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/DictionaryServer.as
  94. +0 −34 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/MatchStrategy.as
  95. +0 −39 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/Response.as
  96. +0 −14 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/ConnectedEvent.as
  97. +0 −26 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/DatabaseEvent.as
  98. +0 −27 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/DefinitionEvent.as
  99. +0 −26 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/DefinitionHeaderEvent.as
  100. +0 −26 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/DictionaryServerEvent.as
  101. +0 −14 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/DisconnectedEvent.as
  102. +0 −37 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/ErrorEvent.as
  103. +0 −26 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/MatchEvent.as
  104. +0 −26 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/MatchStrategiesEvent.as
  105. +0 −14 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/events/NoMatchEvent.as
  106. +0 −25 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/util/CompleteResponseEvent.as
  107. +0 −49 filebrowser/media/filebrowser/uploadify/com/adobe/protocols/dict/util/SocketHelper.as
  108. +0 −85 filebrowser/media/filebrowser/uploadify/com/adobe/serialization/json/JSON.as
  109. +0 −221 filebrowser/media/filebrowser/uploadify/com/adobe/serialization/json/JSONDecoder.as
  110. +0 −299 filebrowser/media/filebrowser/uploadify/com/adobe/serialization/json/JSONEncoder.as
  111. +0 −87 filebrowser/media/filebrowser/uploadify/com/adobe/serialization/json/JSONParseError.as
  112. +0 −104 filebrowser/media/filebrowser/uploadify/com/adobe/serialization/json/JSONToken.as
  113. +0 −67 filebrowser/media/filebrowser/uploadify/com/adobe/serialization/json/JSONTokenType.as
  114. +0 −583 filebrowser/media/filebrowser/uploadify/com/adobe/serialization/json/JSONTokenizer.as
  115. +0 −187 filebrowser/media/filebrowser/uploadify/com/adobe/utils/ArrayUtil.as
  116. +0 −699 filebrowser/media/filebrowser/uploadify/com/adobe/utils/DateUtil.as
  117. +0 −87 filebrowser/media/filebrowser/uploadify/com/adobe/utils/DictionaryUtil.as
  118. +0 −99 filebrowser/media/filebrowser/uploadify/com/adobe/utils/IntUtil.as
  119. +0 −74 filebrowser/media/filebrowser/uploadify/com/adobe/utils/NumberFormatter.as
  120. +0 −270 filebrowser/media/filebrowser/uploadify/com/adobe/utils/StringUtil.as
  121. +0 −168 filebrowser/media/filebrowser/uploadify/com/adobe/utils/XMLUtil.as
  122. +0 −48 filebrowser/media/filebrowser/uploadify/com/adobe/webapis/ServiceBase.as
  123. +0 −108 filebrowser/media/filebrowser/uploadify/com/adobe/webapis/URLLoaderBase.as
  124. +0 −75 filebrowser/media/filebrowser/uploadify/com/adobe/webapis/events/ServiceEvent.as
  125. +0 −5 filebrowser/media/filebrowser/uploadify/example/_notes/dwsync.xml
  126. BIN filebrowser/media/filebrowser/uploadify/example/cancel.png
  127. +0 −5 filebrowser/media/filebrowser/uploadify/example/css/_notes/dwsync.xml
  128. +0 −10 filebrowser/media/filebrowser/uploadify/example/css/default.css
  129. +0 −53 filebrowser/media/filebrowser/uploadify/example/css/uploadify.css
  130. +0 −31 filebrowser/media/filebrowser/uploadify/example/index.php
  131. +0 −10 filebrowser/media/filebrowser/uploadify/example/scripts/_notes/dwsync.xml
  132. +0 −35 filebrowser/media/filebrowser/uploadify/example/scripts/check.php
  133. BIN filebrowser/media/filebrowser/uploadify/example/scripts/expressInstall.swf
  134. +0 −19 filebrowser/media/filebrowser/uploadify/example/scripts/jquery-1.3.2.min.js
  135. +0 −26 filebrowser/media/filebrowser/uploadify/example/scripts/jquery.uploadify.v2.1.0.min.js
  136. +0 −4 filebrowser/media/filebrowser/uploadify/example/scripts/swfobject.js
  137. +0 −46 filebrowser/media/filebrowser/uploadify/example/scripts/uploadify.php
  138. BIN filebrowser/media/filebrowser/uploadify/example/scripts/uploadify.swf
  139. BIN filebrowser/media/filebrowser/uploadify/expressInstall.swf
  140. +0 −19 filebrowser/media/filebrowser/uploadify/jquery-1.3.2.min.js
  141. +0 −258 filebrowser/media/filebrowser/uploadify/jquery.uploadify.v2.1.0.js
  142. +0 −26 filebrowser/media/filebrowser/uploadify/jquery.uploadify.v2.1.0.min.js
  143. +0 −4 filebrowser/media/filebrowser/uploadify/swfobject.js
  144. BIN filebrowser/media/filebrowser/uploadify/uploadify.allglyphs.swf
  145. +0 −53 filebrowser/media/filebrowser/uploadify/uploadify.css
  146. BIN filebrowser/media/filebrowser/uploadify/uploadify.fla
  147. +0 −46 filebrowser/media/filebrowser/uploadify/uploadify.php
  148. BIN filebrowser/media/filebrowser/uploadify/uploadify.swf
  149. +0 −1 filebrowser/models.py
  150. +0 −124 filebrowser/settings.py
  151. +0 −12 filebrowser/templates/filebrowser/append.html
  152. +0 −26 filebrowser/templates/filebrowser/custom_field.html
  153. +0 −1 filebrowser/templates/filebrowser/include/_response.html
  154. +0 −24 filebrowser/templates/filebrowser/include/breadcrumbs.html
  155. +0 −131 filebrowser/templates/filebrowser/include/filelisting.html
  156. +0 −27 filebrowser/templates/filebrowser/include/filter.html
  157. +0 −28 filebrowser/templates/filebrowser/include/paginator.html
  158. +0 −31 filebrowser/templates/filebrowser/include/search.html
  159. +0 −26 filebrowser/templates/filebrowser/include/tableheader.html
  160. +0 −36 filebrowser/templates/filebrowser/include/toolbar.html
  161. +0 −143 filebrowser/templates/filebrowser/index.html
  162. +0 −45 filebrowser/templates/filebrowser/makedir.html
  163. +0 −43 filebrowser/templates/filebrowser/rename.html
  164. +0 −116 filebrowser/templates/filebrowser/upload.html
  165. +0 −156 filebrowser/templates/filebrowser/versions.html
  166. 0 filebrowser/templatetags/__init__.py
  167. +0 −30 filebrowser/templatetags/fb_csrf.py
  168. +0 −51 filebrowser/templatetags/fb_pagination.py
  169. +0 −140 filebrowser/templatetags/fb_tags.py
  170. +0 −175 filebrowser/templatetags/fb_versions.py
  171. +0 −16 filebrowser/urls.py
  172. +0 −476 filebrowser/views.py
View
@@ -1,24 +0,0 @@
-Copyright (c) 2010, Patrick Kranzlmueller (vonautomatisch werkstaetten),
-All rights reserved.
-
-Redistribution and use in source and binary forms, with or without modification,
-are permitted provided that the following conditions are met:
-
-1. Redistributions of source code must retain the above copyright notice,
-this list of conditions and the following disclaimer.
-2. Redistributions in binary form must reproduce the above copyright notice,
-this list of conditions and the following disclaimer in the documentation and/or
-other materials provided with the distribution.
-3. Neither the name of FileBrowser nor the names of its contributors may be used
-to endorse or promote products derived from this software without specific prior
-written permission.
-
-THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS
-OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
-MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL
-THE REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
-EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF
-SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
-HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
-OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
-SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
View
No changes.
View
@@ -1,203 +0,0 @@
-# coding: utf-8
-
-# imports
-import os, re, datetime
-from time import gmtime, strftime
-
-# django imports
-from django.conf import settings
-
-# filebrowser imports
-from filebrowser.settings import *
-from filebrowser.functions import get_file_type, url_join, is_selectable, get_version_path
-
-# PIL import
-if STRICT_PIL:
- from PIL import Image
-else:
- try:
- from PIL import Image
- except ImportError:
- import Image
-
-
-class FileObject(object):
- """
- The FileObject represents a File on the Server.
-
- PATH has to be relative to MEDIA_ROOT.
- """
-
- def __init__(self, path):
- self.path = path
- self.url_rel = path.replace("\\","/")
- self.head = os.path.split(path)[0]
- self.filename = os.path.split(path)[1]
- self.filename_lower = self.filename.lower() # important for sorting
- self.filetype = get_file_type(self.filename)
-
- def _filesize(self):
- """
- Filesize.
- """
- path = self.path.encode('utf8')
- if os.path.isfile(os.path.join(MEDIA_ROOT, path)) or os.path.isdir(os.path.join(MEDIA_ROOT, path)):
- return os.path.getsize(os.path.join(MEDIA_ROOT, path))
- return ""
- filesize = property(_filesize)
-
- def _date(self):
- """
- Date.
- """
- if os.path.isfile(os.path.join(MEDIA_ROOT, self.path)) or os.path.isdir(os.path.join(MEDIA_ROOT, self.path)):
- return os.path.getmtime(os.path.join(MEDIA_ROOT, self.path))
- return ""
- date = property(_date)
-
- def _datetime(self):
- """
- Datetime Object.
- """
- return datetime.datetime.fromtimestamp(self.date)
- datetime = property(_datetime)
-
- def _extension(self):
- """
- Extension.
- """
- return u"%s" % os.path.splitext(self.filename)[1]
- extension = property(_extension)
-
- def _filetype_checked(self):
- if self.filetype == "Folder" and os.path.isdir(self.path_full):
- return self.filetype
- elif self.filetype != "Folder" and os.path.isfile(self.path_full):
- return self.filetype
- else:
- return ""
- filetype_checked = property(_filetype_checked)
-
- def _path_full(self):
- """
- Full server PATH including MEDIA_ROOT.
- """
- return u"%s" % os.path.join(MEDIA_ROOT, self.path)
- path_full = property(_path_full)
-
- def _path_relative(self):
- return self.path
- path_relative = property(_path_relative)
-
- def _path_relative_directory(self):
- """
- Path relative to initial directory.
- """
- directory_re = re.compile(r'^(%s)' % (DIRECTORY))
- value = directory_re.sub('', self.path)
- return u"%s" % value
- path_relative_directory = property(_path_relative_directory)
-
- def _url_relative(self):
- return self.url_rel
- url_relative = property(_url_relative)
-
- def _url_full(self):
- """
- Full URL including MEDIA_URL.
- """
- return u"%s" % url_join(MEDIA_URL, self.url_rel)
- url_full = property(_url_full)
-
- def _url_save(self):
- """
- URL used for the filebrowsefield.
- """
- if SAVE_FULL_URL:
- return self.url_full
- else:
- return self.url_rel
- url_save = property(_url_save)
-
- def _url_thumbnail(self):
- """
- Thumbnail URL.
- """
- if self.filetype == "Image":
- return u"%s" % url_join(MEDIA_URL, get_version_path(self.path, 'fb_thumb'))
- else:
- return ""
- url_thumbnail = property(_url_thumbnail)
-
- def url_admin(self):
- if self.filetype_checked == "Folder":
- directory_re = re.compile(r'^(%s)' % (DIRECTORY))
- value = directory_re.sub('', self.path)
- return u"%s" % value
- else:
- return u"%s" % url_join(MEDIA_URL, self.path)
-
- def _dimensions(self):
- """
- Image Dimensions.
- """
- if self.filetype == 'Image':
- try:
- im = Image.open(os.path.join(MEDIA_ROOT, self.path))
- return im.size
- except:
- pass
- else:
- return False
- dimensions = property(_dimensions)
-
- def _width(self):
- """
- Image Width.
- """
- return self.dimensions[0]
- width = property(_width)
-
- def _height(self):
- """
- Image Height.
- """
- return self.dimensions[1]
- height = property(_height)
-
- def _orientation(self):
- """
- Image Orientation.
- """
- if self.dimensions:
- if self.dimensions[0] >= self.dimensions[1]:
- return "Landscape"
- else:
- return "Portrait"
- else:
- return None
- orientation = property(_orientation)
-
- def _is_empty(self):
- """
- True if Folder is empty, False if not.
- """
- if os.path.isdir(self.path_full):
- if not os.listdir(self.path_full):
- return True
- else:
- return False
- else:
- return None
- is_empty = property(_is_empty)
-
- def __repr__(self):
- return u"%s" % self.url_save
-
- def __str__(self):
- return u"%s" % self.url_save
-
- def __unicode__(self):
- return u"%s" % self.url_save
-
-
View
@@ -1,30 +0,0 @@
-# coding: utf-8
-
-# django imports
-from django.contrib.sessions.models import Session
-from django.shortcuts import get_object_or_404, render_to_response
-from django.contrib.auth.models import User
-from django.template import RequestContext
-from django.conf import settings
-
-
-def flash_login_required(function):
- """
- Decorator to recognize a user by its session.
- Used for Flash-Uploading.
- """
-
- def decorator(request, *args, **kwargs):
- try:
- engine = __import__(settings.SESSION_ENGINE, {}, {}, [''])
- except:
- import django.contrib.sessions.backends.db
- engine = django.contrib.sessions.backends.db
- session_data = engine.SessionStore(request.POST.get('session_key'))
- user_id = session_data['_auth_user_id']
- # will return 404 if the session ID does not resolve to a valid user
- request.user = get_object_or_404(User, pk=user_id)
- return function(request, *args, **kwargs)
- return decorator
-
-
View
@@ -1,123 +0,0 @@
-# coding: utf-8
-
-# imports
-import os
-
-# django imports
-from django.db import models
-from django import forms
-from django.forms.widgets import Input
-from django.db.models.fields import Field, CharField
-from django.utils.encoding import force_unicode
-from django.template.loader import render_to_string
-from django.utils.translation import ugettext_lazy as _
-
-# filebrowser imports
-from filebrowser.settings import *
-from filebrowser.base import FileObject
-from filebrowser.functions import url_to_path
-
-
-class FileBrowseWidget(Input):
- input_type = 'text'
-
- class Media:
- js = (os.path.join(URL_FILEBROWSER_MEDIA, 'js/AddFileBrowser.js'), )
-
- def __init__(self, attrs=None):
- self.directory = attrs.get('directory', '')
- self.extensions = attrs.get('extensions', '')
- self.format = attrs.get('format', '')
- if attrs is not None:
- self.attrs = attrs.copy()
- else:
- self.attrs = {}
-
- def render(self, name, value, attrs=None):
- if value is None:
- value = ""
- final_attrs = self.build_attrs(attrs, type=self.input_type, name=name)
- final_attrs['search_icon'] = URL_FILEBROWSER_MEDIA + 'img/filebrowser_icon_show.gif'
- final_attrs['directory'] = self.directory
- final_attrs['extensions'] = self.extensions
- final_attrs['format'] = self.format
- final_attrs['ADMIN_THUMBNAIL'] = ADMIN_THUMBNAIL
- final_attrs['DEBUG'] = DEBUG
- if value != "":
- try:
- final_attrs['directory'] = os.path.split(value.path_relative_directory)[0]
- except:
- pass
- return render_to_string("filebrowser/custom_field.html", locals())
-
-
-class FileBrowseFormField(forms.CharField):
- widget = FileBrowseWidget
-
- default_error_messages = {
- 'extension': _(u'Extension %(ext)s is not allowed. Only %(allowed)s is allowed.'),
- }
-
- def __init__(self, max_length=None, min_length=None,
- directory=None, extensions=None, format=None,
- *args, **kwargs):
- self.max_length, self.min_length = max_length, min_length
- self.directory = directory
- self.extensions = extensions
- if format:
- self.format = format or ''
- self.extensions = extensions or EXTENSIONS.get(format)
- super(FileBrowseFormField, self).__init__(*args, **kwargs)
-
- def clean(self, value):
- value = super(FileBrowseFormField, self).clean(value)
- if value == '':
- return value
- file_extension = os.path.splitext(value)[1].lower()
- if self.extensions and not file_extension in self.extensions:
- raise forms.ValidationError(self.error_messages['extension'] % {'ext': file_extension, 'allowed': ", ".join(self.extensions)})
- return value
-
-
-class FileBrowseField(Field):
- __metaclass__ = models.SubfieldBase
-
- def __init__(self, *args, **kwargs):
- self.directory = kwargs.pop('directory', '')
- self.extensions = kwargs.pop('extensions', '')
- self.format = kwargs.pop('format', '')
- return super(FileBrowseField, self).__init__(*args, **kwargs)
-
- def to_python(self, value):
- if not value or isinstance(value, FileObject):
- return value
- return FileObject(url_to_path(value))
-
- def get_db_prep_value(self, value):
- if value is None:
- return None
- return unicode(value)
-
-
- def get_manipulator_field_objs(self):
- return [oldforms.TextField]
-
- def get_internal_type(self):
- return "CharField"
-
- def formfield(self, **kwargs):
- attrs = {}
- attrs["directory"] = self.directory
- attrs["extensions"] = self.extensions
- attrs["format"] = self.format
- defaults = {
- 'form_class': FileBrowseFormField,
- 'widget': FileBrowseWidget(attrs=attrs),
- 'directory': self.directory,
- 'extensions': self.extensions,
- 'format': self.format
- }
- defaults.update(kwargs)
- return super(FileBrowseField, self).formfield(**defaults)
-
-
Oops, something went wrong.

0 comments on commit 71f5620

Please sign in to comment.