Permalink
Browse files

page selecter in LinkPlugin via select2 working

  • Loading branch information...
digi604 committed Oct 23, 2012
1 parent af529e6 commit 944d3f07981f56d3e93b773f0e75b1bf0deb305b
View
@@ -6,10 +6,11 @@
from cms.forms.widgets import PageSelectWidget
from cms.forms.utils import get_site_choices, get_page_choices
+
class SuperLazyIterator(object):
def __init__(self, func):
self.func = func
-
+
def __iter__(self):
return iter(self.func())
@@ -26,17 +27,17 @@ def __init__(self, queryset, empty_label=u"---------", cache_choices=False,
errors.update(kwargs['error_messages'])
site_choices = SuperLazyIterator(get_site_choices)
page_choices = SuperLazyIterator(get_page_choices)
- kwargs['required']=required
+ kwargs['required'] = required
fields = (
forms.ChoiceField(choices=site_choices, required=False, error_messages={'invalid': errors['invalid_site']}),
forms.ChoiceField(choices=page_choices, required=False, error_messages={'invalid': errors['invalid_page']}),
)
super(PageSelectFormField, self).__init__(fields, *args, **kwargs)
-
+
def compress(self, data_list):
if data_list:
page_id = data_list[1]
-
+
if page_id in EMPTY_VALUES:
if not self.required:
return None
@@ -46,4 +47,12 @@ def compress(self, data_list):
class PlaceholderFormField(forms.Field):
- pass
+ pass
+
+try:
+ from django_select2.fields import AutoModelSelect2Field
+
+ class PageSearchField(AutoModelSelect2Field):
+ search_fields = ['title_set__title']
+except:
+ pass
View
@@ -1,18 +1,23 @@
from django.forms.models import ModelForm
from django.utils.translation import ugettext_lazy as _
from cms.plugins.link.models import Link
-from django import forms
from cms.models import Page
+
class LinkForm(ModelForm):
- page_link = forms.ModelChoiceField(label=_("page"), queryset=Page.objects.drafts(), required=False)
-
- def for_site(self, site):
+ try:
+ from cms.forms.fields import PageSearchField
+ page_link = PageSearchField(label=_("page"), queryset=Page.objects.drafts(), required=False, search_fields=['title_set__name'])
+ except:
+ from django import forms
+ page_link = forms.ModelChoiceField(label=_("page"), queryset=Page.objects.drafts(), required=False)
+
+ def for_site(self, site):
# override the page_link fields queryset to containt just pages for
# current site
self.fields['page_link'].queryset = Page.objects.drafts().on_site(site)
-
+
class Meta:
model = Link
- exclude = ('page', 'position', 'placeholder', 'language', 'plugin_type')
+ exclude = ('page', 'position', 'placeholder', 'language', 'plugin_type')
View
@@ -12,33 +12,33 @@ def configure(**extra):
from django.conf import settings
os.environ['DJANGO_SETTINGS_MODULE'] = 'cms.test_utils.cli'
defaults = dict(
- CACHE_BACKEND = 'locmem:///',
- DEBUG = True,
- TEMPLATE_DEBUG = True,
- DATABASE_SUPPORTS_TRANSACTIONS = True,
- DATABASES = {
+ CACHE_BACKEND='locmem:///',
+ DEBUG=True,
+ TEMPLATE_DEBUG=True,
+ DATABASE_SUPPORTS_TRANSACTIONS=True,
+ DATABASES={
'default': {
'ENGINE': 'django.db.backends.sqlite3',
'NAME': ':memory:',
}
},
- SITE_ID = 1,
- USE_I18N = True,
- MEDIA_ROOT = '/media/',
- STATIC_ROOT = '/static/',
- CMS_MEDIA_ROOT = '/cms-media/',
- CMS_MEDIA_URL = '/cms-media/',
- MEDIA_URL = '/media/',
- STATIC_URL = '/static/',
- ADMIN_MEDIA_PREFIX = '/static/admin/',
- EMAIL_BACKEND = 'django.core.mail.backends.locmem.EmailBackend',
- SECRET_KEY = 'key',
- TEMPLATE_LOADERS = (
+ SITE_ID=1,
+ USE_I18N=True,
+ MEDIA_ROOT='/media/',
+ STATIC_ROOT='/static/',
+ CMS_MEDIA_ROOT='/cms-media/',
+ CMS_MEDIA_URL='/cms-media/',
+ MEDIA_URL='/media/',
+ STATIC_URL='/static/',
+ ADMIN_MEDIA_PREFIX='/static/admin/',
+ EMAIL_BACKEND='django.core.mail.backends.locmem.EmailBackend',
+ SECRET_KEY='key',
+ TEMPLATE_LOADERS=(
'django.template.loaders.filesystem.Loader',
'django.template.loaders.app_directories.Loader',
'django.template.loaders.eggs.Loader',
),
- TEMPLATE_CONTEXT_PROCESSORS = [
+ TEMPLATE_CONTEXT_PROCESSORS=[
"django.contrib.auth.context_processors.auth",
"django.core.context_processors.i18n",
"django.core.context_processors.debug",
@@ -49,10 +49,10 @@ def configure(**extra):
"sekizai.context_processors.sekizai",
"django.core.context_processors.static",
],
- TEMPLATE_DIRS = [
+ TEMPLATE_DIRS=[
os.path.abspath(os.path.join(os.path.dirname(__file__), 'project', 'templates'))
],
- MIDDLEWARE_CLASSES = [
+ MIDDLEWARE_CLASSES=[
'django.contrib.sessions.middleware.SessionMiddleware',
'django.middleware.csrf.CsrfViewMiddleware',
'django.contrib.auth.middleware.AuthenticationMiddleware',
@@ -64,7 +64,7 @@ def configure(**extra):
'cms.middleware.page.CurrentPageMiddleware',
'cms.middleware.toolbar.ToolbarMiddleware',
],
- INSTALLED_APPS = [
+ INSTALLED_APPS=[
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
@@ -95,27 +95,28 @@ def configure(**extra):
'south',
'reversion',
'sekizai',
+ 'django_select2',
],
- LANGUAGE_CODE = "en",
- LANGUAGES = (
+ LANGUAGE_CODE="en",
+ LANGUAGES=(
('en', gettext('English')),
('fr', gettext('French')),
('de', gettext('German')),
('pt-br', gettext('Brazilian Portuguese')),
('nl', gettext("Dutch")),
),
- CMS_LANGUAGES = {
+ CMS_LANGUAGES={
1: [
{
'code':'en',
'name':gettext('English'),
- 'fallbacks':['fr','de'],
+ 'fallbacks':['fr', 'de'],
'public':True,
},
{
'code':'de',
'name':gettext('German'),
- 'fallbacks':['fr','en'],
+ 'fallbacks':['fr', 'en'],
'public':True,
},
{
@@ -133,7 +134,7 @@ def configure(**extra):
{
'code':'de',
'name':gettext('German'),
- 'fallbacks':['fr','en'],
+ 'fallbacks':['fr', 'en'],
'public':True,
},
{
@@ -146,20 +147,20 @@ def configure(**extra):
{
'code':'nl',
'name':gettext('Dutch'),
- 'fallbacks':['fr','en'],
+ 'fallbacks':['fr', 'en'],
'public':True,
},
],
'default': {
'hide_untranslated':False,
},
},
- CMS_TEMPLATES = (
+ CMS_TEMPLATES=(
('col_two.html', gettext('two columns')),
('col_three.html', gettext('three columns')),
('nav_playground.html', gettext('navigation examples')),
),
- CMS_PLACEHOLDER_CONF = {
+ CMS_PLACEHOLDER_CONF={
'col_sidebar': {
'plugins': ('FilePlugin', 'FlashPlugin', 'LinkPlugin', 'PicturePlugin',
'TextPlugin', 'SnippetPlugin'),
@@ -168,13 +169,13 @@ def configure(**extra):
'col_left': {
'plugins': ('FilePlugin', 'FlashPlugin', 'LinkPlugin', 'PicturePlugin',
- 'TextPlugin', 'SnippetPlugin','GoogleMapPlugin',),
+ 'TextPlugin', 'SnippetPlugin', 'GoogleMapPlugin',),
'name': gettext("left column")
},
'col_right': {
'plugins': ('FilePlugin', 'FlashPlugin', 'LinkPlugin', 'PicturePlugin',
- 'TextPlugin', 'SnippetPlugin','GoogleMapPlugin',),
+ 'TextPlugin', 'SnippetPlugin', 'GoogleMapPlugin',),
'name': gettext("right column")
},
'extra_context': {
@@ -183,35 +184,35 @@ def configure(**extra):
"name": "extra context"
},
},
- CMS_SOFTROOT = True,
- CMS_MODERATOR = True,
- CMS_PERMISSION = True,
- CMS_PUBLIC_FOR = 'all',
- CMS_CACHE_DURATIONS = {
+ CMS_SOFTROOT=True,
+ CMS_MODERATOR=True,
+ CMS_PERMISSION=True,
+ CMS_PUBLIC_FOR='all',
+ CMS_CACHE_DURATIONS={
'menus': 0,
'content': 0,
'permissions': 0,
},
CMS_APPHOOKS=[],
- CMS_REDIRECTS = True,
- CMS_SEO_FIELDS = True,
- CMS_MENU_TITLE_OVERWRITE = True,
- CMS_URL_OVERWRITE = True,
- CMS_SHOW_END_DATE = True,
- CMS_SHOW_START_DATE = True,
- CMS_PLUGIN_PROCESSORS = tuple(),
- CMS_PLUGIN_CONTEXT_PROCESSORS = tuple(),
- CMS_SITE_CHOICES_CACHE_KEY = 'CMS:site_choices',
- CMS_PAGE_CHOICES_CACHE_KEY = 'CMS:page_choices',
- SOUTH_TESTS_MIGRATE = False,
- CMS_NAVIGATION_EXTENDERS = (
+ CMS_REDIRECTS=True,
+ CMS_SEO_FIELDS=True,
+ CMS_MENU_TITLE_OVERWRITE=True,
+ CMS_URL_OVERWRITE=True,
+ CMS_SHOW_END_DATE=True,
+ CMS_SHOW_START_DATE=True,
+ CMS_PLUGIN_PROCESSORS=tuple(),
+ CMS_PLUGIN_CONTEXT_PROCESSORS=tuple(),
+ CMS_SITE_CHOICES_CACHE_KEY='CMS:site_choices',
+ CMS_PAGE_CHOICES_CACHE_KEY='CMS:page_choices',
+ SOUTH_TESTS_MIGRATE=False,
+ CMS_NAVIGATION_EXTENDERS=(
('cms.test_utils.project.sampleapp.menu_extender.get_nodes', 'SampleApp Menu'),
),
- TEST_RUNNER = 'cms.test_utils.runners.NormalTestRunner',
- JUNIT_OUTPUT_DIR = '.',
- TIME_TESTS = False,
- ROOT_URLCONF = 'cms.test_utils.cli',
- PASSWORD_HASHERS = (
+ TEST_RUNNER='cms.test_utils.runners.NormalTestRunner',
+ JUNIT_OUTPUT_DIR='.',
+ TIME_TESTS=False,
+ ROOT_URLCONF='cms.test_utils.cli',
+ PASSWORD_HASHERS=(
'django.contrib.auth.hashers.MD5PasswordHasher',
)
)
@@ -231,4 +232,4 @@ def configure(**extra):
from django.contrib import admin
- admin.autodiscover()
+ admin.autodiscover()
@@ -18,6 +18,7 @@
url(r'^media/cms/(?P<path>.*)$', 'django.views.static.serve',
{'document_root': settings.CMS_MEDIA_ROOT, 'show_indexes': True}),
url(r'^jsi18n/(?P<packages>\S+?)/$', 'django.views.i18n.javascript_catalog'),
+ url(r'^select2/', include('django_select2.urls')),
)
@@ -7,4 +7,5 @@ South>=0.7.2
html5lib
django-mptt==0.5.1
django-sekizai>=0.6.1
+Django-Select2>=3.1.2
argparse

0 comments on commit 944d3f0

Please sign in to comment.