Esempio n. 1
0
 def test_facetResults(self):
     """ Checks type of data returned from query. """
     facet_count_dict = common.facetResults(facet=u'placeMenu')
     log.debug(u'facet_count_dict, ```%s```' %
               pprint.pformat(facet_count_dict))
     for place in [u'Galilee', u'Jordan', u'Judaea']:
         self.assertEqual(True, place in facet_count_dict.keys())
         self.assertEqual(True, type(facet_count_dict[place]) == int)
Esempio n. 2
0
 def __init__(self, *args, **kwargs):
     """ Builds choices dynamically.
         <http://stackoverflow.com/questions/3419997/creating-a-dynamic-choice-field> """
     #
     super(SearchForm, self).__init__(*args, **kwargs)
     log.debug( 'SearchForm() instantiated' )
     #
     # url = 'http://127.0.0.1/test/dev/django_choices.json'
     # r = requests.get( url )
     # log.debug( 'r.content, ```%s```' % r.content )
     # self.choice_places = json.loads( r.content )
     #
     self.choice_places = [(item, item) for item in sorted( common.facetResults('placeMenu').keys()) if item]
     self.fields['place'] = forms.MultipleChoiceField(required=False, choices=self.choice_places, widget=forms.SelectMultiple(attrs={'size':'10'}))
     #
     self.vocab_request = requests.get("http://cds.library.brown.edu/projects/iip/include_taxonomies.xml")
     self.vocab = ET.fromstring(self.vocab_request.content)
     self.taxonomies = self.vocab.findall('{http://www.tei-c.org/ns/1.0}taxonomy')
     #
     self.type_tax = [tax for tax in self.taxonomies if tax.attrib.values()[0] == 'IIP-genre'][0]
     self.types_dict = dict([(element.attrib.values()[0], element.find('{http://www.tei-c.org/ns/1.0}catDesc').text) for element in self.type_tax.findall('{http://www.tei-c.org/ns/1.0}category')])
     self.choice_types = make_vocab_list( self.types_dict, sorted( common.facetResults('type').keys()) )
     self.fields['type'] = forms.MultipleChoiceField(required=False, choices=self.choice_types, widget=forms.SelectMultiple(attrs={'size':'7'}))
     #
     self.phys_types_tax = [tax for tax in self.taxonomies if tax.attrib.values()[0] == 'IIP-form'][0]
     self.physical_types_dict = dict([(element.attrib.values()[0], element.find('{http://www.tei-c.org/ns/1.0}catDesc').text) for element in self.phys_types_tax.findall('{http://www.tei-c.org/ns/1.0}category')])
     self.physical_types = make_vocab_list(self.physical_types_dict, sorted( common.facetResults('physical_type').keys()))
     self.fields['physical_type'] = forms.MultipleChoiceField(required=False, choices=self.physical_types, widget=forms.SelectMultiple(attrs={'size':'7'}))
     #
     self.religions_tax = [tax for tax in self.taxonomies if tax.attrib.values()[0] == 'IIP-religion'][0]
     self.religions = [(element.attrib.values()[0], element.find('{http://www.tei-c.org/ns/1.0}catDesc').text) for element in self.religions_tax.findall('{http://www.tei-c.org/ns/1.0}category')]
     self.fields['religion'] = forms.MultipleChoiceField(required=False, choices=self.religions, widget=forms.CheckboxSelectMultiple)
     #
     self.languages_dict = {
         "he":"Hebrew",
         "la": "Latin",
         "grc": "Greek",
         "arc": "Aramaic",
         "x-unknown":"Unknown"
         }
     self.languages = make_vocab_list(self.languages_dict, sorted( common.facetResults('language').keys()))
     self.fields['language'] = forms.MultipleChoiceField(required=False, choices=self.languages, widget=forms.CheckboxSelectMultiple)
Esempio n. 3
0
 def test_facetResults( self ):
     """ Checks type of data returned from query. """
     facet_count_dict = common.facetResults( facet=u'placeMenu' )
     for place in [  u'Galilee', u'Judaea', u'Lower Galilee' ]:
         self.assertEqual(
             True,
             place in facet_count_dict.keys()
             )
         self.assertEqual(
             True,
             type(facet_count_dict[place]) == int
             )
