Skip to content

Commit

Permalink
Merge branch 'master' of github.com:pacifica/pacifica-metadata into i…
Browse files Browse the repository at this point in the history
…ssue-48-instrument_categories

* 'master' of github.com:pacifica/pacifica-metadata:
  Remove the colon query mechanism for determining the instrument group (pacifica#51)

# Conflicts:
#	metadata/rest/instrument_queries/query_base.py
#	metadata/rest/user_queries/query_base.py
  • Loading branch information
kauberry committed Jul 13, 2017
2 parents 614cbe3 + 3522b5f commit 5dd3b82
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 14 deletions.
21 changes: 14 additions & 7 deletions metadata/rest/instrument_queries/query_base.py
Original file line number Diff line number Diff line change
@@ -1,28 +1,35 @@
"""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,
'active': _ie.active,
'last_updated': _ie.updated.isoformat(' ')
'active': _ie.active
}

@staticmethod
Expand Down
1 change: 1 addition & 0 deletions metadata/rest/migration_queries/migrate_proposals.py
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ def generate_proposal_list():

for prop in proposals_with_links:
prop_entry = PropQueryBase.format_proposal_block(prop)
prop_entry['abstract'] = prop.abstract
prop_entry['instruments'] = [inst.instrument.id for inst in prop.instruments_prefetch]
prop_entry['users'] = [user_entry.person.id for user_entry in prop.users_prefetch]
proposal_list[prop.id] = prop_entry
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
9 changes: 3 additions & 6 deletions 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 = u'[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 All @@ -35,10 +35,9 @@ def format_user_block(user_entry, option=None):
'category': user_hash.get('last_name')[:1],
'person_id': user_hash.get('_id'),
'first_name': user_hash.get('first_name'),
'middle_initial': user_hash.get('middle_initial'),
'last_name': user_hash.get('last_name'),
'network_id': user_hash.get('network_id'),
'email_address': user_hash['email_address'],
'email_address': user_hash.get('email_address'),
'last_updated': user_hash.get('updated'),
'display_name': display_name,
'simple_display_name': u'{0} {1}'.format(
Expand All @@ -50,10 +49,8 @@ def format_user_block(user_entry, option=None):
return_block = {
'person_id': user_hash.get('_id'),
'first_name': user_hash.get('first_name'),
'middle_initial': user_hash.get('middle_initial'),
'last_name': user_hash.get('last_name'),
'network_id': user_hash.get('network_id'),
'display_name': u'{0} {1}'.format(
'display_name': '{0} {1}'.format(
user_hash.get('first_name'),
user_hash.get('last_name')
),
Expand Down

0 comments on commit 5dd3b82

Please sign in to comment.