Commits

Anonymous committed 3c1d819

Getting the example to work.

Comments (0)

Files changed (12)

Add a comment to this file

autocomplete_test/data.db

Binary file added.

Add a comment to this file

autocomplete_test/example/__init__.py

Empty file added.

autocomplete_test/example/forms.py

+from django import forms
+
+from autocomplete_test.example.models import Example
+from jautocomplete.widgets import SelectAutocompleteInput
+
+class TestForm(forms.ModelForm):
+    class Meta:
+        model = Example
+        widgets = {
+            "value": SelectAutocompleteInput()
+        }

autocomplete_test/example/models.py

+from django.db import models
+
+class Value(models.Model):
+    name = models.CharField(max_length=90)
+    
+    def __unicode__(self):
+        return self.name
+    
+class Example(models.Model):
+    value = models.ForeignKey(Value)
+    
+    

autocomplete_test/example/tests.py

+"""
+This file demonstrates writing tests using the unittest module. These will pass
+when you run "manage.py test".
+
+Replace this with more appropriate tests for your application.
+"""
+
+from django.test import TestCase
+
+
+class SimpleTest(TestCase):
+    def test_basic_addition(self):
+        """
+        Tests that 1 + 1 always equals 2.
+        """
+        self.assertEqual(1 + 1, 2)

autocomplete_test/example/views.py

+from django.shortcuts import render
+
+from autocomplete_test.example.forms import TestForm
+
+def test(request, template="test.html"):
+    form = TestForm()
+    return render(request,
+                  template,
+                  dict(form=form))

autocomplete_test/requirements.txt

+Django=1.3.1
+
+#python setup.py develop
+
+

autocomplete_test/settings.py

 DEBUG = True
 TEMPLATE_DEBUG = DEBUG
 
+import os
+PATH = os.path.abspath(os.path.dirname(__file__))
+
+def relative(path):
+    return os.path.abspath(os.path.join(PATH, path))
+
 ADMINS = (
     # ('Your Name', 'your_email@domain.com'),
 )
 
 DATABASES = {
     'default': {
-        'ENGINE': 'django.db.backends.', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
-        'NAME': '',                      # Or path to database file if using sqlite3.
+        'ENGINE': 'django.db.backends.sqlite3', # Add 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+        'NAME': relative('data.db'),                      # Or path to database file if using sqlite3.
         'USER': '',                      # Not used with sqlite3.
         'PASSWORD': '',                  # Not used with sqlite3.
         'HOST': '',                      # Set to empty string for localhost. Not used with sqlite3.
 # Examples: "http://media.lawrence.com", "http://example.com/media/"
 MEDIA_URL = ''
 
+STATIC_URL = "/static/"
+
 # URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
 # trailing slash.
 # Examples: "http://foo.com/media/", "/media/".
 ROOT_URLCONF = 'autocomplete_test.urls'
 
 TEMPLATE_DIRS = (
+    relative('templates')
     # Put strings here, like "/home/html/django_templates" or "C:/www/django/templates".
     # Always use forward slashes, even on Windows.
     # Don't forget to use absolute paths, not relative paths.
     'django.contrib.sessions',
     'django.contrib.sites',
     'django.contrib.messages',
-    # Uncomment the next line to enable the admin:
-    # 'django.contrib.admin',
-    # Uncomment the next line to enable admin documentation:
-    # 'django.contrib.admindocs',
+    'django.contrib.staticfiles',
+    'django.contrib.admin',
+    'autocomplete_test.example',
+    'jautocomplete'
 )

autocomplete_test/templates/test.html

+<html>
+    <head>
+        <title>Test</title>
+        <script src="//ajax.googleapis.com/ajax/libs/jquery/1.5.1/jquery.js"></script>
+        {{ form.media }}
+    </head>
+    <body>
+        {{ form.as_p }}
+    </body>
+</html>
+ 

autocomplete_test/urls.py

 # admin.autodiscover()
 
 urlpatterns = patterns('',
+    url(r'^$', 'autocomplete_test.example.views.test'),
     # Example:
     # (r'^autocomplete_test/', include('autocomplete_test.foo.urls')),
 

jautocomplete/static/css/jquery.autocomplete.css

+.ac_results {
+	padding: 0px;
+	border: 1px solid black;
+	background-color: white;
+	overflow: hidden;
+	z-index: 99999;
+}
+
+.ac_results ul {
+	width: 100%;
+	list-style-position: outside;
+	list-style: none;
+	padding: 0;
+	margin: 0;
+}
+
+.ac_results li {
+	margin: 0px;
+	padding: 2px 5px;
+	cursor: default;
+	display: block;
+	/* 
+	if width will be 100% horizontal scrollbar will apear 
+	when scroll mode will be used
+	*/
+	/*width: 100%;*/
+	font: menu;
+	font-size: 12px;
+	/* 
+	it is very important, if line-height not setted or setted 
+	in relative units scroll will be broken in firefox
+	*/
+	line-height: 16px;
+	overflow: hidden;
+}
+
+.ac_loading {
+	background: white url('indicator.gif') right center no-repeat;
+}
+
+.ac_odd {
+	background-color: #eee;
+}
+
+.ac_over {
+	background-color: #0A246A;
+	color: white;
+}

jautocomplete/widgets.py

     """
     class Media:
         css = {
-                'all': ('%scss/jquery.autocomplete.css' % settings.MEDIA_URL,)
+                'all': ('%scss/jquery.autocomplete.css' % settings.STATIC_URL,)
         }
         js = (
-                '%sjs/jquery.js' % settings.MEDIA_URL,
-                '%sjs/jquery.autocomplete.js' % settings.MEDIA_URL,
-                '%sjs/autocomplete.popup.js ' % settings.MEDIA_URL
+                '%sjs/lib/jquery.autocomplete.js' % settings.STATIC_URL,
+                '%sjs/autocomplete.popup.js ' % settings.STATIC_URL
         )
 
     #def text_field_value(self, value):
         else:
             text_field_value = u''
         return rendered + mark_safe(javascript_template % {
-                            'MEDIA_URL': settings.MEDIA_URL,
+                            'MEDIA_URL': settings.STATIC_URL,
                             'text_field_value': text_field_value,
                             'text_field_size': 40,
                             'name': name,
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.