Commits

George Notaras committed 46daed9

Added code from django-tagging-autocomplete-modified project.

Comments (0)

Files changed (6)

 django-taggit-autocomplete-modified
 Django
 Sphinx
+django-taggit

src/taggit_autocomplete_modified/__init__.py

 #  limitations under the License.
 #
 
-VERSION = (0, 1, 0, 'final', 0)
+# Scheme: <major>.<minor>.<maintenance>.<maturity>.<revision>
+# maturity: final/beta/alpha
+
+VERSION = (0, 1, 0, 'alpha', 1)
 
 def get_version():
-    version = '%d.%d.%d' % (VERSION[0], VERSION[1], VERSION[2])
+    version = '%s.%s' % (VERSION[0], VERSION[1])
+    if VERSION[2] is not None:
+        version = '%s.%s' % (version, VERSION[2])
+    if VERSION[3] != 'final':
+        if VERSION[4] > 0:
+            version = '%s%s%s' % (version, VERSION[3][0], VERSION[4])
+        else:
+            version = '%s%s' % (version, VERSION[3][0])
     return version
 
+__version__ = get_version()
+
+def get_status_classifier():
+    if VERSION[3] == 'final':
+        return 'Development Status :: 5 - Production/Stable'
+    elif VERSION[3] == 'beta':
+        return 'Development Status :: 4 - Beta'
+    elif VERSION[3] == 'alpha':
+        return 'Development Status :: 3 - Alpha'
+    raise NotImplementedError

src/taggit_autocomplete_modified/settings.py

 from django.conf import settings
 
 
-MY_APP_SETTING = getattr(settings, 'MY_APP_SETTING', '...')
+# Override TAGGING_AUTOCOMPLETE_JS_ROOT in settings.py
+DEFAULT_TAGGING_AUTOCOMPLETE_JS_BASE_URL = '%s/js' % settings.STATIC_URL.rstrip('/')
+TAGGING_AUTOCOMPLETE_JS_BASE_URL = getattr(settings, 'TAGGING_AUTOCOMPLETE_JS_BASE_URL', DEFAULT_TAGGING_AUTOCOMPLETE_JS_BASE_URL)
 
+# Override TAGGING_AUTOCOMPLETE_CSS_ROOT in settings.py
+DEFAULT_TAGGING_AUTOCOMPLETE_CSS_BASE_URL = '%s/css' % settings.STATIC_URL.rstrip('/')
+TAGGING_AUTOCOMPLETE_CSS_BASE_URL = getattr(settings, 'TAGGING_AUTOCOMPLETE_CSS_BASE_URL', DEFAULT_TAGGING_AUTOCOMPLETE_CSS_BASE_URL)
+
+# TODO: Add a setting for the autocomplete options: http://docs.jquery.com/Plugins/Autocomplete/autocomplete#url_or_dataoptions

src/taggit_autocomplete_modified/urls.py

 
 from django.conf.urls.defaults import *
 
+urlpatterns = patterns('tagging_autocomplete_modified.views',
+    url(r'^json$', 'list_tags', name='tagging_autocomplete-list'),
+)
+

src/taggit_autocomplete_modified/views.py

 #  See the License for the specific language governing permissions and
 #  limitations under the License.
 #
+
+from django.db.models.loading import cache
+from django.http import HttpResponse
+from django.utils.datastructures import MultiValueDictKeyError
+
+
+def list_tags(request):
+    Tag = cache.get_model('tagging', 'Tag')
+    try:
+        tags = Tag.objects.filter(name__istartswith=request.GET['q']).values_list('name', flat=True)
+    except MultiValueDictKeyError:
+        pass
+    return HttpResponse('\n'.join(tags), mimetype='text/plain')
+
+

src/taggit_autocomplete_modified/widgets.py

+# -*- coding: utf-8 -*-
+#
+#  This file is part of django-taggit-autocomplete-modified.
+#
+#  DESCRIPTION_DESCRIPTION_DESCRIPTION
+#
+#  Development Web Site:
+#    - http://www.codetrax.org/projects/django-taggit-autocomplete-modified
+#  Public Source Code Repository:
+#    - https://source.codetrax.org/hgroot/django-taggit-autocomplete-modified
+#
+#  Copyright 2011 George Notaras <gnot [at] g-loaded.eu>
+#
+#  Licensed under the Apache License, Version 2.0 (the "License");
+#  you may not use this file except in compliance with the License.
+#  You may obtain a copy of the License at
+#
+#      http://www.apache.org/licenses/LICENSE-2.0
+#
+#  Unless required by applicable law or agreed to in writing, software
+#  distributed under the License is distributed on an "AS IS" BASIS,
+#  WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+#  See the License for the specific language governing permissions and
+#  limitations under the License.
+#
+
+
+from django.forms.widgets import Input
+from django.core.urlresolvers import reverse
+from django.utils.safestring import mark_safe
+
+from tagging_autocomplete_modified import settings
+
+
+class TagAutocomplete(Input):
+    input_type = 'text'
+    
+    def render(self, name, value, attrs=None):
+        json_view = reverse('tagging_autocomplete-list')
+        html = super(TagAutocomplete, self).render(name, value, attrs)
+        js = u'<script type="text/javascript">jQuery().ready(function() { jQuery("#%s").autocomplete("%s", { multiple: true }); });</script>' % (attrs['id'], json_view)
+        return mark_safe("\n".join([html, js]))
+    
+    class Media:
+        css = {
+            'all': ('%s/jquery.autocomplete.css' % settings.TAGGING_AUTOCOMPLETE_CSS_BASE_URL,)
+        }
+        js = (
+            '%s/jquery.js' % settings.TAGGING_AUTOCOMPLETE_JS_BASE_URL,
+            '%s/jquery.autocomplete.js' % settings.TAGGING_AUTOCOMPLETE_JS_BASE_URL,
+        )
+