Commits

Anonymous committed d1b4faa

initial files

Comments (0)

Files changed (15)

+syntax:glob
+*.pyc
+*~
+.*.swp

__init__.py

Empty file added.
+#!/usr/bin/env python
+from django.core.management import execute_manager
+try:
+    import settings # Assumed to be in the same directory.
+except ImportError:
+    import sys
+    sys.stderr.write("Error: Can't find the file 'settings.py' in the directory containing %r. It appears you've customized things.\nYou'll have to run django-admin.py, passing it your settings module.\n(If the file settings.py does indeed exist, it's causing an ImportError somehow.)\n" % __file__)
+    sys.exit(1)
+
+if __name__ == "__main__":
+    execute_manager(settings)

media/js/jquery_autocomplete.js

+function jquery_autocomplete(name, ac_url, force_selection) {
+    $(document).ready(function () {
+        var input = $('#id_' + name);
+        var hidden_input = $('#id_hidden_' + name);
+        input.autocomplete(ac_url, {
+            limit: 10,
+            dataType: 'json',
+            parse: function(data) {
+                var parsed = [];
+                for (var i in data) {
+                    row = {
+                        data: data[i][1]+'|'+data[i][0],
+                        value: data[i][0],
+                        result: data[i][1]
+                    };
+                    parsed[parsed.length] = row;
+                }
+                return parsed;
+            },    
+            formatItem: function(data, i, total, term) {
+                return data.split('|')[0];
+            }
+        });
+        input.result(function(event, data, formatted) {
+            hidden_input.val(data.split('|')[1]);
+        });
+        form = $("form:first");
+        form.submit(function() {
+            if (hidden_input.val() != input.val() && !force_selection) {
+                hidden_input.val(input.val());
+            }
+        });
+    });
+}
+
+autocomplete = jquery_autocomplete;

media/js/yui_autocomplete.js

+function yui_autocomplete(name, ac_url, force_selection) {
+
+    this.name = name;
+    this.ac_url = ac_url;
+    this.force_selection = force_selection;
+
+    this.setup = function () {
+        var datasource = new YAHOO.util.XHRDataSource(ac_url);
+        datasource.responseType = YAHOO.util.XHRDataSource.TYPE_JSON;
+        datasource.responseSchema = {
+            resultsList: "result",
+            fields: ["label", "id"]
+        };
+
+        datasource.doBeforeParseData = function (request, original, callback) {
+            var parsed = {"result": []};
+            for (var i in original)
+                parsed.result.push({"id": original[i][0], "label": original[i][1]});
+            return parsed;
+        };
+        datasource.resultTypeList = false;
+
+        var input = document.getElementById("id_"+name);
+        var container = document.createElement("div");
+        YAHOO.util.Dom.insertAfter(container, input);
+        if (!YAHOO.util.Dom.hasClass(document.body, "yui-skin-sam"))
+            YAHOO.util.Dom.addClass(document.body, "yui-skin-sam");
+
+        var autocomplete = new YAHOO.widget.AutoComplete(input, container, datasource);
+        autocomplete.resultTypeList = false;
+        autocomplete.queryDelay = .5;
+        autocomplete.forceSelection = force_selection;
+
+        var selected_item = {label: null, id: null};
+        var hidden = document.getElementById("id_hidden_"+name);
+        autocomplete.itemSelectEvent.subscribe(function (type, args) {
+            selected_item = args[2];
+            hidden.value = selected_item.id;
+        });
+        form = document.getElementsByTagName("form")[0];
+        YAHOO.util.Event.addListener(form, "submit", function (event, form) {
+            if (selected_item.label != input.value && !force_selection)
+                hidden.value = input.value;
+        });
+        this.datasource = datasource;
+        this.autocomplete = autocomplete;
+    };
+    YAHOO.util.Event.onDOMReady(this.setup, null, this);
+};
+
+autocomplete = yui_autocomplete;

runtime.db

Binary file added.

runtime/__init__.py

Empty file added.

runtime/fixtures/clienti.json

