From d55b3ad3a9effee5b2981553400f73458bdb622e Mon Sep 17 00:00:00 2001 From: Tomas Gavenciak Date: Sun, 17 May 2015 07:28:55 +0200 Subject: [PATCH] Autocomplete pro Skola (a pozdeji pro dalsi) --- mamweb/settings_common.py | 13 ++++++++----- mamweb/templates/admin/base_site.html | 7 +++++++ mamweb/templates/base.html | 1 + mamweb/urls.py | 1 + requirements.txt | 1 + seminar/admin.py | 3 ++- seminar/autocomplete_light_registry.py | 24 ++++++++++++++++++++++++ 7 files changed, 44 insertions(+), 6 deletions(-) create mode 100644 mamweb/templates/admin/base_site.html create mode 100644 seminar/autocomplete_light_registry.py diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index 02fde297..c842bfc2 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -78,13 +78,9 @@ TEMPLATE_CONTEXT_PROCESSORS = ( ) INSTALLED_APPS = ( - 'admin_tools', - 'admin_tools.theming', - 'admin_tools.menu', - 'admin_tools.dashboard', + # Basic - 'django.contrib.admin', 'django.contrib.auth', 'django.contrib.contenttypes', 'django.contrib.sessions', @@ -104,6 +100,13 @@ INSTALLED_APPS = ( 'mamweb', 'seminar', + # Prvni: + 'autocomplete_light', + 'admin_tools', + 'admin_tools.theming', + 'admin_tools.menu', + 'admin_tools.dashboard', + 'django.contrib.admin', ) DEBUG_TOOLBAR_CONFIG = { diff --git a/mamweb/templates/admin/base_site.html b/mamweb/templates/admin/base_site.html new file mode 100644 index 00000000..03e292f3 --- /dev/null +++ b/mamweb/templates/admin/base_site.html @@ -0,0 +1,7 @@ +{% extends "admin/base.html" %} +{% load staticfiles %} + +{% block extrahead %} + +{% include 'autocomplete_light/static.html' %} +{% endblock %} diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index 4aa19173..7fd235e3 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -10,6 +10,7 @@ + {% include 'autocomplete_light/static.html' %} diff --git a/mamweb/urls.py b/mamweb/urls.py index 0fcc599a..eb564ebe 100644 --- a/mamweb/urls.py +++ b/mamweb/urls.py @@ -10,6 +10,7 @@ urlpatterns = i18n_patterns('', url(r'^admin/', include(admin.site.urls)), # NOQA url(r'^admin_tools/', include('admin_tools.urls')), url(r'^ckeditor/', include('ckeditor.urls')), + url(r'^autocomplete/', include('autocomplete_light.urls')), url(r'^', include('seminar.urls')), url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'), ) diff --git a/requirements.txt b/requirements.txt index d782b0d0..5e7cba79 100644 --- a/requirements.txt +++ b/requirements.txt @@ -19,6 +19,7 @@ django-solo==1.1.0 django-ckeditor==4.4.7 django-admin-tools==0.5.2 django-taggit==0.14.0 +django-autocomplete-light==2.1.1 # debug tools/extensions diff --git a/seminar/admin.py b/seminar/admin.py index c8110d7f..56b2846d 100644 --- a/seminar/admin.py +++ b/seminar/admin.py @@ -6,7 +6,7 @@ from solo.admin import SingletonModelAdmin from ckeditor.widgets import CKEditorWidget from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni - +import autocomplete_light ### Nastaveni admin.site.register(Nastaveni, SingletonModelAdmin) @@ -29,6 +29,7 @@ admin.site.register(Skola, SkolaAdmin) ### Resitel class ResitelAdmin(reversion.VersionAdmin): + form = autocomplete_light.modelform_factory(Resitel) fieldsets = [ (None, {'fields': ['jmeno', 'prijmeni', 'user']}), (u'Škola', {'fields': ['skola', 'rok_maturity']}), diff --git a/seminar/autocomplete_light_registry.py b/seminar/autocomplete_light_registry.py new file mode 100644 index 00000000..34ba7d58 --- /dev/null +++ b/seminar/autocomplete_light_registry.py @@ -0,0 +1,24 @@ +import autocomplete_light +from models import Skola + +# This will generate a PersonAutocomplete class +autocomplete_light.register(Skola, + # Just like in ModelAdmin.search_fields + search_fields=['nazev', 'mesto', 'ulice'], + attrs={ + # This will set the input placeholder attribute: + 'placeholder': 'Skola', + # This will set the yourlabs.Autocomplete.minimumCharacters + # options, the naming conversion is handled by jQuery + 'data-autocomplete-minimum-characters': 1, + }, + # This will set the data-widget-maximum-values attribute on the + # widget container element, and will be set to + # yourlabs.Widget.maximumValues (jQuery handles the naming + # conversion). + widget_attrs={ + 'data-widget-maximum-values': 15, + # Enable modern-style widget ! + 'class': 'modern-style', + }, +)