Skip to content

Commit

Permalink
Remove the colon query mechanism for determining the instrument group (
Browse files Browse the repository at this point in the history
…#51)

* Remove the colon query mechanism for determining the instrument group

This uses the appropriate instrument group relationship for determining
the category and the groups for the instrument.

* should not contain EUS anywhere

* fix comment to be more accurate
  • Loading branch information
dmlb2000 authored Jul 12, 2017
1 parent 733e819 commit 3522b5f
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 7 deletions.
18 changes: 13 additions & 5 deletions metadata/rest/instrument_queries/query_base.py
Original file line number Diff line number Diff line change
@@ -1,23 +1,31 @@
"""CherryPy Status Metadata proposalinfo base class."""
import re
from metadata.orm.instrument_group import InstrumentGroup
from metadata.orm.groups import Groups


class QueryBase(object):
"""Retrieves a set of instruments for a given keyword set."""

@staticmethod
def format_instrument_block(instrument_entry):
"""Construct a dictionary from a given proposal instance in the metadata stack."""
"""Construct a dictionary from a given instrument instance in the metadata stack."""
_ie = instrument_entry
name_components = re.search(r'(.+):\s*(.+)', str(_ie.name))
category = name_components.group(1) if name_components is not None else 'Miscellaneous'
name = name_components.group(2) if name_components is not None else _ie.name
g_names = Groups.select(
Groups.name
).join(
InstrumentGroup
).where(
InstrumentGroup.instrument_id == _ie.id
)
category = g_names[0].name if g_names else 'Miscellaneous'
name = _ie.name
display_name = '[{0} / ID:{1}] {2}'.format(
category, _ie.id, name
)
return {
'id': _ie.id,
'category': category,
'groups': [g.name for g in g_names],
'display_name': display_name,
'name': name,
'name_short': _ie.name_short,
Expand Down
2 changes: 1 addition & 1 deletion metadata/rest/test/test_userinfo.py
Original file line number Diff line number Diff line change
Expand Up @@ -49,7 +49,7 @@ def test_userinfo_api(self):
user = req_json.pop()
self.assertEqual(user['person_id'], user_id)

# test search with eus id
# test search with user id
search_terms = '10'
req = requests.get(
'{0}/userinfo/search/{1}'.format(self.url, search_terms))
Expand Down
2 changes: 1 addition & 1 deletion metadata/rest/user_queries/query_base.py
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,7 @@ def format_user_block(user_entry, option=None):
prop_id = prop.id
clean_proposals[prop_id] = info

display_name = '[EUS ID {0}] {1} {2} <{3}>'.format(
display_name = '[User ID {0}] {1} {2} <{3}>'.format(
user_entry.id,
user_hash.get('first_name'),
user_hash.get('last_name'),
Expand Down

0 comments on commit 3522b5f

Please sign in to comment.