Skip to content

Commit fd4484c

Browse files
committed
Fixed seo extension reliability
It used to have some hard-coded assumptions about the model it was being registered for. Now it conditionally updates the admin fieldsets only if it finds the appropriate fieldset
1 parent 6ad352e commit fd4484c

1 file changed

Lines changed: 10 additions & 3 deletions

File tree

  • feincms/module/extensions

feincms/module/extensions/seo.py

Lines changed: 10 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -2,16 +2,23 @@
22
Adds several fields which are helpful for SEO optimization
33
"""
44

5+
import logging
6+
57
from django.db import models
68
from django.utils.translation import ugettext_lazy as _
79

8-
910
def register(cls, admin_cls):
1011
cls.add_to_class('meta_keywords', models.TextField(_('meta keywords'), blank=True,
1112
help_text=_('This will be prepended to the default keyword list.')))
1213
cls.add_to_class('meta_description', models.TextField(_('meta description'), blank=True,
1314
help_text=_('This will be prepended to the default description.')))
1415

1516
if admin_cls:
16-
admin_cls.fieldsets[1][1]['fields'].extend(['meta_keywords', 'meta_description'])
17-
admin_cls.search_fields.extend(['meta_keywords', 'meta_description'])
17+
admin_cls.search_fields += ('meta_keywords', 'meta_description')
18+
19+
if admin_cls.fieldsets:
20+
fieldsets = [ f for f in admin_cls.fieldsets if f[0] == "Other options"]
21+
if fieldsets:
22+
fieldsets[0][1]['fields'].extend(['meta_keywords', 'meta_description'])
23+
else:
24+
logging.warning("Couldn't determine which fieldset on %s should have the seo fields", admin_cls)

0 commit comments

Comments
 (0)