diff --git a/.gitignore b/.gitignore index 8ff7aa83..270271a5 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ build/ node_modules/ +*.pyc diff --git a/.vscode/launch.json b/.vscode/launch.json new file mode 100644 index 00000000..7b1271fd --- /dev/null +++ b/.vscode/launch.json @@ -0,0 +1,168 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${file}", + "cwd": "${workspaceRoot}", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "PySpark", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "osx": { + "pythonPath": "${env.SPARK_HOME}/bin/spark-submit" + }, + "windows": { + "pythonPath": "${env.SPARK_HOME}/bin/spark-submit.cmd" + }, + "linux": { + "pythonPath": "${env.SPARK_HOME}/bin/spark-submit" + }, + "program": "${file}", + "cwd": "${workspaceRoot}", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Python Module", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "module": "module.name", + "cwd": "${workspaceRoot}", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Integrated Terminal/Console", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${file}", + "cwd": "null", + "console": "integratedTerminal", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit" + ] + }, + { + "name": "External Terminal/Console", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${file}", + "cwd": "null", + "console": "externalTerminal", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit" + ] + }, + { + "name": "Django", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${workspaceRoot}/manage.py", + "cwd": "${workspaceRoot}", + "args": [ + "runserver", + "--noreload" + ], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput", + "DjangoDebugging" + ] + }, + { + "name": "Flask", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config.python.pythonPath}", + "program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter", + "cwd": "${workspaceRoot}", + "env": { + "FLASK_APP": "${workspaceRoot}/quickstart/app.py" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Flask (old)", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config.python.pythonPath}", + "program": "${workspaceRoot}/run.py", + "cwd": "${workspaceRoot}", + "args": [], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Watson", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${workspaceRoot}/console.py", + "cwd": "${workspaceRoot}", + "args": [ + "dev", + "runserver", + "--noreload=True" + ], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Attach (Remote Debug)", + "type": "python", + "request": "attach", + "localRoot": "${workspaceRoot}", + "remoteRoot": "${workspaceRoot}", + "port": 3000, + "secret": "my_secret", + "host": "localhost" + } + ] +} \ No newline at end of file diff --git a/.vscode/settings.json b/.vscode/settings.json new file mode 100644 index 00000000..0c4a6693 --- /dev/null +++ b/.vscode/settings.json @@ -0,0 +1,3 @@ +{ + "vsicons.presets.angular": false +} \ No newline at end of file diff --git a/demo/.vscode/launch.json b/demo/.vscode/launch.json new file mode 100644 index 00000000..7b1271fd --- /dev/null +++ b/demo/.vscode/launch.json @@ -0,0 +1,168 @@ +{ + "version": "0.2.0", + "configurations": [ + { + "name": "Python", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${file}", + "cwd": "${workspaceRoot}", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "PySpark", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "osx": { + "pythonPath": "${env.SPARK_HOME}/bin/spark-submit" + }, + "windows": { + "pythonPath": "${env.SPARK_HOME}/bin/spark-submit.cmd" + }, + "linux": { + "pythonPath": "${env.SPARK_HOME}/bin/spark-submit" + }, + "program": "${file}", + "cwd": "${workspaceRoot}", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Python Module", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "module": "module.name", + "cwd": "${workspaceRoot}", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Integrated Terminal/Console", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${file}", + "cwd": "null", + "console": "integratedTerminal", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit" + ] + }, + { + "name": "External Terminal/Console", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${file}", + "cwd": "null", + "console": "externalTerminal", + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit" + ] + }, + { + "name": "Django", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${workspaceRoot}/manage.py", + "cwd": "${workspaceRoot}", + "args": [ + "runserver", + "--noreload" + ], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput", + "DjangoDebugging" + ] + }, + { + "name": "Flask", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config.python.pythonPath}", + "program": "fully qualified path fo 'flask' executable. Generally located along with python interpreter", + "cwd": "${workspaceRoot}", + "env": { + "FLASK_APP": "${workspaceRoot}/quickstart/app.py" + }, + "args": [ + "run", + "--no-debugger", + "--no-reload" + ], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Flask (old)", + "type": "python", + "request": "launch", + "stopOnEntry": false, + "pythonPath": "${config.python.pythonPath}", + "program": "${workspaceRoot}/run.py", + "cwd": "${workspaceRoot}", + "args": [], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Watson", + "type": "python", + "request": "launch", + "stopOnEntry": true, + "pythonPath": "${config.python.pythonPath}", + "program": "${workspaceRoot}/console.py", + "cwd": "${workspaceRoot}", + "args": [ + "dev", + "runserver", + "--noreload=True" + ], + "debugOptions": [ + "WaitOnAbnormalExit", + "WaitOnNormalExit", + "RedirectOutput" + ] + }, + { + "name": "Attach (Remote Debug)", + "type": "python", + "request": "attach", + "localRoot": "${workspaceRoot}", + "remoteRoot": "${workspaceRoot}", + "port": 3000, + "secret": "my_secret", + "host": "localhost" + } + ] +} \ No newline at end of file diff --git a/demo/demo.sqlite b/demo/demo.sqlite new file mode 100644 index 00000000..a323c7a7 Binary files /dev/null and b/demo/demo.sqlite differ diff --git a/demo/example/__init__.pyc b/demo/example/__init__.pyc new file mode 100644 index 00000000..989ce996 Binary files /dev/null and b/demo/example/__init__.pyc differ diff --git a/demo/example/forms.pyc b/demo/example/forms.pyc new file mode 100644 index 00000000..1c0fcd4d Binary files /dev/null and b/demo/example/forms.pyc differ diff --git a/demo/example/migrations/0001_initial.py b/demo/example/migrations/0001_initial.py new file mode 100644 index 00000000..ce073462 --- /dev/null +++ b/demo/example/migrations/0001_initial.py @@ -0,0 +1,49 @@ +# -*- coding: utf-8 -*- +# Generated by Django 1.10.3 on 2016-11-28 17:23 +from __future__ import unicode_literals + +import datetime +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + initial = True + + dependencies = [ + ] + + operations = [ + migrations.CreateModel( + name='Order', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('customer', models.CharField(max_length=150)), + ('date', models.DateField(default=datetime.date.today, editable=False)), + ], + ), + migrations.CreateModel( + name='OrderedItem', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('quantity', models.PositiveSmallIntegerField()), + ('order', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='ordered_items', to='example.Order')), + ], + ), + migrations.CreateModel( + name='Product', + fields=[ + ('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')), + ('name', models.CharField(max_length=150)), + ], + options={ + 'ordering': ('name',), + }, + ), + migrations.AddField( + model_name='ordereditem', + name='product', + field=models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, related_name='orders', to='example.Product'), + ), + ] diff --git a/demo/example/migrations/0001_initial.pyc b/demo/example/migrations/0001_initial.pyc new file mode 100644 index 00000000..f38b08a6 Binary files /dev/null and b/demo/example/migrations/0001_initial.pyc differ diff --git a/demo/example/migrations/__init__.py b/demo/example/migrations/__init__.py new file mode 100644 index 00000000..e69de29b diff --git a/demo/example/migrations/__init__.pyc b/demo/example/migrations/__init__.pyc new file mode 100644 index 00000000..1361ac0a Binary files /dev/null and b/demo/example/migrations/__init__.pyc differ diff --git a/demo/example/models.pyc b/demo/example/models.pyc new file mode 100644 index 00000000..91ab7848 Binary files /dev/null and b/demo/example/models.pyc differ diff --git a/demo/example/urls.py b/demo/example/urls.py index 11bbcef2..d109e86f 100644 --- a/demo/example/urls.py +++ b/demo/example/urls.py @@ -1,35 +1,89 @@ -from django.conf.urls import patterns, url, include -from example.forms import AutoCompleteOrderedItemForm, OrderedItemForm, ContactFormset, MaxFiveContactsFormset, EmptyContactFormset, EventFormset -from example.forms import AutoCompleteSelectFieldForm - -urlpatterns = patterns('example.views', - url(r'^stacked/$', 'formset', {'formset_class': ContactFormset, 'template': 'example/formset-stacked.html'}, name='example_stacked'), - url(r'^table/$', 'formset', {'formset_class': ContactFormset, 'template': 'example/formset-table.html'}, name='example_table'), - url(r'^form-template/$', 'formset_with_template', {'formset_class': EmptyContactFormset, 'template': 'example/form-template.html'}, name='example_form_template'), - url(r'^admin-widget/$', 'formset', {'formset_class': EventFormset, 'template': 'example/formset-admin-widget.html'}, name='example_admin_widget'), - url(r'^multiple-formsets/$', 'multiple_formsets', {'template': 'example/formset-multiple-formsets.html'}, name='example_multiple_formsets'), - 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'^inline-formset-ajax-selects/$', 'inline_formset', - {'form_class': AutoCompleteSelectFieldForm, 'template': 'example/inline-formset-django-ajax-select.html'}, name='example_inline_ajax_selects'), - url(r'^autocomplete-products/$', 'autocomplete_products', name='example_autocomplete_products') -) - import django +from django.conf.urls import include, url + +from example.forms import (AutoCompleteOrderedItemForm, + AutoCompleteSelectFieldForm, ContactFormset, + EmptyContactFormset, EventFormset, + MaxFiveContactsFormset, OrderedItemForm) + +from .views import (autocomplete_products, formset, formset_with_template, + inline_formset, multiple_formsets) + +urlpatterns = [ + url(r'^stacked/$', + formset, + {'formset_class': ContactFormset, + 'template': 'example/formset-stacked.html'}, + name='example_stacked'), + + url(r'^table/$', + formset, + {'formset_class': ContactFormset, + 'template': 'example/formset-table.html'}, + name='example_table'), + + url(r'^form-template/$', + formset_with_template, + {'formset_class': EmptyContactFormset, + 'template': 'example/form-template.html'}, + name='example_form_template'), + + url(r'^admin-widget/$', + formset, + {'formset_class': EventFormset, + 'template': 'example/formset-admin-widget.html'}, + name='example_admin_widget'), + + url(r'^multiple-formsets/$', + multiple_formsets, + {'template': 'example/formset-multiple-formsets.html'}, + name='example_multiple_formsets'), + + 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'^inline-formset-ajax-selects/$', + inline_formset, + {'form_class': AutoCompleteSelectFieldForm, + 'template': 'example/inline-formset-django-ajax-select.html'}, + name='example_inline_ajax_selects'), + + url(r'^autocomplete-products/$', autocomplete_products, + name='example_autocomplete_products') +] + major, minor = django.VERSION[:2] if major >= 1 and minor >= 2: # These examples require Django 1.2 and above: - urlpatterns += patterns('example.views', - url(r'^max-forms/$', 'formset', {'formset_class': MaxFiveContactsFormset, 'template': 'example/max-forms.html'}, name='example_max_forms'), - url(r'^empty-form/$', 'formset', {'formset_class': EmptyContactFormset, 'template': 'example/empty-form.html'}, name='example_empty_form'), - ) + urlpatterns += [ + url(r'^max-forms/$', + formset, + {'formset_class': MaxFiveContactsFormset, + 'template': 'example/max-forms.html'}, + name='example_max_forms'), + url(r'^empty-form/$', + formset, + {'formset_class': EmptyContactFormset, + 'template': 'example/empty-form.html'}, + name='example_empty_form'), + ] -if major >=1 and minor >= 7: +if major >= 1 and minor >= 7: from example.forms import MinTwoContactsFormset # These examples require Django 1.7 and above: - urlpatterns += patterns('example.views', - url(r'^min-forms/$', 'formset', {'formset_class': MinTwoContactsFormset, 'template': 'example/min-forms.html'}, name='example_min_forms'), - ) \ No newline at end of file + urlpatterns += [ + url(r'^min-forms/$', + formset, + {'formset_class': MinTwoContactsFormset, + 'template': 'example/min-forms.html'}, name='example_min_forms'), + ] diff --git a/demo/example/urls.pyc b/demo/example/urls.pyc new file mode 100644 index 00000000..575e7b71 Binary files /dev/null and b/demo/example/urls.pyc differ diff --git a/demo/example/views.py b/demo/example/views.py index 0b824bb4..f60c718a 100644 --- a/demo/example/views.py +++ b/demo/example/views.py @@ -23,8 +23,7 @@ def formset(request, formset_class, template): return display_data(request, data) else: formset = formset_class() - return render_to_response(template, {'formset': formset}, - context_instance=RequestContext(request)) + return render_to_response(template, {'formset': formset}, ) def formset_with_template(request, formset_class, template): # If you're using a Django version older than 1.2, you won't have `formset.empty_form`; @@ -41,8 +40,7 @@ def formset_with_template(request, formset_class, template): if formset.is_valid(): data = formset.cleaned_data return display_data(request, data) - return render_to_response(template, {'form': form, 'formset': formset}, - context_instance=RequestContext(request)) + return render_to_response(template, {'form': form, 'formset': formset},) def inline_formset(request, form_class, template): OrderedItemFormset = get_ordereditem_formset(form_class, extra=1, can_delete=True) @@ -62,8 +60,7 @@ def inline_formset(request, form_class, template): else: form = OrderForm(instance=order) formset = OrderedItemFormset(instance=order) - return render_to_response(template, {'form': form, 'formset': formset}, - context_instance=RequestContext(request)) + return render_to_response(template, {'form': form, 'formset': formset},) def multiple_formsets(request, template): if request.method == 'POST': @@ -74,4 +71,4 @@ def multiple_formsets(request, template): else: contact_formset, event_formset = ContactFormset(prefix='contact_form'), EventFormset(prefix='event_form') return render_to_response(template, {'contact_formset': contact_formset, 'event_formset': event_formset}, - context_instance=RequestContext(request)) + ) diff --git a/demo/example/views.pyc b/demo/example/views.pyc new file mode 100644 index 00000000..a53849c7 Binary files /dev/null and b/demo/example/views.pyc differ diff --git a/demo/settings.py b/demo/settings.py index e28a1813..799b9038 100644 --- a/demo/settings.py +++ b/demo/settings.py @@ -38,7 +38,7 @@ # Absolute path to the directory that holds media. # Example: "/home/media/media.lawrence.com/" -MEDIA_ROOT = os.path.join(PROJECT_DIR, 'static') +MEDIA_ROOT = os.path.join(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). @@ -59,28 +59,55 @@ 'django.template.loaders.app_directories.Loader', ) -MIDDLEWARE_CLASSES = ( - 'django.middleware.common.CommonMiddleware', +# MIDDLEWARE_CLASSES = ( +# 'django.middleware.common.CommonMiddleware', +# 'django.contrib.sessions.middleware.SessionMiddleware', +# 'django.contrib.auth.middleware.AuthenticationMiddleware', +# ) + +MIDDLEWARE = [ + 'django.middleware.security.SecurityMiddleware', 'django.contrib.sessions.middleware.SessionMiddleware', + 'django.middleware.common.CommonMiddleware', + 'django.middleware.csrf.CsrfViewMiddleware', 'django.contrib.auth.middleware.AuthenticationMiddleware', -) + 'django.contrib.messages.middleware.MessageMiddleware', + 'django.middleware.clickjacking.XFrameOptionsMiddleware', -ROOT_URLCONF = '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'), -) +ROOT_URLCONF = 'urls' -TEMPLATE_CONTEXT_PROCESSORS = ( - 'django.contrib.auth.context_processors.auth', - 'django.core.context_processors.media', - #'django.core.context_processors.i18n', - #'django.core.context_processors.request', - #'django.core.context_processors.debug', -) +# 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'), +# ) + +TEMPLATES = [ + { + 'BACKEND': 'django.template.backends.django.DjangoTemplates', + 'DIRS': [os.path.join(PROJECT_DIR, 'templates')], + 'APP_DIRS': True, + 'OPTIONS': { + 'context_processors': [ + 'django.template.context_processors.debug', + 'django.template.context_processors.request', + 'django.contrib.auth.context_processors.auth', + 'django.contrib.messages.context_processors.messages', + ], + }, + }, +] + +# TEMPLATE_CONTEXT_PROCESSORS = ( +# 'django.contrib.auth.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', @@ -98,3 +125,7 @@ 'search_field': 'name', } } + +STATIC_URL = '/static/' + +STATICFILES_DIRS = (os.path.join(PROJECT_DIR, 'static'),) \ No newline at end of file diff --git a/demo/settings.pyc b/demo/settings.pyc new file mode 100644 index 00000000..4458bcc8 Binary files /dev/null and b/demo/settings.pyc differ diff --git a/demo/templates/base.html b/demo/templates/base.html index aa635b38..96eae367 100644 --- a/demo/templates/base.html +++ b/demo/templates/base.html @@ -1,3 +1,4 @@ +{% load i18n static %} - -{% block title %}Velkomm{% endblock %} :: Django Dynamic Formset Examples - - - -{% block extrahead %}{% endblock %} + + {% block title %}Velkomm{% endblock %} :: Django Dynamic Formset Examples + + + {% block extrahead %}{% endblock %} diff --git a/demo/templates/example/empty-form.html b/demo/templates/example/empty-form.html index 674f1c90..f469cfd5 100644 --- a/demo/templates/example/empty-form.html +++ b/demo/templates/example/empty-form.html @@ -14,13 +14,13 @@