Browse Source

Autocomplete pro Skola (a pozdeji pro dalsi)

remotes/origin/feincms
Tomas Gavenciak 10 years ago
parent
commit
d55b3ad3a9
  1. 13
      mamweb/settings_common.py
  2. 7
      mamweb/templates/admin/base_site.html
  3. 1
      mamweb/templates/base.html
  4. 1
      mamweb/urls.py
  5. 1
      requirements.txt
  6. 3
      seminar/admin.py
  7. 24
      seminar/autocomplete_light_registry.py

13
mamweb/settings_common.py

@ -78,13 +78,9 @@ TEMPLATE_CONTEXT_PROCESSORS = (
) )
INSTALLED_APPS = ( INSTALLED_APPS = (
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
# Basic # Basic
'django.contrib.admin',
'django.contrib.auth', 'django.contrib.auth',
'django.contrib.contenttypes', 'django.contrib.contenttypes',
'django.contrib.sessions', 'django.contrib.sessions',
@ -104,6 +100,13 @@ INSTALLED_APPS = (
'mamweb', 'mamweb',
'seminar', 'seminar',
# Prvni:
'autocomplete_light',
'admin_tools',
'admin_tools.theming',
'admin_tools.menu',
'admin_tools.dashboard',
'django.contrib.admin',
) )
DEBUG_TOOLBAR_CONFIG = { DEBUG_TOOLBAR_CONFIG = {

7
mamweb/templates/admin/base_site.html

@ -0,0 +1,7 @@
{% extends "admin/base.html" %}
{% load staticfiles %}
{% block extrahead %}
<script src="{% static 'js/jquery-1.11.1.js' %}"></script>
{% include 'autocomplete_light/static.html' %}
{% endblock %}

1
mamweb/templates/base.html

@ -10,6 +10,7 @@
<link href="{% static 'css/mamweb.css' %}" rel="stylesheet"> <link href="{% static 'css/mamweb.css' %}" rel="stylesheet">
<link href="{% static 'css/prettyPhoto.css' %}" rel="stylesheet" type="text/css" media="screen" charset="utf-8" /> <link href="{% static 'css/prettyPhoto.css' %}" rel="stylesheet" type="text/css" media="screen" charset="utf-8" />
<script src="{% static 'js/jquery-1.11.1.js' %}"></script> <script src="{% static 'js/jquery-1.11.1.js' %}"></script>
{% include 'autocomplete_light/static.html' %}
</head> </head>
<body class='{% if True %}org-logged-in{% endif %}'> <body class='{% if True %}org-logged-in{% endif %}'>
<!-- TODO: only on org login --> <!-- TODO: only on org login -->

1
mamweb/urls.py

@ -10,6 +10,7 @@ urlpatterns = i18n_patterns('',
url(r'^admin/', include(admin.site.urls)), # NOQA url(r'^admin/', include(admin.site.urls)), # NOQA
url(r'^admin_tools/', include('admin_tools.urls')), url(r'^admin_tools/', include('admin_tools.urls')),
url(r'^ckeditor/', include('ckeditor.urls')), url(r'^ckeditor/', include('ckeditor.urls')),
url(r'^autocomplete/', include('autocomplete_light.urls')),
url(r'^', include('seminar.urls')), url(r'^', include('seminar.urls')),
url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'), url(r'^$', TemplateView.as_view(template_name='home.html'), name='home'),
) )

1
requirements.txt

@ -19,6 +19,7 @@ django-solo==1.1.0
django-ckeditor==4.4.7 django-ckeditor==4.4.7
django-admin-tools==0.5.2 django-admin-tools==0.5.2
django-taggit==0.14.0 django-taggit==0.14.0
django-autocomplete-light==2.1.1
# debug tools/extensions # debug tools/extensions

3
seminar/admin.py

@ -6,7 +6,7 @@ from solo.admin import SingletonModelAdmin
from ckeditor.widgets import CKEditorWidget from ckeditor.widgets import CKEditorWidget
from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni from seminar.models import Skola, Resitel, Rocnik, Cislo, Problem, Reseni, PrilohaReseni, Nastaveni, Soustredeni
import autocomplete_light
### Nastaveni ### Nastaveni
admin.site.register(Nastaveni, SingletonModelAdmin) admin.site.register(Nastaveni, SingletonModelAdmin)
@ -29,6 +29,7 @@ admin.site.register(Skola, SkolaAdmin)
### Resitel ### Resitel
class ResitelAdmin(reversion.VersionAdmin): class ResitelAdmin(reversion.VersionAdmin):
form = autocomplete_light.modelform_factory(Resitel)
fieldsets = [ fieldsets = [
(None, {'fields': ['jmeno', 'prijmeni', 'user']}), (None, {'fields': ['jmeno', 'prijmeni', 'user']}),
(u'Škola', {'fields': ['skola', 'rok_maturity']}), (u'Škola', {'fields': ['skola', 'rok_maturity']}),

24
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',
},
)
Loading…
Cancel
Save