def get_context_data(self, **kwargs): """Update context data to add publication.""" context = super(DataDepotLegacyPublishedView, self).get_context_data(**kwargs) logger.info('Get context Data') nees_id = kwargs['project_id'].strip('.groups').strip('/') logger.debug('nees_id: %s', nees_id) pub = BaseESPublicationLegacy(nees_id=nees_id) logger.debug('pub: %s', pub.to_dict()) context['neesId'] = nees_id.split('/')[0] context['citation_title'] = pub.title context['citation_date'] = getattr(pub, 'startDate', '') experiments = getattr(pub, 'experiments') if experiments and len(experiments): context['doi'] = getattr(pub.experiments[0], 'doi', '') exp_users = [getattr(exp, 'creators', []) for exp in experiments] users = [user for users in exp_users for user in users] context['authors'] = [{ 'full_name': '{last_name}, {first_name}'.format( last_name=getattr(user, 'lastName', ''), first_name=getattr(user, 'firstName', ''), ), 'institution': '' } for user in users] context['publication'] = pub context['description'] = pub.description if self.request.user.is_authenticated: context['angular_init'] = json.dumps({ 'authenticated': True, }) else: context['angular_init'] = json.dumps({ 'authenticated': False, }) return context
def listing(self, system=None, file_path=None, offset=0, limit=100, **kwargs): """Perform the search and output in a serializable format.""" query = self.construct_query(system, file_path, **kwargs) listing_search = Search() listing_search = listing_search.filter(query).sort('_index') listing_search = listing_search.extra(from_=offset, size=limit) res = listing_search.execute() children = [] for hit in res: try: getattr(hit, 'projectId') children.append(BaseESPublication(**hit.to_dict()).to_file()) except AttributeError: children.append( BaseESPublicationLegacy(**hit.to_dict()).to_file()) result = { 'trail': [{ 'name': '$SEARCH', 'path': '/$SEARCH' }], 'name': '$SEARCH', 'path': '/', 'system': system, 'type': 'dir', 'children': children, 'permissions': 'READ' } return result
def listing(self, system=None, file_path=None, offset=0, limit=100, **kwargs): """Wrap the search result in a BaseFile object for serializtion.""" query = self.construct_query(**kwargs) listing_search = Search() listing_search = listing_search.filter(query).sort( '_index', {'project._exact': {'order': 'asc', 'unmapped_type': 'keyword'}}, {'created': {'order': 'desc', 'unmapped_type': 'long'}} ) listing_search = listing_search.extra(from_=offset, size=limit) res = listing_search.execute() children = [] for hit in res: try: getattr(hit, 'projectId') children.append(BaseESPublication(**hit.to_dict()).to_file()) except AttributeError: children.append(BaseESPublicationLegacy(**hit.to_dict()).to_file()) result = { 'trail': [{'name': '$SEARCH', 'path': '/$SEARCH'}], 'name': '$SEARCH', 'path': '/', 'system': system, 'type': 'dir', 'children': children, 'permissions': 'READ' } return result
def get(self, request, nees_id): """ Retrieve a NEES project using its ID and return its JSON representation. """ pub = BaseESPublicationLegacy(nees_id=nees_id) return JsonResponse(pub.to_file())