-
Notifications
You must be signed in to change notification settings - Fork 3.9k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: simplify REST API handling of usage keys
- Loading branch information
1 parent
dc8fd74
commit 8d10909
Showing
5 changed files
with
48 additions
and
53 deletions.
There are no files selected for viewing
This file contains 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 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 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 @@ | ||
""" | ||
URL pattern converters | ||
https://docs.djangoproject.com/en/5.1/topics/http/urls/#registering-custom-path-converters | ||
""" | ||
from opaque_keys import InvalidKeyError | ||
from opaque_keys.edx.keys import UsageKeyV2 | ||
|
||
|
||
class UsageKeyV2Converter: | ||
""" | ||
Converter that matches V2 usage keys like: | ||
lb:Org:LIB:drag-and-drop-v2:91c2b1d5 | ||
""" | ||
regex = r'[\w-]+(:[\w\-.]+)+' | ||
|
||
def to_python(self, value): | ||
try: | ||
return UsageKeyV2.from_string(value) | ||
except InvalidKeyError as exc: | ||
raise ValueError from exc | ||
|
||
def to_url(self, value): | ||
return str(value) |
This file contains 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 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