-
Notifications
You must be signed in to change notification settings - Fork 2
Add search functionality and display page #20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
14 commits
Select commit
Hold shift + click to select a range
3813139
Added search functionality from unicore-cms
nathanbegbie 5ac7baf
Copied tests for paginator into utils from unicore-cms
nathanbegbie b0be60b
added tests for everything except language tests
nathanbegbie d8b6acf
change get_object to to_object
Rizziepit 80f86ea
a last get_object removed
Rizziepit e2184be
fixed merge conflicts from merging in develop branch
nathanbegbie 1c6cbd5
Merge branch 'develop' of github.com:universalcore/springboard into f…
nathanbegbie 1ce3d95
Corrected template stuff
nathanbegbie 9977ee4
Got search working
nathanbegbie 244ce46
Merge branch 'develop' into feature/issue-20-add-search
Rizziepit 0c559dc
pulled and merged changes made in develop
nathanbegbie 37dcd66
Got category filter working, removed test print statements
nathanbegbie 3b42277
Added test for searching in selected language
nathanbegbie 65ded89
removed return statement with coverage issue
nathanbegbie File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,3 @@ | ||
| {% macro image(src, srcset, alt) -%} | ||
| <img src="{{src}}" srcset="{{srcset}}" alt="{{alt}}"> | ||
| {%- endmacro %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,123 @@ | ||
| {% import 'atoms.html' as atoms %} | ||
|
|
||
| {% macro list_of_languages(view, languages, styling_classes) -%} | ||
| <ul class="nav list_of_languages list-inline {{styling_classes}}" role="navigation"> | ||
| {% for lang_code, lang_name in languages %} | ||
| <li> | ||
| <a href="{{'locale_matched'|route_url(language=lang_code)}}">{{lang_name}}</a> | ||
| </li> | ||
| {% endfor %} | ||
| <li><a href={{'locale_change'|route_url}}>>></a></li> | ||
| </ul> | ||
| {%- endmacro %} | ||
|
|
||
| {% macro logo(view, src, styling_classes) -%} | ||
| <div class="logo {{styling_classes}}"> | ||
| <a href={{view.request.route_url('home')}}> | ||
| {{atoms.image(src, "", "")}} | ||
| </a> | ||
| </div> | ||
| {%- endmacro %} | ||
|
|
||
| {% macro banner_with_image(src) -%} | ||
| <div class ="banner"> | ||
| {{ atoms.image(src, "", "")}} | ||
| </div> | ||
| {%- endmacro %} | ||
|
|
||
| <!-- Assumed that list always includes home --> | ||
| {% macro list_of_site_links(view, dict, styling_classes) -%} | ||
| <ul class="nav {{styling_classes}}" role="navigation"> | ||
| <li><a href={{view.request.route_url('home')}}>Home</a></li> | ||
| {% for key, value in dict %} | ||
| <li><a href={{view.request.route_url('flatpage', slug=key)}}>{{value}}</a></li> | ||
| {% endfor %} | ||
| </ul> | ||
| {%- endmacro %} | ||
|
|
||
| {% macro image_and_heading(view, cat, styling_classes) -%} | ||
| <div class="{{styling_classes}}"> | ||
| {{atoms.image( view.get_image_url(cat.image_host, cat.image, 45, 45), "" , "" ) }} | ||
| <h3>{{cat.title}}</h3> | ||
| </div> | ||
| {%- endmacro %} | ||
|
|
||
| {% macro footer(message) -%} | ||
| <div class="footer" role="contentinfo"> | ||
| © {{message}} | ||
| </div> | ||
| {%- endmacro %} | ||
|
|
||
| {% macro search_box(view) -%} | ||
| <form action={{view.request.route_url('search')}} method='GET'> | ||
| <label for="q">Search: | ||
| <input id="q" name="q" type="text"> | ||
| </label> | ||
| <input type="submit" value='Submit' /> | ||
| </form> | ||
| {%- endmacro %} | ||
|
|
||
| {% macro page_number_navigator(view, paginator, p, query) -%} | ||
|
|
||
| {% if paginator.has_previous_page() %} | ||
| <a href={{view.request.route_url('search')}}?q={{query}}&p={{p-1}} >< Previous</a> | ||
| {% endif %} | ||
|
|
||
| {% if paginator.show_start() %} | ||
| <a href={{view.request.route_url('search')}}?q={{query}}&p=0>1</a> | ||
| {% endif %} | ||
|
|
||
| {% if paginator.needs_start_ellipsis() %} | ||
| <a>...</a> | ||
| {% endif %} | ||
|
|
||
| {% if paginator.page_numbers_left() %} | ||
| {% for number in paginator.page_numbers_left() %} | ||
| <a href={{view.request.route_url('search')}}?q={{query}}&p={{number}}>{{number + 1}}</a> | ||
| {% endfor %} | ||
| {% endif %} | ||
|
|
||
| <b>{{p + 1}}</b> | ||
|
|
||
| {% if paginator.page_numbers_right() %} | ||
| {% for number in paginator.page_numbers_right() %} | ||
| <a href={{view.request.route_url('search')}}?q={{query}}&p={{number}}>{{number + 1}}</a> | ||
| {% endfor %} | ||
| {% endif %} | ||
|
|
||
| {% if paginator.needs_end_ellipsis() %} | ||
| <a>...</a> | ||
| {% endif %} | ||
|
|
||
| {% if paginator.show_end() %} | ||
| <a href={{view.request.route_url('search')}}?q={{query}}&p={{paginator.total_pages()-1}}>{{paginator.total_pages()}}</a> | ||
| {% endif %} | ||
|
|
||
| {% if paginator.has_next_page() %} | ||
| <a href={{view.request.route_url('search')}}?q={{query}}&p={{p + 1}}>Next ></a> | ||
| {% endif %} | ||
|
|
||
| {%- endmacro %} | ||
|
|
||
| {% macro message_for_no_results(query) -%} | ||
| {% if query %} | ||
| <p>No results found for <b>{{query}}</b></p> | ||
| {% else %} | ||
| <p>No results found!</p> | ||
| {% endif %} | ||
| {%- endmacro %} | ||
|
|
||
| {% macro search_summary(num_of_results, query) -%} | ||
| {% if num_of_results==1 %} | ||
| <p>1 search result for: <b>{{query}}</b></p> | ||
| {% elif num_of_results > 1 %} | ||
| <p>{{num_of_results}} search results for: <b>{{query}}</b></p> | ||
| {% endif %} | ||
| {%- endmacro %} | ||
|
|
||
| {% macro article_summary(result, all_categories) -%} | ||
| {% if result.primary_category %} | ||
| <p>{{result.primary_category|get_category_title(all_categories) }}</p> | ||
| {% endif %} | ||
| <a href="{{'page'|route_url(uuid=result.uuid)}}">{{result.title}} ... Read More ></a> | ||
| {%- endmacro %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,12 @@ | ||
| {% import 'molecules.html' as molecules %} | ||
| {% import 'atoms.html' as atoms %} | ||
|
|
||
| {% macro list_of_returned_articles(paginator, all_categories) -%} | ||
| <ul> | ||
| {% for result in paginator.get_page() %} | ||
| <li> | ||
| {{molecules.article_summary(result, all_categories)}} | ||
| </li> | ||
| {% endfor %} | ||
| </ul> | ||
| {%- endmacro %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,23 @@ | ||
| {% extends "base.jinja2" %} | ||
| {% import 'atoms.html' as atoms %} | ||
| {% import 'molecules.html' as molecules %} | ||
| {% import 'organisms.html' as organisms %} | ||
|
|
||
| {% block content %} | ||
| <div class="content"> | ||
|
|
||
| {% if paginator %} | ||
|
|
||
| {{molecules.search_summary(paginator.total_count(), query)}} | ||
|
|
||
| {% if paginator.total_pages() > 1 %} | ||
| {{molecules.page_number_navigator(view, paginator, p, query)}} | ||
| {% endif %} | ||
|
|
||
| {{organisms.list_of_returned_articles(paginator, all_categories)}} | ||
| {% else %} | ||
| {{molecules.message_for_no_results(query)}} | ||
| {% endif %} | ||
|
|
||
| </div> | ||
| {% endblock %} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,115 @@ | ||
| from springboard.tests import SpringboardTestCase | ||
|
|
||
|
|
||
| from pyramid import testing | ||
| from unicore.content.models import Page | ||
|
|
||
|
|
||
| class TestSearch(SpringboardTestCase): | ||
|
|
||
| def setUp(self): | ||
| self.workspace = self.mk_workspace() | ||
| settings = { | ||
| 'unicore.repos_dir': self.working_dir, | ||
| 'unicore.content_repo_urls': self.workspace.working_dir, | ||
| 'available_languages': '\n'.join([ | ||
| 'eng_GB', | ||
| 'swa_KE', | ||
| 'spa_ES', | ||
| ]), | ||
| 'featured_languages': '\n'.join([ | ||
| 'spa_ES', | ||
| 'eng_GB', | ||
| ]) | ||
| } | ||
| self.config = testing.setUp(settings=settings) | ||
| self.app = self.mk_app(self.workspace, settings=settings) | ||
|
|
||
| def tearDown(self): | ||
| testing.tearDown() | ||
|
|
||
| def test_search_no_results(self): | ||
| self.app = self.mk_app(self.workspace) | ||
|
|
||
| resp = self.app.get('/search/', params={'q': ''}, status=200) | ||
| self.assertTrue('No results found' in resp.body) | ||
|
|
||
| def test_search_blank(self): | ||
| self.app = self.mk_app(self.workspace) | ||
| self.mk_pages(self.workspace) | ||
|
|
||
| resp = self.app.get('/search/', params={'q': None}, status=200) | ||
| self.assertTrue('No results found' in resp.body) | ||
|
|
||
| def test_search_2_results(self): | ||
| self.app = self.mk_app(self.workspace) | ||
| self.mk_pages(self.workspace, count=2) | ||
| resp = self.app.get('/search/', params={'q': 'sample'}, status=200) | ||
|
|
||
| self.assertFalse('No results found' in resp.body) | ||
| self.assertTrue('Test Page 0' in resp.body) | ||
| self.assertTrue('Test Page 1' in resp.body) | ||
|
|
||
| def test_search_multiple_results(self): | ||
| self.app = self.mk_app(self.workspace) | ||
| self.mk_pages(self.workspace, count=11) | ||
| resp = self.app.get('/search/', params={'q': 'sample'}, status=200) | ||
| self.assertTrue( | ||
| 'Next ></a>' | ||
| in resp.body) | ||
|
|
||
| def test_search_profanity(self): | ||
| self.app = self.mk_app(self.workspace) | ||
| self.mk_pages(self.workspace, count=2) | ||
|
|
||
| resp = self.app.get('/search/', params={'q': 'kak'}, status=200) | ||
|
|
||
| self.assertTrue('No results found' in resp.body) | ||
|
|
||
| def test_search_added_page(self): | ||
| self.app = self.mk_app(self.workspace) | ||
| mother_page = Page({ | ||
| 'title': 'title for mother', 'language': 'eng_GB', 'position': 2, | ||
| 'content': 'Page for mother test page'}) | ||
| self.workspace.save(mother_page, 'Add mother page') | ||
|
|
||
| self.workspace.refresh_index() | ||
|
|
||
| resp = self.app.get('/search/', params={'q': 'mother'}, status=200) | ||
|
|
||
| self.assertTrue('mother' in resp.body) | ||
| self.assertFalse('No results found' in resp.body) | ||
|
|
||
| def test_pagination(self): | ||
| self.app = self.mk_app(self.workspace) | ||
| self.mk_pages(self.workspace, count=15, content='baby') | ||
| resp = self.app.get( | ||
| '/search/', params={'q': 'baby', 'p': '0'}, status=200) | ||
| self.assertFalse('Previous' in resp.body) | ||
| self.assertTrue('Next' in resp.body) | ||
|
|
||
| def test_search_language_filter(self): | ||
| [category_eng] = self.mk_categories( | ||
| self.workspace, count=1, language='eng_GB', | ||
| title='English Category') | ||
| self.mk_pages( | ||
| self.workspace, count=1, language='eng_GB', | ||
| primary_category=category_eng.uuid, | ||
| content='Page for mother test page') | ||
| [category_spa] = self.mk_categories( | ||
| self.workspace, count=1, language='spa_ES', | ||
| title='Spanish Category') | ||
| self.mk_pages( | ||
| self.workspace, count=1, language='spa_ES', | ||
| primary_category=category_spa.uuid, | ||
| content='Page for mother test page') | ||
|
|
||
| self.app.get('/locale/?language=eng_GB', status=302) | ||
| resp = self.app.get('/search/', params={'q': 'mother'}, status=200) | ||
| self.assertTrue('English Category' in resp.body) | ||
| self.assertFalse('Spanish Category' in resp.body) | ||
|
|
||
| self.app.get('/locale/?language=spa_ES', status=302) | ||
| resp = self.app.get('/search/', params={'q': 'mother'}, status=200) | ||
| self.assertTrue('Spanish Category' in resp.body) | ||
| self.assertFalse('English Category' in resp.body) | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What are we testing here exactly?