Skip to content
Toggle navigation
P
Projects
G
Groups
S
Snippets
Help
CIRCLE
/
cloud
This project
Loading...
Sign in
Toggle navigation
Go to a project
Project
Repository
Issues
94
Merge Requests
10
Pipelines
Wiki
Snippets
Members
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Commit
b61a5728
authored
Sep 09, 2014
by
Bach Dániel
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
dashboard: improve autocomplete
parent
c79a3431
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
with
45 additions
and
11 deletions
+45
-11
circle/dashboard/autocomplete_light_registry.py
+36
-11
circle/dashboard/static/dashboard/dashboard.css
+9
-0
No files found.
circle/dashboard/autocomplete_light_registry.py
View file @
b61a5728
import
autocomplete_light
from
django.contrib.auth.models
import
User
from
django.utils.translation
import
ugettext
as
_
from
.views
import
AclUpdateView
from
.models
import
Profile
class
AclUserGroupAutocomplete
(
autocomplete_light
.
AutocompleteGenericBase
):
search_fields
=
(
(
'
^first_name'
,
'last_name'
,
'username'
,
'^
email'
,
'profile__org_id'
),
(
'
^
name'
,
'groupprofile__org_id'
),
(
'
first_name'
,
'last_name'
,
'username'
,
'
email'
,
'profile__org_id'
),
(
'name'
,
'groupprofile__org_id'
),
)
autocomplete_js_attributes
=
{
'placeholder'
:
_
(
"Name of group or user"
)}
choice_html_format
=
u'<span data-value="
%
s"><span>
%
s</span>
%
s</span>'
choice_html_format
=
(
u'<span data-value="
%
s"><span style="display:none"'
u'>
%
s</span>
%
s</span>'
)
def
choice_html
(
self
,
choice
):
def
highlight
(
self
,
field
,
q
,
none_wo_match
=
True
):
if
not
field
:
return
None
try
:
name
=
choice
.
get_full_name
()
except
AttributeError
:
name
=
_
(
'group'
)
if
name
:
name
=
u'(
%
s)'
%
name
match
=
field
.
lower
()
.
index
(
q
.
lower
())
except
ValueError
:
match
=
None
if
q
and
match
is
not
None
:
match_end
=
match
+
len
(
q
)
return
(
field
[:
match
]
+
'<span class="autocomplete-hl">'
+
field
[
match
:
match_end
]
+
'</span>'
+
field
[
match_end
:])
else
:
return
None
if
none_wo_match
else
field
def
choice_displayed_text
(
self
,
choice
):
q
=
unicode
(
self
.
request
.
GET
.
get
(
'q'
,
''
))
name
=
self
.
highlight
(
unicode
(
choice
),
q
,
False
)
if
isinstance
(
choice
,
User
):
extra_fields
=
[
self
.
highlight
(
choice
.
get_full_name
(),
q
,
False
),
self
.
highlight
(
choice
.
email
,
q
)]
try
:
extra_fields
.
append
(
self
.
highlight
(
choice
.
profile
.
org_id
,
q
))
except
Profile
.
DoesNotExist
:
pass
return
'
%
s (
%
s)'
%
(
name
,
', '
.
join
(
f
for
f
in
extra_fields
if
f
))
else
:
return
'
%
s (
%
s)'
%
(
name
,
_
(
'group'
))
def
choice_html
(
self
,
choice
):
return
self
.
choice_html_format
%
(
self
.
choice_value
(
choice
),
self
.
choice_label
(
choice
),
name
)
self
.
choice_value
(
choice
),
self
.
choice_label
(
choice
),
self
.
choice_displayed_text
(
choice
))
def
choices_for_request
(
self
):
user
=
self
.
request
.
user
...
...
circle/dashboard/static/dashboard/dashboard.css
View file @
b61a5728
...
...
@@ -960,3 +960,12 @@ textarea[name="list-new-namelist"] {
#vm-activity-state
{
margin-bottom
:
15px
;
}
.autocomplete-hl
{
color
:
#b20000
;
font-weight
:
bold
;
}
.hilight
.autocomplete-hl
{
color
:
orange
;
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment