Skip to content

Commit 39dfd82

Browse files
author
Patrick Lauber
committed
merge
--HG-- emptychangelog : true
2 parents 0578243 + afe6f78 commit 39dfd82

File tree

10 files changed

+46
-28
lines changed

10 files changed

+46
-28
lines changed

cms/models/__init__.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@
22
from pagemodel import *
33
from permissionmodels import *
44
from pluginmodel import *
5-
from titlemodels import *
5+
from titlemodels import *

cms/models/managers.py

Lines changed: 10 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -93,9 +93,7 @@ def get_home(self, site=None):
9393
def search(self, q, language=None, current_site_only=True):
9494
"""Simple search function
9595
96-
NOTE:For future may be better if every plugin defines Q object relative
97-
to page, and search function just takes them. This will give us
98-
posibillity to search over custom plugins.
96+
Plugins can define a 'search_fields' tuple similar to ModelAdmin classes
9997
"""
10098
qs = self.public()
10199

@@ -105,20 +103,15 @@ def search(self, q, language=None, current_site_only=True):
105103

106104
qt = Q(title_set__title__icontains=q)
107105

108-
plugins = (
109-
('cms.plugins.text', Q(cmsplugin__text__body__icontains=q)),
110-
('cms.plugins.file', Q(cmsplugin__file__title__icontains=q)),
111-
('cms.plugins.snippet', Q(cmsplugin__snippetptr__snippet__html__icontains=q)),
112-
('cms.plugins.link', Q(cmsplugin__link__name__icontains=q)),
113-
('cms.plugins.teaser', Q(cmsplugin__teaser__description__icontains=q)),
114-
)
115-
106+
# find 'searchable' plugins and build query
116107
qp = Q()
117-
# build plugin query depending on installed plugins
118-
for app_name, q in plugins:
119-
if not app_name in settings.INSTALLED_APPS:
120-
continue
121-
qp |= q
108+
# cannot import CMSPlugin due to Manager -> Page -> Plugin circle!
109+
CMSPlugin = models.get_model('cms','cmsplugin')
110+
for c in CMSPlugin.__subclasses__():
111+
if hasattr(c, 'search_fields'):
112+
for field in c.search_fields:
113+
qp |= Q(**{'cmsplugin__%s__%s__icontains' % \
114+
(c.__name__.lower(), field):q})
122115

123116
if language:
124117
qt &= Q(title_set__language=language)
@@ -129,7 +122,6 @@ def search(self, q, language=None, current_site_only=True):
129122
return qs.distinct()
130123

131124

132-
133125
class TitleManager(PublisherManager):
134126
def get_title(self, page, language, language_fallback=False, latest_by='creation_date'):
135127
"""
@@ -466,4 +458,4 @@ def __get_id_list(self, user, attr):
466458
class PageModeratorStateManager(models.Manager):
467459
def get_delete_actions(self):
468460
from cms.models import PageModeratorState
469-
return self.filter(action=PageModeratorState.ACTION_DELETE)
461+
return self.filter(action=PageModeratorState.ACTION_DELETE)

cms/plugin_base.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,26 @@ class Meta:
2828
exclude = ('page', 'position', 'placeholder', 'language', 'plugin_type')
2929
self.form = DefaultModelForm
3030

31+
# Move 'advanced' fields into separate fieldset.
32+
# Currently disabled if fieldsets already set, though
33+
# could simply append an additional 'advanced' fieldset --
34+
# but then the plugin can't customise the advanced fields
35+
if not self.__class__.fieldsets:
36+
basic_fields = []
37+
advanced_fields = []
38+
for f in self.model._meta.fields:
39+
if not f.auto_created and f.editable:
40+
if hasattr(f,'advanced'):
41+
advanced_fields.append(f.name)
42+
else: basic_fields.append(f.name)
43+
if advanced_fields: # leave well enough alone otherwise
44+
self.__class__.fieldsets = (
45+
(None, { 'fields' : basic_fields}),
46+
(_('Advanced options'),
47+
{'fields' : advanced_fields,
48+
'classes' : ('collapse',)})
49+
)
50+
3151
if admin_site:
3252
super(CMSPluginBase, self).__init__(self.model, admin_site)
3353

@@ -126,4 +146,4 @@ def __repr__(self):
126146
return smart_str(self.name)
127147

128148
def __unicode__(self):
129-
return self.name
149+
return self.name

cms/plugins/file/models.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
21
from django.db import models
32
from django.utils.translation import ugettext_lazy as _
43
from cms.models import CMSPlugin
54
from posixpath import join, basename, splitext, exists
6-
5+
from django.db.models import Q
76
from cms import settings as cms_settings
87
from django.conf import settings
98

@@ -55,4 +54,5 @@ def __unicode__(self):
5554
# added if, because it raised attribute error when file wasnt defined
5655
return self.get_file_name();
5756
return "<empty>"
58-
57+
58+
search_fields = ('title',)

cms/plugins/file/templates/cms/plugins/file.html

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,5 +5,3 @@
55
{% if object.title %}{{ object.title }}{% else %}{{ object.get_file_name }}{% endif %} {% if object.file_exists %}<span class="filesize">({{ object.file.size|filesizeformat }})</span>{% else %}(file missing!){% endif %}</a>
66
</span>
77
{% endif %}
8-
9-

cms/plugins/link/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
from django.utils.translation import ugettext_lazy as _
33
from cms.models import CMSPlugin, Page
44
from django.conf import settings
5+
from django.db.models import Q
56

67
class Link(CMSPlugin):
78
"""
@@ -15,3 +16,5 @@ class Link(CMSPlugin):
1516

1617
def __unicode__(self):
1718
return self.name
19+
20+
search_fields = ('name',)

cms/plugins/snippet/models.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
from cms.models import CMSPlugin
44
from django.conf import settings
55
from cms.utils.helpers import reversion_register
6+
from django.db.models import Q
67

78
# Stores the actual data
89
class Snippet(models.Model):
@@ -29,6 +30,8 @@ class SnippetPtr(CMSPlugin):
2930
class Meta:
3031
verbose_name = _("Snippet")
3132

33+
search_fields = ('snippet__html',)
34+
3235
# We don't both with SnippetPtr, since all the data is actually in Snippet
3336
reversion_register(Snippet)
3437

cms/plugins/teaser/models.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,8 @@
1-
21
from django.db import models
32
from django.utils.translation import ugettext_lazy as _
43
from cms.models import CMSPlugin, Page
54
from os.path import basename
6-
5+
from django.db.models import Q
76
from django.conf import settings
87

98
class Teaser(CMSPlugin):
@@ -19,3 +18,4 @@ class Teaser(CMSPlugin):
1918
def __unicode__(self):
2019
return self.title
2120

21+
search_fields = ('description',)

cms/plugins/text/models.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,7 @@
66
from django.utils.text import truncate_words
77
from cms.plugins.text.utils import plugin_admin_html_to_tags,\
88
plugin_tags_to_admin_html
9+
from django.db.models import Q
910

1011
class Text(CMSPlugin):
1112
"""A block of content, tied to a page, for a particular language"""
@@ -24,6 +25,7 @@ def _get_body_admin(self):
2425
admin. Read/write.
2526
""")
2627

28+
search_fields = ('body',)
2729

2830
def __unicode__(self):
2931
return u"%s" % (truncate_words(strip_tags(self.body), 3)[:30]+"...")

cms/signals.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -154,7 +154,7 @@ def post_save_user_group(instance, raw, created, **kwargs):
154154
# TODO: same as in post_save_user - raw sql is just not nice - workaround...?
155155

156156
cursor = connection.cursor()
157-
query = "INSERT INTO `%s` (`group_ptr_id`, `created_by_id`) VALUES (%d, %d)" % (
157+
query = "INSERT INTO %s (group_ptr_id, created_by_id) VALUES (%d, %d)" % (
158158
PageUserGroup._meta.db_table,
159159
instance.pk,
160160
creator.pk

0 commit comments

Comments
 (0)