Esempio n. 4
0
File: tests.py Progetto: crotger/iip
 def test_facetResults( self ):
     """ Checks type of data returned from query. """
     facet_count_dict = common.facetResults( facet=u'placeMenu' )
     log.debug( u'facet_count_dict, ```%s```' % pprint.pformat(facet_count_dict) )
     for place in [  u'Galilee', u'Jordan', u'Judaea' ]:
         self.assertEqual(
             True,
             place in facet_count_dict.keys()
             )
         self.assertEqual(
             True,
             type(facet_count_dict[place]) == int
             )
Esempio n. 5
0
 def __init__(self, *args, **kwargs):
     """ Builds choices dynamically.
         <http://stackoverflow.com/questions/3419997/creating-a-dynamic-choice-field> """
     #
     super(SearchForm, self).__init__(*args, **kwargs)
     log.debug('SearchForm() instantiated')
     #
     # url = 'http://127.0.0.1/test/dev/django_choices.json'
     # r = requests.get( url )
     # log.debug( 'r.content, ```%s```' % r.content )
     # self.choice_places = json.loads( r.content )
     #
     self.choice_places = [
         (item, item)
         for item in sorted(common.facetResults('placeMenu').keys()) if item
     ]
     self.fields['place'] = forms.MultipleChoiceField(
         required=False,
         choices=self.choice_places,
         widget=forms.SelectMultiple(attrs={'size': '10'}))
     #
     self.vocab_request = requests.get(
         "http://cds.library.brown.edu/projects/iip/include_taxonomies.xml")
     self.vocab = ET.fromstring(self.vocab_request.content)
     self.taxonomies = self.vocab.findall(
         '{http://www.tei-c.org/ns/1.0}taxonomy')
     #
     self.type_tax = [
         tax for tax in self.taxonomies
         if tax.attrib.values()[0] == 'IIP-genre'
     ][0]
     self.types_dict = dict([
         (element.attrib.values()[0],
          element.find('{http://www.tei-c.org/ns/1.0}catDesc').text)
         for element in self.type_tax.findall(
             '{http://www.tei-c.org/ns/1.0}category')
     ])
     self.choice_types = make_vocab_list(
         self.types_dict, sorted(common.facetResults('type').keys()))
     self.fields['type'] = forms.MultipleChoiceField(
         required=False,
         choices=self.choice_types,
         widget=forms.SelectMultiple(attrs={'size': '7'}))
     #
     self.phys_types_tax = [
         tax for tax in self.taxonomies
         if tax.attrib.values()[0] == 'IIP-form'
     ][0]
     self.physical_types_dict = dict([
         (element.attrib.values()[0],
          element.find('{http://www.tei-c.org/ns/1.0}catDesc').text)
         for element in self.phys_types_tax.findall(
             '{http://www.tei-c.org/ns/1.0}category')
     ])
     self.physical_types = make_vocab_list(
         self.physical_types_dict,
         sorted(common.facetResults('physical_type').keys()))
     self.fields['physical_type'] = forms.MultipleChoiceField(
         required=False,
         choices=self.physical_types,
         widget=forms.SelectMultiple(attrs={'size': '7'}))
     #
     self.religions_tax = [
         tax for tax in self.taxonomies
         if tax.attrib.values()[0] == 'IIP-religion'
     ][0]
     self.religions = [
         (element.attrib.values()[0],
          element.find('{http://www.tei-c.org/ns/1.0}catDesc').text)
         for element in self.religions_tax.findall(
             '{http://www.tei-c.org/ns/1.0}category')
     ]
     self.fields['religion'] = forms.MultipleChoiceField(
         required=False,
         choices=self.religions,
         widget=forms.CheckboxSelectMultiple)
     #
     self.languages_dict = {
         "he": "Hebrew",
         "la": "Latin",
         "grc": "Greek",
         "arc": "Aramaic",
         "x-unknown": "Unknown"
     }
     self.languages = make_vocab_list(
         self.languages_dict,
         sorted(common.facetResults('language').keys()))
     self.fields['language'] = forms.MultipleChoiceField(
         required=False,
         choices=self.languages,
         widget=forms.CheckboxSelectMultiple)