Commit 3c056c38 by Bach Dániel

dashboard: doctest for autocomplete.highlight

parent 0b7b8883
...@@ -7,15 +7,12 @@ from .views import AclUpdateView ...@@ -7,15 +7,12 @@ from .views import AclUpdateView
from .models import Profile from .models import Profile
class AclUserGroupAutocomplete(autocomplete_light.AutocompleteGenericBase): def highlight(field, q, none_wo_match=True):
search_fields = ( """
('first_name', 'last_name', 'username', 'email', 'profile__org_id'), >>> highlight('<b>Akkount Krokodil', 'kro', False)
('name', 'groupprofile__org_id'), u'&lt;b&gt;Akkount <span class="autocomplete-hl">Kro</span>kodil'
) """
choice_html_format = (u'<span data-value="%s"><span style="display:none"'
u'>%s</span>%s</span>')
def highlight(self, field, q, none_wo_match=True):
if not field: if not field:
return None return None
try: try:
...@@ -33,20 +30,29 @@ class AclUserGroupAutocomplete(autocomplete_light.AutocompleteGenericBase): ...@@ -33,20 +30,29 @@ class AclUserGroupAutocomplete(autocomplete_light.AutocompleteGenericBase):
else: else:
return escape(field) return escape(field)
class AclUserGroupAutocomplete(autocomplete_light.AutocompleteGenericBase):
search_fields = (
('first_name', 'last_name', 'username', 'email', 'profile__org_id'),
('name', 'groupprofile__org_id'),
)
choice_html_format = (u'<span data-value="%s"><span style="display:none"'
u'>%s</span>%s</span>')
def choice_displayed_text(self, choice): def choice_displayed_text(self, choice):
q = unicode(self.request.GET.get('q', '')) q = unicode(self.request.GET.get('q', ''))
name = self.highlight(unicode(choice), q, False) name = highlight(unicode(choice), q, False)
if isinstance(choice, User): if isinstance(choice, User):
extra_fields = [self.highlight(choice.get_full_name(), q, False), extra_fields = [highlight(choice.get_full_name(), q, False),
self.highlight(choice.email, q)] highlight(choice.email, q)]
try: try:
extra_fields.append(self.highlight(choice.profile.org_id, q)) extra_fields.append(highlight(choice.profile.org_id, q))
except Profile.DoesNotExist: except Profile.DoesNotExist:
pass pass
return '%s (%s)' % (name, ', '.join(f for f in extra_fields return '%s (%s)' % (name, ', '.join(f for f in extra_fields
if f)) if f))
else: else:
return '%s (%s)' % (name, _('group')) return _('%s (group)') % name
def choice_html(self, choice): def choice_html(self, choice):
return self.choice_html_format % ( return self.choice_html_format % (
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or sign in to comment