This repository has been archived by the owner on Aug 26, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 679
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[569285] Implement question tagging based on django-taggit, which has…
… a nicer API and less-intrusive schema requirements than django-tagging. * Introduce an autocomplete widget with decent user feedback on both adding and removal. Should be reusable elsewhere without much work. Also has non-JS fallback. * Tag storage for the autocompleter is client-side, which lets us take reaction time from 300ms (or greater) down to around 0. Also provides lighter server load, and, as a side effect, containment search for tags rather than just prefix (the former being tricky to index with MySQL). Uses linear search atm, but performance on an 814-word vocab is acceptable on a 2GHz i7.
- Loading branch information
Showing
35 changed files
with
1,173 additions
and
43 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
[ | ||
{ | ||
"pk": 1, | ||
"model": "taggit.tag", | ||
"fields": { | ||
"name": "red", | ||
"slug": "red" | ||
} | ||
}, | ||
{ | ||
"pk": 2, | ||
"model": "taggit.tag", | ||
"fields": { | ||
"name": "green", | ||
"slug": "green" | ||
} | ||
}, | ||
{ | ||
"pk": 3, | ||
"model": "taggit.tag", | ||
"fields": { | ||
"name": "lemon", | ||
"slug": "lemon" | ||
} | ||
}, | ||
{ | ||
"pk": 5, | ||
"model": "taggit.tag", | ||
"fields": { | ||
"name": "purplepurplepurple", | ||
"slug": "purplepurplepurple" | ||
} | ||
}, | ||
{ | ||
"pk": 7, | ||
"model": "taggit.tag", | ||
"fields": { | ||
"name": "colorless", | ||
"slug": "colorless" | ||
} | ||
}, | ||
{ | ||
"pk": 217, | ||
"model": "taggit.taggeditem", | ||
"fields": { | ||
"tag": 2, | ||
"content_type": ["questions", "question"], | ||
"object_id": 2 | ||
} | ||
}, | ||
{ | ||
"pk": 226, | ||
"model": "taggit.taggeditem", | ||
"fields": { | ||
"tag": 7, | ||
"content_type": ["questions", "question"], | ||
"object_id": 2 | ||
} | ||
} | ||
] |
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,19 @@ | ||
"""Fairly generic tagging utilities headed toward a dedicated app""" | ||
|
||
from taggit.models import Tag | ||
|
||
|
||
def add_existing_tag(tag_name, tag_manager): | ||
"""Add a tag that already exists to an object. Return the normalized name. | ||
Given a tag name and a TaggableManager, have the manager add the tag of | ||
that name. The tag is matched case-insensitively. If there is no such tag, | ||
raise Tag.DoesNotExist. | ||
Return the canonically cased name of the tag. | ||
""" | ||
# TODO: Think about adding a new method to _TaggableManager upstream. | ||
tag = Tag.objects.get(name__iexact=tag_name) | ||
tag_manager.add(tag) | ||
return tag.name |
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
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
Oops, something went wrong.