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
| // https://w3c.github.io/gamepad/#dfn-standard-gamepad-layout | |
| const Dpad = { | |
| UP: 12, | |
| LEFT: 14, | |
| RIGHT: 15, | |
| DOWN: 13, | |
| }; | |
| const Buttons = { | |
| A: 0, | |
| B: 1, |
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
| class Book(models.Model): | |
| isbn = models.CharField(max_length=13) | |
| title = models.TextField() | |
| author = models.TextField() | |
| visible = models.BooleanField(default=True) |
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
| def book_list(request: HttpRequest) -> HttpResponse: | |
| if request.method == "GET": | |
| books = Book.objects.filter(visible=True) | |
| if "author" in request.GET: | |
| books = books.filter(author__icontains=request.GET["author"]) | |
| if "title" in request.GET: | |
| books = books.filter(title__icontains=request.GET["title"]) | |
| response_data = [book_to_json(book) for book in books] | |
| return JsonResponse(response_data, safe=False) |
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
| def book_to_json(book: Book): | |
| return { | |
| "isbn": book.isbn, | |
| "title": book.title, | |
| "author": book.author, | |
| } | |
| def book_from_json(data: dict) -> Book: | |
| return Book( |
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
| class AnyUUID: | |
| def __eq__(self, other): | |
| if isinstance(other, str): | |
| try: | |
| UUID(other) | |
| return True | |
| except ValueError: | |
| return False | |
| else: | |
| return isinstance(other, UUID) |
OlderNewer