diff --git a/galerie/admin.py b/galerie/admin.py index 98c83ea9..f0ac6e28 100644 --- a/galerie/admin.py +++ b/galerie/admin.py @@ -5,7 +5,6 @@ from django.contrib import admin from django.http import HttpResponseRedirect from django import forms from django.db import models -from autocomplete_light import shortcuts as autocomplete_light # akction @@ -39,11 +38,12 @@ class GalerieInline(admin.TabularInline): class ObrazekAdmin(admin.ModelAdmin): list_display = ('obrazek_velky', 'nazev', 'popis', 'obrazek_maly_tag') + search_fields = ['nazev','popis'] class GalerieAdmin(admin.ModelAdmin): - form = autocomplete_light.modelform_factory(Galerie, autocomplete_fields=['titulni_obrazek'], fields=['titulni_obrazek']) model = Galerie fields = ('zobrazit', 'nazev', 'titulni_obrazek', 'popis', 'galerie_up', 'soustredeni', 'poradi') + autocomplete_fields = ['titulni_obrazek'] list_display = ('nazev', 'soustredeni', 'galerie_up', 'poradi', 'zobrazit', 'datum_zmeny') inlines = [GalerieInline] actions = [zverejnit_fotogalerii, prepnout_fotogalerii_do_org_rezimu] diff --git a/galerie/autocomplete_light_registry.py b/galerie/autocomplete_light_registry.py.old similarity index 100% rename from galerie/autocomplete_light_registry.py rename to galerie/autocomplete_light_registry.py.old diff --git a/mamweb/settings_common.py b/mamweb/settings_common.py index ce471e70..e686fcd6 100644 --- a/mamweb/settings_common.py +++ b/mamweb/settings_common.py @@ -103,7 +103,8 @@ INSTALLED_APPS = ( 'ckeditor', 'ckeditor_uploader', 'taggit', - 'autocomplete_light', + 'dal', + 'dal_select2', 'fluent_comments', 'crispy_forms', diff --git a/mamweb/templates/admin/base_site.html b/mamweb/templates/admin/base_site.html index 2b364bca..7e8707ef 100644 --- a/mamweb/templates/admin/base_site.html +++ b/mamweb/templates/admin/base_site.html @@ -4,7 +4,6 @@ {% block extrahead %} -{% include 'autocomplete_light/static.html' %} {% endblock %} {% block branding %} diff --git a/mamweb/templates/base.html b/mamweb/templates/base.html index aeb5f51b..208f797f 100644 --- a/mamweb/templates/base.html +++ b/mamweb/templates/base.html @@ -11,7 +11,6 @@ - {% include 'autocomplete_light/static.html' %} diff --git a/mamweb/urls.py b/mamweb/urls.py index 6294fac4..0c8877a2 100644 --- a/mamweb/urls.py +++ b/mamweb/urls.py @@ -11,7 +11,6 @@ urlpatterns = [ # Admin a nastroje path('admin/', admin.site.urls), # NOQA path('ckeditor/', include('ckeditor_uploader.urls')), - path('autocomplete/', include('autocomplete_light.urls')), # Seminarova aplikace (ma vlastni podadresare) path('', include('seminar.urls')), diff --git a/requirements.txt b/requirements.txt index 2bcec862..99794896 100644 --- a/requirements.txt +++ b/requirements.txt @@ -22,7 +22,7 @@ django-solo django-ckeditor django-flat-theme django-taggit -django-autocomplete-light==2.3.6 +django-autocomplete-light django-crispy-forms django-imagekit django-polymorphic diff --git a/seminar/autocomplete_light_registry.py b/seminar/autocomplete_light_registry.py.old similarity index 100% rename from seminar/autocomplete_light_registry.py rename to seminar/autocomplete_light_registry.py.old diff --git a/seminar/forms.py b/seminar/forms.py index d2a710cb..b0aa6f72 100644 --- a/seminar/forms.py +++ b/seminar/forms.py @@ -1,6 +1,12 @@ from django import forms +from dal import autocomplete +from .models import Skola + from seminar.models import Resitel + + + class PrihlaskaForm(forms.Form): jmeno = forms.CharField(label='Jméno', max_length=256, required=True) prijmeni = forms.CharField(label='Příjmení', max_length=256, required=True) @@ -20,6 +26,10 @@ class PrihlaskaForm(forms.Form): ('other', 'Jiné')), required=False) + skola = forms.ModelChoiceField( + queryset=Skola.objects.all(), + widget=autocomplete.ModelSelect2(url='autocomplete_skola') + ) # skola_stat_select = forms.ChoiceField(label='Stát', # choices = (('cz', 'Česká Republika'), diff --git a/seminar/templates/seminar/prihlaska.html b/seminar/templates/seminar/prihlaska.html index 28eb81b1..35e49163 100644 --- a/seminar/templates/seminar/prihlaska.html +++ b/seminar/templates/seminar/prihlaska.html @@ -1,8 +1,10 @@ {% extends "seminar/zadani/base.html" %} {% load staticfiles %} +{% load static %} {% block script %} + {% endblock %} {% block content %} @@ -35,5 +37,7 @@ $("#id_kraj_select").on("change",region_changed); //$("#id_skola_stat_select").on("change",country_changed); +{{form.media}} + {% endblock %} diff --git a/seminar/urls.py b/seminar/urls.py index d3b8c645..a8d4ff76 100644 --- a/seminar/urls.py +++ b/seminar/urls.py @@ -100,6 +100,7 @@ urlpatterns = [ path('prihlaska/',views.prihlaskaView), path('', views.TitulniStranaView.as_view(), name='titulni_strana'), + path('autocomplete/skola/',views.SkolaAutocomplete.as_view(), name='autocomplete_skola') # Ceka na autocomplete v3 # path('autocomplete/organizatori/', # staff_member_required(views.OrganizatorAutocomplete.as_view()), diff --git a/seminar/views.py b/seminar/views.py index d64ce300..69d110b0 100644 --- a/seminar/views.py +++ b/seminar/views.py @@ -10,8 +10,9 @@ from django.http import Http404,HttpResponseBadRequest,HttpResponseRedirect from django.db.models import Q from django.views.decorators.csrf import ensure_csrf_cookie from django.contrib.auth import authenticate, login, get_user_model +from dal import autocomplete -from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Tema, Clanek, Osoba +from .models import Problem, Cislo, Reseni, Nastaveni, Rocnik, Soustredeni, Organizator, Resitel, Novinky, Soustredeni_Ucastnici, Pohadka, Tema, Clanek, Osoba, Skola #from .models import VysledkyZaCislo, VysledkyKCisluZaRocnik, VysledkyKCisluOdjakziva from . import utils from .unicodecsv import UnicodeWriter @@ -1011,7 +1012,11 @@ def prihlaskaView(request): r.save() r.osoba = o - #TODO doplnit skolu + if form.cleaned_data.get('skola'): + r.skola = form.cleaned_data['skola'] + else: + pass + #TODO doplnit skolu, kdyz neni v seznamu r.save() @@ -1025,6 +1030,19 @@ def prihlaskaView(request): return render(request, 'seminar/prihlaska.html', {'form': form}) +class SkolaAutocomplete(autocomplete.Select2QuerySetView): + def get_queryset(self): + # Don't forget to filter out results depending on the visitor ! + qs = Skola.objects.all() + if self.q: + qs = qs.filter( + Q(nazev__istartswith=self.q)| + Q(kratky_nazev__istartswith=self.q)| + Q(ulice__istartswith=self.q)| + Q(mesto__istartswith=self.q)) + + return qs + # Ceka na autocomplete v3 # class OrganizatorAutocomplete(autocomplete.Select2QuerySetView): # def get_queryset(self):