# $URL$ # $Id$ websiteConfig = configs['website'] drilldownFieldNames = { 'drilldown.norm.date.year': {'en':'Year', 'nl':'Jaar'}, 'drilldown.norm.date.decennium': {'en':'Decennium', 'nl':'Decennium'}, 'drilldown.norm.date.centennium': {'en':'Century', 'nl':'Eeuw'}, 'drilldown.norm.name.oneinitial': {'en':'Name', 'nl':'Naam'}, 'drilldown.norm.name.lastname': {'en':'Top 10 Names', 'nl':'Top 10 Namen'}, 'drilldown.meta.repository.id': {'en':'Repository', 'nl':'Repository'}, 'drilldown.meta.repository.repositoryGroupId': {'en':'Source', 'nl':'Bron'}, 'drilldown.mods.classification': {'en':'Classification', 'nl':'Classificatie'}, 'drilldown.mods.genre': {'en':'Genre', 'nl':'Genre'}, 'drilldown.mods.language.languageTerm': {'en':'Language', 'nl':'Taal'}, 'drilldown.mods.relatedItem.titleInfo.title': {'en':'Journal/series', 'nl':'Tijdschrift/reeks'}, 'drilldown.mods.subject.topic': {'en':'Subject', 'nl':'Onderwerp'} } drilldownFields = [ ##### ##### TP: (field, number, sorted) ##### number == 0: all items? ('drilldown.mods.genre', 0, True), ##### #('drilldown.mods.name.namePart', 20, False), #('drilldown.norm.name.oneinitial', 20, False), #('drilldown.meta.repository.id', 10, False), ('drilldown.meta.repository.repositoryGroupId', 10, True), ('drilldown.mods.language.languageTerm', 10, True), ('drilldown.mods.relatedItem.titleInfo.title', 10, True), ('drilldown.mods.subject.topic', 10, True), ('drilldown.mods.classification', 10, True), ] drilldownFieldsNoMultiLevel = [] drilldownFieldsNoMultiLevel.extend(drilldownFields) drilldownFieldsNoMultiLevel.insert(0, ('drilldown.norm.name.lastname', 10, False)) drilldownFieldsNoMultiLevel.insert(0, ('drilldown.norm.date.centennium', 10, False)) groupName = { 'ir-uvt-nl' : {'en': 'Tilburg University Repository', 'nl': 'Tilburg University Repository'}, 'kuleuven-be' : {'en': 'EO: KU Leuven', 'nl': 'EO: KU Leuven'}, 'lse-ac-uk' : {'en': 'EO: London School of Economics', 'nl': 'EO: London School of Economics'}, 'opc-uvt-nl' : {'en': 'Catalogue', 'nl': 'Catalogus'}, 'repec-org' : {'en': 'RePEc', 'nl': 'RePEc'}, 'repub-eur-nl' : {'en': 'EO: Erasmus University Rotterdam', 'nl': 'EO: Erasmus Universiteit Rotterdam'}, 'tilburguniversity-nl': {'en': 'EO: Tilburg University', 'nl': 'EO: Universiteit van Tilburg'}, 'ulb-ac-be' : {'en': 'EO: Universite Libre de Bruxelles', 'nl': 'EO: Universite Libre de Bruxelles'}, 'unimaas-nl' : {'en': 'EO: Maastricht University', 'nl': 'EO: Universiteit Maastricht'}, } space = "\n " def fieldAndTermSplit(fieldAndTerm): return fieldAndTerm.split(':', 1) def fieldAndTermJoin(field, term): return '%s:%s' % (field, term) def shrink(aString, maxLength=160): if len(aString) > maxLength: return aString[:maxLength] + '...' return aString def createDrilldownQuery(drilldownArgs, sortKeys): newArguments = []; if sortKeys: newArguments.append(('sortKeys', sortKeys)) for existing in drilldownArgs: newArguments.append(('drilldown', existing)) return urlencode(newArguments) def displayLabel(label): return '
%s
' % label def displayTerm(term, fieldName, language, maxLength=25): if fieldName == 'drilldown.mods.genre': term = term.replace('info:eu-repo/semantics/', '') elif fieldName == 'drilldown.meta.repository.repositoryGroupId': term = groupName.get(term, {'en':term, 'nl':term})[language] elif fieldName == 'drilldown.norm.date.decennium': to = int(term) + 9 term = term + '-' + str(to) elif fieldName == 'drilldown.norm.date.centennium': to = int(term) + 99 term = term + '-' + str(to) return shrink(term, maxLength) def displayItem_checkbox(query, term, selected, field, language, count): s = space + ' ' s = s + escapeHtml(displayTerm(term, field, language)) + ' (' + str(count) + ')' s = s + '
' return s def displayFilter_checkbox(query, title, category, selection): s = space + ' ' # s = s + category+ ': ' s = s + escapeHtml(selection) s = s + '
' return s def displayItem(query, term, selected, field, language, count): text = escapeHtml(displayTerm(term, field, language)) + ' (' + str(count) + ')' if selected: # s = '
' + text + '
' s = '' else: s = '
' s = s + text s = s + '
' return s def displayItemGroep(label, termCounts, selectedFacets, fieldName, selectedFieldNames, arguments, language, sortKeys): s = '' t = '' for term, count in termCounts: if fieldName in selectedFieldNames and term in selectedFieldNames[fieldName]: drilldownArgs = set(selectedFacets) drilldownArgs.remove(fieldName + ":" + term) query = createDrilldownQuery(drilldownArgs, sortKeys) s += displayItem(query, term, True, fieldName, language, count) else: drilldownArgs = set(arguments.get('drilldown', []) + [fieldAndTermJoin(fieldName, term)]) query = createDrilldownQuery(drilldownArgs, sortKeys) s += displayItem(query, term, False, fieldName, language, count) if (s): t = space + '%s' % displayLabel(label) + s return t def displayFilter(query, term , category, selection): # logger.debug('Query:' + query) s = '
' s = s + 'deselect' + term + '' + escapeHtml(selection) s = s + '
' return s def displayDrilldownExtraLabel(levelField, selectedFieldNames, drilldownFieldNames, language, selectedFacets, sortKeys, total ): previousUpField = "" s = '' upField = "" if levelField == "drilldown.norm.date.decennium" and "drilldown.norm.date.centennium" in selectedFieldNames: upField = "drilldown.norm.date.centennium" elif levelField == "drilldown.norm.date.year" and "drilldown.norm.date.centennium" in selectedFieldNames: upField = "drilldown.norm.date.centennium" elif levelField == "drilldown.norm.date.year" and "drilldown.norm.date.decennium" in selectedFieldNames: upField = "drilldown.norm.date.decennium" elif levelField == "drilldown.norm.name.oneinitial" and "drilldown.norm.name.lastname" in selectedFieldNames: upField = "drilldown.norm.name.lastname" if upField: for term in selectedFieldNames[upField]: if not (upField == previousUpField): label = drilldownFieldNames.get(upField, {'en':upField, 'nl':upField})[language] s += displayLabel(label) drilldownArgs = set(selectedFacets) drilldownArgs.remove(upField + ":" + term) query = createDrilldownQuery(drilldownArgs, sortKeys) s += displayItem(query, term, True, upField, language, total) previousUpField = upField return s def displayDrilldownFields(total, bitMatrixRow, arguments, language): chooseFromTitle = websiteConfig.get('choosefrom') selectedFacets = arguments.get('drilldown', []) selectedFieldNames = {} if selectedFacets: for drilldownItem in selectedFacets: fieldName, value = fieldAndTermSplit(drilldownItem) if not fieldName in selectedFieldNames: selectedFieldNames[fieldName] = [] selectedFieldNames[fieldName].append(value) yield '
' yield '
' + chooseFromTitle +'
' sortKeys = arguments.get('sortKeys', [''])[0] if total < 500000: ####### TP: result set is not too large, multilevel results will be calculated multilevelResults = any.multiLevelDrilldown(bitMatrixRow, ['date', 'author']) for (fieldName, levelField), termCounts in multilevelResults: yield displayDrilldownExtraLabel(levelField, selectedFieldNames, drilldownFieldNames, language, selectedFacets, sortKeys, total) label = drilldownFieldNames.get(levelField, {'en':levelField, 'nl':levelField})[language] yield displayItemGroep(label, termCounts, selectedFacets, levelField, selectedFieldNames, arguments, language, sortKeys) fields = drilldownFields else: ####### TP: result set is too large, only one level of the multilevel facests will be calculated. fields = drilldownFieldsNoMultiLevel drilldownResults = any.drilldown(bitMatrixRow, fields) drilldownResultsAsDict = dict(drilldownResults) for fieldName, number, sorted in fields: termCounts = drilldownResultsAsDict.get(fieldName,[]) label = drilldownFieldNames.get(fieldName, {'en':fieldName, 'nl':fieldName})[language] if termCounts == []: continue yield displayItemGroep(label, termCounts, selectedFacets, fieldName, selectedFieldNames, arguments, language, sortKeys) yield """ %(space)s
%(space)s """ % {'space': space} #def main(hits, httpQuery, arguments, path='', *args, **kwargs): # anton: httpQuery mag waarschijnlijk wel helemaal weg # def main(total, bitMatrixRow, httpQuery, arguments, path='', *args, **kwargs): language = path.startswith('/en/') and 'en' or 'nl' websiteConfig.setDefaults(section='drilldown', language=language) yield space + '
' logger.debug('arguments:\n'+prpt.pformat(arguments)) selectedFacets = arguments.get('drilldown', []) # selectedLabel= any.configuration().get('limitTo','Selected:') selectedLabel= websiteConfig.get('limitTo',default='Selected:') # next line results in: TypeError: not all arguments converted during string formatting sortKeys = arguments.get('sortKeys', [''])[0] if selectedFacets: yield space + '
' yield space + '

%s

' % selectedLabel yield '\n %(space)s
%(space)s """ % {'space': space} if total > 0: yield displayDrilldownFields(total, bitMatrixRow, arguments, language)