Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
I
internewshid
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container Registry
Model registry
Operate
Environments
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
aptivate
client-projects
internewshid
Commits
cf954b28
Commit
cf954b28
authored
9 years ago
by
Alice Heaton
Browse files
Options
Downloads
Patches
Plain Diff
Ensure that drop downs use the short name version and are sorted alphabetically.
parent
b75c6c75
No related branches found
Branches containing commit
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
django/website/hid/tests/views_tests.py
+29
-3
29 additions, 3 deletions
django/website/hid/tests/views_tests.py
django/website/hid/views.py
+11
-4
11 additions, 4 deletions
django/website/hid/views.py
with
40 additions
and
7 deletions
django/website/hid/tests/views_tests.py
+
29
−
3
View file @
cf954b28
...
...
@@ -158,6 +158,32 @@ def test_get_category_options_with_no_taxonomy_returns_all():
assert
(
other_term
.
name
,
other_term
.
long_name
)
in
options
@pytest.mark.django_db
def
test_get_category_options_orders_by_lowercase_name
():
# TODO: Rewrite tests to use transport layer
ebola_questions
=
TaxonomyFactory
(
name
=
"
Ebola Questions
"
)
test_term_values
=
[
(
'
test a1
'
,
'
1
'
),
(
'
test b1
'
,
'
2
'
),
(
'
test A2
'
,
'
3
'
),
(
'
test B2
'
,
'
4
'
)
]
for
test_value
in
test_term_values
:
TermFactory
(
name
=
test_value
[
0
],
long_name
=
test_value
[
1
],
taxonomy
=
ebola_questions
)
view
=
ViewItems
()
options
=
view
.
get_category_options
(
ebola_questions
.
id
)
# Make sure we are only comparing with out test values!
options
=
[
o
for
o
in
options
if
o
in
test_term_values
]
# Expected is the list ordered by lowercase short name.
expected
=
sorted
(
test_term_values
,
key
=
lambda
e
:
e
[
0
].
lower
())
assert
options
==
expected
def
test_views_item_get_request_parameters_renames_items_of_active_location
():
query
=
QueryDict
(
'
action=something-bottom&item-top=top-value&item-bottom=bottom-value
'
...
...
@@ -186,12 +212,12 @@ def test_views_item_get_request_parameters_sets_default_location():
def
test_views_item_get_request_parameters_sets_default_action_and_location
():
query
=
QueryDict
(
'
item-top=value&item-bottom=
unchanged
'
'
item-top=
top-
value&item-bottom=
bottom-value
'
)
expected
=
{
'
action
'
:
'
none
'
,
'
item
'
:
'
value
'
,
'
item-bottom
'
:
'
unchanged
'
'
item
'
:
'
top-
value
'
,
'
item-bottom
'
:
'
bottom-value
'
}
actual
=
ViewItems
.
get_request_parameters
(
query
)
assert
actual
.
dict
()
==
expected
This diff is collapsed.
Click to expand it.
django/website/hid/views.py
+
11
−
4
View file @
cf954b28
import
re
from
collections
import
OrderedDict
from
django.contrib
import
messages
from
django.core.urlresolvers
import
reverse
from
django.http
import
HttpResponseRedirect
,
QueryDict
...
...
@@ -89,14 +91,19 @@ class ViewItems(SingleTableView):
def
get_category_options
(
self
,
categories_id
=
None
):
# TODO: Use data layer
terms
=
self
.
get_matching_terms
(
categories_id
)
return
tuple
((
t
.
name
,
t
.
long_name
)
for
t
in
terms
)
def
get_matching_terms
(
self
,
categories_id
):
if
categories_id
is
None
:
return
Term
.
objects
.
all
()
return
(
Term
.
objects
.
extra
(
select
=
{
'
name_lower
'
:
'
lower(name)
'
})
.
order_by
(
'
name_lower
'
)
.
all
())
return
Term
.
objects
.
filter
(
taxonomy__id
=
categories_id
)
return
(
Term
.
objects
.
extra
(
select
=
{
'
name_lower
'
:
'
lower(name)
'
})
.
order_by
(
'
name_lower
'
)
.
filter
(
taxonomy__id
=
categories_id
))
def
get_table
(
self
,
**
kwargs
):
# TODO: Filter on taxonomy
...
...
@@ -138,7 +145,7 @@ class ViewItems(SingleTableView):
"""
return
{
'
label
'
:
label
,
'
items
'
:
d
ict
(
'
items
'
:
OrderedD
ict
(
[(
prefix
+
short_name
,
short_name
)
for
short_name
,
long_name
in
items
]
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment