예제 #1
0
 def matching_faqs_count(self):
     """Return the FAQs matching the same keywords."""
     if not self.search_text:
         return 0
     try:
         faq_collection = IFAQCollection(self.context)
     except TypeError:
         # The context is not adaptable to IFAQCollection.
         return 0
     return faq_collection.searchFAQs(search_text=self.search_text).count()
예제 #2
0
 def matching_faqs_count(self):
     """Return the FAQs matching the same keywords."""
     if not self.search_text:
         return 0
     try:
         faq_collection = IFAQCollection(self.context)
     except TypeError:
         # The context is not adaptable to IFAQCollection.
         return 0
     return faq_collection.searchFAQs(search_text=self.search_text).count()
예제 #3
0
 def list_all(self):
     """Return a Link to list all FAQs."""
     # We adapt to IFAQCollection so that the link can be used
     # on objects which don't provide `IFAQCollection` directly, but for
     # which an adapter exists that gives the proper context.
     collection = IFAQCollection(self.context)
     url = canonical_url(collection, rootsite='answers') + '/+faqs'
     return Link(url, 'List all FAQs', icon='info')
예제 #4
0
 def matching_faqs_url(self):
     """Return the URL to use to display the list of matching FAQs."""
     assert self.matching_faqs_count > 0, (
         "can't call matching_faqs_url when matching_faqs_count == 0")
     collection = IFAQCollection(self.context)
     return canonical_url(collection) + '/+faqs?' + urlencode(
         {
             'field.search_text': self.search_text.encode('utf-8'),
             'field.actions.search': 'Search',
         })
예제 #5
0
 def create_faq(self):
     """Return a Link to create a new FAQ."""
     collection = IFAQCollection(self.context)
     if IProjectGroup.providedBy(self.context):
         url = ''
         enabled = False
     else:
         url = canonical_url(collection,
                             view_name='+createfaq',
                             rootsite='answers')
         enabled = True
     return Link(url, 'Create a new FAQ', icon='add', enabled=enabled)