+[
+    {
+        "pk": 1, 
+        "model": "runtime.cliente", 
+        "fields": {
+            "Fax": null, 
+            "Via": null, 
+            "Tel": null, 
+            "nome": "Alfano", 
+            "Prov": null, 
+            "CAP": null, 
+            "CF": null, 
+            "sede": null, 
+            "PIVA": null, 
+            "Citta": null
+        }
+    }, 
+    {
+        "pk": 2, 
+        "model": "runtime.cliente", 
+        "fields": {
+            "Fax": null, 
+            "Via": null, 
+            "Tel": null, 
+            "nome": "Aldo", 
+            "Prov": null, 
+            "CAP": null, 
+            "CF": null, 
+            "sede": null, 
+            "PIVA": null, 
+            "Citta": null
+        }
+    }, 
+    {
+        "pk": 3, 
+        "model": "runtime.cliente", 
+        "fields": {
+            "Fax": null, 
+            "Via": null, 
+            "Tel": null, 
+            "nome": "Alfredo", 
+            "Prov": null, 
+            "CAP": null, 
+            "CF": null, 
+            "sede": null, 
+            "PIVA": null, 
+            "Citta": null
+        }
+    }, 
+    {
+        "pk": 4, 
+        "model": "runtime.cliente", 
+        "fields": {
+            "Fax": null, 
+            "Via": null, 
+            "Tel": null, 
+            "nome": "Alfonso", 
+            "Prov": null, 
+            "CAP": null, 
+            "CF": null, 
+            "sede": null, 
+            "PIVA": null, 
+            "Citta": null
+        }
+    }, 
+    {
+        "pk": 5, 
+        "model": "runtime.cliente", 
+        "fields": {
+            "Fax": null, 
+            "Via": null, 
+            "Tel": null, 
+            "nome": "Armando", 
+            "Prov": null, 
+            "CAP": null, 
+            "CF": null, 
+            "sede": null, 
+            "PIVA": null, 
+            "Citta": null
+        }
+    }
+]
+from django.forms import ModelForm
+from acexample.runtime.models import Committente
+
+from autocomplete.fields import ModelChoiceField
+
+class CommittenteForm(ModelForm):
+
+    class Meta:
+        model=Committente
+
+    idcliente = ModelChoiceField('cliente')
+
+from django.db import models
+
+class Cliente(models.Model):
+    nome=models.CharField(max_length=50)
+    sede=models.CharField(max_length=50, null=True, blank=True)
+    Via=models.CharField(max_length=50,null=True, blank=True)
+    CAP=models.CharField(max_length=5,null=True, blank=True)
+    Prov=models.CharField(max_length=2,null=True, blank=True)
+    Tel=models.CharField(max_length=20,null=True, blank=True)
+    Fax=models.CharField(max_length=20,null=True, blank=True)
+    Citta=models.CharField(max_length=50,null=True, blank=True)
+    PIVA=models.CharField(max_length=20,null=True, blank=True)
+    CF=models.CharField(max_length=20,null=True, blank=True)
+
+    def __unicode__(self):
+        return self.nome
+
+    class Meta:
+        verbose_name_plural = "Clienti"
+
+
+class Committente(models.Model):
+    idcliente=models.ForeignKey(Cliente)
+    nome=models.CharField(max_length=50)
+    telefono=models.CharField(max_length=20, null=True, blank=True)
+    cellulare=models.CharField(max_length=20, null=True, blank=True)
+    email=models.EmailField(null=True, blank=True)
+
+    def __unicode__(self):
+        return self.nome
+    
+    class Meta:
+        verbose_name_plural = "Committenti"
+
+"""
+This file demonstrates two different styles of tests (one doctest and one
+unittest). These will both pass when you run "manage.py test".
+
+Replace these 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.failUnlessEqual(1 + 1, 2)
+
+__test__ = {"doctest": """
+Another way to test that 1 + 1 is equal to 2.
+
+>>> 1 + 1 == 2
+True
+"""}
+
+from django.http import HttpResponse
+from django.shortcuts import render_to_response
+
+from acexample.runtime.forms import CommittenteForm as ExampleForm
+
+def example(request):
+    valid = False
+    if request.GET:
+        form = ExampleForm(request.GET)
+        if form.is_valid():
+            valid = True
+    else:
+        form = ExampleForm()
+
+    return render_to_response("autocomplete.html", {'form':form,'valid':valid})
+
+import os
+
+PROJECT_DIR = os.path.abspath(os.path.dirname(__file__))
+
+# Django settings for runtime project.
+
+DEBUG = True
+TEMPLATE_DEBUG = DEBUG
+
+ADMINS = (
+    # ('Your Name', 'your_email@domain.com'),
+)
+
+MANAGERS = ADMINS
+
+DATABASE_ENGINE = 'sqlite3'           # 'postgresql_psycopg2', 'postgresql', 'mysql', 'sqlite3' or 'oracle'.
+DATABASE_NAME = os.path.join(PROJECT_DIR, 'example.db')           # Or path to database file if using sqlite3.
+DATABASE_USER = ''             # Not used with sqlite3.
+DATABASE_PASSWORD = ''         # Not used with sqlite3.
+DATABASE_HOST = ''             # Set to empty string for localhost. Not used with sqlite3.
+DATABASE_PORT = ''             # Set to empty string for default. Not used with sqlite3.
+
+# Local time zone for this installation. Choices can be found here:
+# http://en.wikipedia.org/wiki/List_of_tz_zones_by_name
+# although not all choices may be available on all operating systems.
+# If running in a Windows environment this must be set to the same as your
+# system time zone.
+TIME_ZONE = 'America/Chicago'
+
+# Language code for this installation. All choices can be found here:
+# http://www.i18nguy.com/unicode/language-identifiers.html
+LANGUAGE_CODE = 'en-us'
+
+SITE_ID = 1
+
+# If you set this to False, Django will make some optimizations so as not
+# to load the internationalization machinery.
+USE_I18N = True
+
+# Absolute path to the directory that holds media.
+# Example: "/home/media/media.lawrence.com/"
+MEDIA_ROOT = os.path.join(PROJECT_DIR, 'media/')
+
+# URL that handles the media served from MEDIA_ROOT. Make sure to use a
+# trailing slash if there is a path component (optional in other cases).
+# Examples: "http://media.lawrence.com", "http://example.com/media/"
+MEDIA_URL = 'http://localhost:8000/media/'
+
+# URL prefix for admin media -- CSS, JavaScript and images. Make sure to use a
+# trailing slash.
+# Examples: "http://foo.com/media/", "/media/".
+ADMIN_MEDIA_PREFIX = '/admin-media/'
+
+# Make this unique, and don't share it with anybody.
+SECRET_KEY = '391l-xq=t(k257sh_$#14&qg8x-d2hm$)v5ud11wucj0p$r=bd'
+
+# List of callables that know how to import templates from various sources.
+TEMPLATE_LOADERS = (
+    'django.template.loaders.filesystem.load_template_source',
+    'django.template.loaders.app_directories.load_template_source',
+#     'django.template.loaders.eggs.load_template_source',
+)
+
+MIDDLEWARE_CLASSES = (
+    'django.middleware.common.CommonMiddleware',
+    'django.contrib.sessions.middleware.SessionMiddleware',
+    'django.contrib.auth.middleware.AuthenticationMiddleware',
+)
+
+ROOT_URLCONF = 'acexample.urls'
+
+TEMPLATE_DIRS = (
+    # 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.
+    '/'.join((PROJECT_DIR, 'templates')),
+)
+
+INSTALLED_APPS = (
+    'django.contrib.auth',
+    'django.contrib.contenttypes',
+    'django.contrib.sessions',
+    'django.contrib.sites',
+    'runtime',
+)

templates/autocomplete.html

+<html>
+  <head>
+    <title>Test</title>
+    {{ form.media }}
+
+  <style type="text/css">
+    .yui-skin-sam .yui-ac {
+      width: 25em;
+      padding-bottom: 2em;
+    }
+  </style>
+  </head>
+  <body class="yui-skin-sam">
+
+<h1>Aggiungi Committente</h1>
+<table class="tblform">
+<tr>
+<td width=10> </td>
+<td>
+
+  <form action="." method="get">
+    {% if valid %}
+    <h2>Form inviato correttamente!</h2>
+    {% endif %}
+<table>
+{{ form.as_table }}
+<tr>
+<td>
+<input type="submit" value="Aggiungi" />
+</td>
+</tr>
+</table>
+</form>
+
+</td>
+</tr>
+</table>
+
+
+  </body>
+</html>
+from django.conf.urls.defaults import *
+from django.conf import settings
+
+from autocomplete.views import autocomplete
+
+from acexample.runtime.models import Cliente
+
+# Uncomment the next two lines to enable the admin:
+# from django.contrib import admin
+# admin.autodiscover()
+autocomplete.register(
+    id = 'cliente',
+    queryset = Cliente.objects.all(),
+    fields = ('nome',),
+    limit = 5,
+)
+
+urlpatterns = patterns('',
+    # Example:
+    # (r'^runtime/', include('runtime.foo.urls')),
+
+    # Uncomment the admin/doc line below and add 'django.contrib.admindocs' 
+    # to INSTALLED_APPS to enable admin documentation:
+    # (r'^admin/doc/', include('django.contrib.admindocs.urls')),
+
+    # Uncomment the next line to enable the admin:
+    # (r'^admin/', include(admin.site.urls)),
+    url('^autocomplete/(\w+)/$', autocomplete, name='autocomplete'), 
+    url('^example/$', 'acexample.runtime.views.example'),
+
+    url(r'^media/(?P<path>.*)$', 'django.views.static.serve',
+        {'show_indexes': True,
+         'document_root': settings.MEDIA_ROOT}),
+)