Commits

tehfink committed 32acbbd

`limit_choices_to` for FaqEntryLink should remove "duplicates", i.e.: unpublished plugins from faq link list in admin; code comments

Comments (0)

Files changed (1)

cmsplugin_faq/models.py

 
     def get_absolute_url(self):
         """ returns url pointing to the anchor in the cms Page containing the FaqEntry plugin """
+
+        #use django's slugify for the href anchor (e.g.: remove non-ASCII characters)
         from django.template.defaultfilters import slugify
 
+        #create the FaqEntry's url as a combination of the Page's url + '#' + the slugified anchor
         url = "%s#%s" % (Page.objects.get(id=self.page_id).get_absolute_url(language='self.language'), slugify(self.topic))
 
+        #supposedly the following is not necessary. but i haven't been able to get it working with multilingual otherwise
         #check if multilingual middleware is installed
         if 'cms.middleware.multilingual.MultilingualURLMiddleware' in settings.MIDDLEWARE_CLASSES:
+            #prepend language namespace (better way to do this?)
             url = '/' + self.language + url
 
         return url
 
 class FaqEntryLink(CMSPlugin):
     """Model to give FaqEntryLink plugin various options"""
-    link = models.ForeignKey(FaqEntry, blank=True, null=True, verbose_name=_('Linked FAQ Entry'), help_text=_('Leave empty for random'))
+    link = models.ForeignKey(FaqEntry, limit_choices_to={'publisher_is_draft': False}, blank=True, null=True, verbose_name=_('Linked FAQ Entry'), help_text=_('Leave empty for random'))
     truncate_body = models.PositiveSmallIntegerField(_('Truncate words'), default=5, help_text=_('Truncate FAQ Entry body by this many words; zero means Django default'))
     show_body = models.BooleanField(_('Show FAQ Entry body'),default=True)
     css = models.CharField(_('CSS class'), max_length=1, choices=CMSPLUGIN_FAQENTRYLINK_CSS_CHOICES, blank=True, help_text=_('Additional CSS class to apply'))
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for ProjectModifiedEvent.java.
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.