-
Notifications
You must be signed in to change notification settings - Fork 4.3k
Eugeny/problem type search #7641
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
e-kolpakov
merged 16 commits into
openedx:master
from
open-craft:eugeny/problem-type-search
Apr 17, 2015
Merged
Changes from all commits
Commits
Show all changes
16 commits
Select commit
Hold shift + click to select a range
2f03b97
Index dictionary for CapaDescriptor + extending tests to cover it
e-kolpakov d34c6a0
Filtering using search index + tests
e-kolpakov 4f6905e
Added library search indexer and tests
e-kolpakov eb7c5be
Refactored tests to explicitly state with which modulestores they work
e-kolpakov bd891c2
Added setting to enable/disable library indexing + moved is_index_ena…
e-kolpakov 77cc80f
Added code to fire library_updated signal when library is updated
e-kolpakov 89443cf
Fixed broken test
e-kolpakov 5737364
Added library update task test
e-kolpakov 9bbad95
Moved library key normalization into library_tools module, fixed libr…
e-kolpakov 75d61b6
Renamed course_key to structure_key to reflect the fact it might be a…
e-kolpakov bd8754b
Removed stale test helper method
e-kolpakov 0b2b9fe
Added management command to manually reindex libraries
e-kolpakov 26b1e8d
Made methods with no implementation abstract
e-kolpakov 4d3750a
Pylint fixes
e-kolpakov 3b348b7
Tests for reindex library management command
e-kolpakov d4f85d8
Removed unnecessary comments
e-kolpakov 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
75 changes: 75 additions & 0 deletions
75
cms/djangoapps/contentstore/management/commands/reindex_library.py
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,75 @@ | ||
| """ Management command to update libraries' search index """ | ||
| from django.core.management import BaseCommand, CommandError | ||
| from optparse import make_option | ||
| from textwrap import dedent | ||
|
|
||
| from contentstore.courseware_index import LibrarySearchIndexer | ||
|
|
||
| from opaque_keys.edx.keys import CourseKey | ||
| from opaque_keys import InvalidKeyError | ||
| from opaque_keys.edx.locations import SlashSeparatedCourseKey | ||
| from opaque_keys.edx.locator import LibraryLocator | ||
|
|
||
| from .prompt import query_yes_no | ||
|
|
||
| from xmodule.modulestore.django import modulestore | ||
|
|
||
|
|
||
| class Command(BaseCommand): | ||
| """ | ||
| Command to reindex content libraries (single, multiple or all available) | ||
|
|
||
| Examples: | ||
|
|
||
| ./manage.py reindex_library lib1 lib2 - reindexes libraries with keys lib1 and lib2 | ||
| ./manage.py reindex_library --all - reindexes all available libraries | ||
| """ | ||
| help = dedent(__doc__) | ||
|
|
||
| can_import_settings = True | ||
|
|
||
| args = "<library_id library_id ...>" | ||
|
|
||
| option_list = BaseCommand.option_list + ( | ||
| make_option( | ||
| '--all', | ||
| action='store_true', | ||
| dest='all', | ||
| default=False, | ||
| help='Reindex all libraries' | ||
| ),) | ||
|
|
||
| CONFIRMATION_PROMPT = u"Reindexing all libraries might be a time consuming operation. Do you want to continue?" | ||
|
|
||
| def _parse_library_key(self, raw_value): | ||
| """ Parses library key from string """ | ||
| try: | ||
| result = CourseKey.from_string(raw_value) | ||
| except InvalidKeyError: | ||
| result = SlashSeparatedCourseKey.from_deprecated_string(raw_value) | ||
|
|
||
| if not isinstance(result, LibraryLocator): | ||
| raise CommandError(u"Argument {0} is not a library key".format(raw_value)) | ||
|
|
||
| return result | ||
|
|
||
| def handle(self, *args, **options): | ||
| """ | ||
| By convention set by django developers, this method actually executes command's actions. | ||
| So, there could be no better docstring than emphasize this once again. | ||
| """ | ||
| if len(args) == 0 and not options.get('all', False): | ||
| raise CommandError(u"reindex_library requires one or more arguments: <library_id>") | ||
|
|
||
| store = modulestore() | ||
|
|
||
| if options.get('all', False): | ||
| if query_yes_no(self.CONFIRMATION_PROMPT, default="no"): | ||
| library_keys = [library.location.library_key.replace(branch=None) for library in store.get_libraries()] | ||
| else: | ||
| return | ||
| else: | ||
| library_keys = map(self._parse_library_key, args) | ||
|
|
||
| for library_key in library_keys: | ||
| LibrarySearchIndexer.do_library_reindex(store, library_key) |
Oops, something went wrong.
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.
Of these classmethods, are all subclasses expected to implement them? Any methods which need to be implemented by all subclasses should use the
@abstractmethoddecorator, as is used in the modulestore.