forked from elo80ka/django-dynamic-formset
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Added minified version Added README.txt git-svn-id: https://django-dynamic-formset.googlecode.com/svn/trunk@2 9f2ace40-7153-11de-83e1-4fc93b4a6815
- Loading branch information
stan.madueke
committed
Oct 10, 2009
1 parent
51695e8
commit b622194
Showing
39 changed files
with
1,290 additions
and
0 deletions.
There are no files selected for viewing
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,17 @@ | ||
============================================ | ||
A jQuery plugin for managing Django formsets | ||
============================================ | ||
|
||
This jQuery_ plugin helps you create more usable Django_ formsets by | ||
allowing clients add and remove forms on the client-side. | ||
|
||
For installation instructions, see the file ``INSTALL.txt`` in | ||
this directory; for documentation see the files in the ``docs/`` | ||
directory. | ||
|
||
The latest versions of these documents can always be viewed on the | ||
Google Code project web site for this application, which is located at | ||
http://code.google.com/p/django-dynamic-formset/. | ||
|
||
.. _jQuery: http://jquery.com/ | ||
.. _Django: http://www.djangoproject.com/ |
Empty file.
Empty file.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Black-eyed Peas" | ||
} | ||
}, | ||
{ | ||
"pk": 10, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Kidney Beans" | ||
} | ||
}, | ||
{ | ||
"pk": 3, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Minty Loin of Lamb" | ||
} | ||
}, | ||
{ | ||
"pk": 7, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Olive Oil (Extra Virgin)" | ||
} | ||
}, | ||
{ | ||
"pk": 8, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Oreos" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Prime Bac'n" | ||
} | ||
}, | ||
{ | ||
"pk": 9, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Reese's Peanut Butter Cups" | ||
} | ||
}, | ||
{ | ||
"pk": 6, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Rice Wine Vinegar" | ||
} | ||
}, | ||
{ | ||
"pk": 4, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Sweetcorn" | ||
} | ||
}, | ||
{ | ||
"pk": 5, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Szechuan Peppercorn" | ||
} | ||
}, | ||
{ | ||
"pk": 11, | ||
"model": "example.product", | ||
"fields": { | ||
"name": "Uncle Bob's Hot, Hot Sauce" | ||
} | ||
} | ||
] |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,48 @@ | ||
from django import forms | ||
from django.forms import fields, models, formsets, widgets | ||
from example.models import Product, Order, OrderedItem | ||
|
||
class OrderForm(models.ModelForm): | ||
class Meta: | ||
model = Order | ||
|
||
class OrderedItemForm(models.ModelForm): | ||
class Meta: | ||
model = OrderedItem | ||
|
||
class AutoCompleteOrderedItemForm(models.ModelForm): | ||
""" | ||
Display the Ordered Item form with an autocomplete textbox for the | ||
Products instead of the Dropdown List. | ||
""" | ||
|
||
class Meta: | ||
model = OrderedItem | ||
|
||
class Media: | ||
js = ('js/jquery.autocomplete.min.js', 'js/autocomplete-init.js',) | ||
css = { | ||
'all': ('css/jquery.autocomplete.css',), | ||
} | ||
|
||
def __init__(self, *args, **kwargs): | ||
super(AutoCompleteOrderedItemForm, self).__init__(*args, **kwargs) | ||
self.fields['product'].widget = widgets.TextInput(attrs={'class': 'autocomplete-me'}) | ||
|
||
def get_ordereditem_formset(form, formset=models.BaseInlineFormSet, **kwargs): | ||
return models.inlineformset_factory(Order, OrderedItem, form, formset, **kwargs) | ||
|
||
CONTACT_INFO_TYPES = ( | ||
('Phone', 'Phone'), | ||
('Fax', 'Fax'), | ||
('Email', 'Email'), | ||
('AIM', 'AIM'), | ||
('Gtalk', 'Gtalk/Jabber'), | ||
('Yahoo', 'Yahoo'), | ||
) | ||
|
||
class ContactInfoForm(forms.Form): | ||
type = fields.ChoiceField(choices=CONTACT_INFO_TYPES) | ||
value = fields.CharField(max_length=200) | ||
|
||
ContactFormset = formsets.formset_factory(ContactInfoForm) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
|
||
# Test with inlineformsets and inlinemodelformsets | ||
# Test with fieldsets (admin)? | ||
|
||
from django.db import models | ||
from django.template.defaultfilters import pluralize | ||
from datetime import date | ||
|
||
class Product(models.Model): | ||
name = models.CharField(max_length=150) | ||
|
||
class Meta: | ||
ordering = ('name',) | ||
|
||
def __unicode__(self): | ||
return self.name | ||
|
||
class Order(models.Model): | ||
customer = models.CharField(max_length=150) | ||
date = models.DateField(default=date.today, editable=False) | ||
|
||
def __unicode__(self): | ||
return u"%s's order" % self.customer | ||
|
||
class OrderedItem(models.Model): | ||
order = models.ForeignKey(Order, related_name='ordered_items') | ||
product = models.ForeignKey(Product, related_name='orders') | ||
quantity = models.PositiveSmallIntegerField() | ||
|
||
def __unicode__(self): | ||
return u"%s (%d)" % (self.product, self.quantity) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,12 @@ | ||
from django.conf.urls.defaults import * | ||
from example.forms import AutoCompleteOrderedItemForm, OrderedItemForm | ||
|
||
urlpatterns = patterns('example.views', | ||
url(r'^stacked/$', 'formset', {'template': 'example/formset-stacked.html'}, name='example_stacked'), | ||
url(r'^table/$', 'formset', {'template': 'example/formset-table.html'}, name='example_table'), | ||
url(r'^inline-formset/$', 'inline_formset', | ||
{'form_class': OrderedItemForm, 'template': 'example/inline-formset.html'}, name='example_inline_formset'), | ||
url(r'^inline-formset-autocomplete/$', 'inline_formset', | ||
{'form_class': AutoCompleteOrderedItemForm, 'template': 'example/inline-formset-autocomplete.html'}, name='example_inline_autocomplete'), | ||
url(r'^autocomplete-products/$', 'autocomplete_products', name='example_autocomplete_products') | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,40 @@ | ||
from django.http import HttpResponse | ||
from django.shortcuts import render_to_response | ||
from django.template.context import RequestContext | ||
from example.forms import ContactFormset, Order, OrderForm, get_ordereditem_formset | ||
from example.models import Order, Product | ||
|
||
def autocomplete_products(request): | ||
q = request.GET.get('q', '') | ||
products = Product.objects.filter(name__icontains=q).values_list('pk', 'name') | ||
output = u'\n'.join([u'%d|%s' % tuple(product) for product in products]) | ||
return HttpResponse(output, mimetype='text/plain') | ||
|
||
def display_data(request, data): | ||
return render_to_response('example/posted-data.html', {'data': data}, | ||
context_instance=RequestContext(request)) | ||
|
||
def formset(request, template): | ||
if request.method == 'POST': | ||
formset = ContactFormset(request.POST) | ||
if formset.is_valid(): | ||
data = formset.cleaned_data | ||
return display_data(request, data) | ||
else: | ||
formset = ContactFormset() | ||
return render_to_response(template, {'formset': formset}, | ||
context_instance=RequestContext(request)) | ||
|
||
def inline_formset(request, form_class, template): | ||
OrderedItemFormset = get_ordereditem_formset(form_class, extra=1) | ||
if request.method == 'POST': | ||
form = OrderForm(request.POST) | ||
formset = OrderedItemFormset(request.POST) | ||
if form.is_valid() and formset.is_valid(): | ||
data = formset.cleaned_data | ||
return display_data(request, data) | ||
else: | ||
form = OrderForm() | ||
formset = OrderedItemFormset() | ||
return render_to_response(template, {'form': form, 'formset': formset}, | ||
context_instance=RequestContext(request)) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,11 @@ | ||
#!/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) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,91 @@ | ||
# Django settings for demo project. | ||
import os | ||
|
||
PROJECT_DIR = os.path.normpath(os.path.dirname(__file__)) | ||
|
||
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 = 'demo.sqlite' # 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 = 'Africa/Lagos' | ||
|
||
# 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, 'static') | ||
|
||
# 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 = '/static/' | ||
|
||
# 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 = '/media/' | ||
|
||
# Make this unique, and don't share it with anybody. | ||
SECRET_KEY = 's2r2k*nqosri4%)5c8w^--jpv+8tzrvbzr11p-frp9kq5ot13v' | ||
|
||
# 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', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'django.middleware.common.CommonMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'demo.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. | ||
os.path.join(PROJECT_DIR, 'templates'), | ||
) | ||
|
||
TEMPLATE_CONTEXT_PROCESSORS = ( | ||
'django.core.context_processors.auth', | ||
'django.core.context_processors.media', | ||
#'django.core.context_processors.i18n', | ||
#'django.core.context_processors.request', | ||
#'django.core.context_processors.debug', | ||
) | ||
|
||
INSTALLED_APPS = ( | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.sites', | ||
'example', | ||
) |
Oops, something went wrong.