Skip to content

Instantly share code, notes, and snippets.

@valdergallo
Last active August 29, 2015 14:01
Show Gist options
  • Save valdergallo/df0d56c7bb935ca4022e to your computer and use it in GitHub Desktop.
Save valdergallo/df0d56c7bb935ca4022e to your computer and use it in GitHub Desktop.
Design Patterns Catalog
class SearchCatalog(object):
"""
- Design Patterns Catalog
- https://github.com/faif/python-patterns/blob/master/catalog.py
"""
def __new__(self, request, application, keywords):
search_function = getattr(self, '%s_search' % application, False)
if keywords == 'Search...':
keywords = ''
if search_function:
try:
results = search_function(request, keywords)
except (UnicodeError, ValueError, TypeError):
raise ValueError("Invalid value")
else:
results = {}
return results
@staticmethod
def proposal_search(request, keywords):
pass
@staticmethod
def cpo_search(request, keywords):
pass
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment