Changeset 207
- Timestamp:
- 09/14/08 22:58:17 (4 months ago)
- Files:
-
- trunk/microfacts/controllers/factlet.py (modified) (1 diff)
- trunk/microfacts/data/napoleon.js (modified) (1 diff)
- trunk/microfacts/getdata/dbpedia.py (modified) (5 diffs)
- trunk/microfacts/lib/cli.py (modified) (1 diff)
- trunk/microfacts/templates/factlet/edit_core.html (modified) (1 diff)
- trunk/microfacts/tests/functional/test_factlet.py (modified) (1 diff)
- trunk/microfacts/tests/getdata/test_dbpedia.py (modified) (1 diff)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
trunk/microfacts/controllers/factlet.py
r206 r207 69 69 logger.debug('Creating new factlet from url: %s' % url) 70 70 # TODO: check dbpedia_enabled is True? 71 d = microfacts.getdata.dbpedia.Describe( )71 d = microfacts.getdata.dbpedia.Describe(recurse_for_location=True) 72 72 d.execute(url) 73 73 try: trunk/microfacts/data/napoleon.js
r195 r207 29 29 "source" : "http://en.wikipedia.org/wiki/Battle_of_Trafalgar", 30 30 "description" : "", 31 "start" : "1805-10-21" 31 "start" : "1805-10-21", 32 "location" : {"type": "Point", "coordinates": [-6.25, 36.166] } 32 33 }, 33 34 { 34 "title" : "Battle of Jena", 35 "source" : "http://en.wikipedia.org/wiki/Battle_of_Jena", 36 "start" : "1806-10-14" 35 "title" : "Battle of Jena-Auerstadt", 36 "source" : "http://en.wikipedia.org/wiki/Battle_of_Jena-Auerstedt", 37 "start" : "1806-10-14", 38 "location" : {"type": "Point", "coordinates": [50.92722, 11.58611] } 37 39 }, 38 40 { trunk/microfacts/getdata/dbpedia.py
r206 r207 75 75 class Describe: 76 76 77 def __init__(self, verbose=False ):77 def __init__(self, verbose=False, recurse_for_location=False): 78 78 self.results = [] 79 79 self.verbose = verbose 80 80 self.language = 'en' 81 self.recurse_for_location = recurse_for_location 81 82 82 83 def execute(self, uri): … … 115 116 return self.to_str() 116 117 117 def extract(self , recurse_for_location=False):118 def extract(self): 118 119 kwds = { 'title' : None, 119 120 'description' : None, … … 170 171 171 172 # get lat/long indirectly ... 172 if recurse_for_location and kwds['place'] and not kwds['long']:173 if self.recurse_for_location and kwds['place'] and not kwds['long']: 173 174 # need to retrieve long/lats from place 174 175 for place in kwds['place']: 175 176 # TODO: put this in debug 176 # print 'Processing place', place 177 if self.verbose: 178 print 'Processing place', place 177 179 newd = Describe() 178 180 newd.execute(place) … … 180 182 # always assume if we have long have lat 181 183 if out['long']: 184 if self.verbose: 185 print 'Using place data from', place 182 186 # should probably record which place this came from somehow 183 187 kwds['long'] = out['long'] … … 242 246 kwds['image'] = kwds['image_urls'][0] 243 247 if kwds['long']: 244 kwds['location'] = { 'type': 'Point', coordinates:None }248 kwds['location'] = { 'type': 'Point', 'coordinates': None } 245 249 kwds['location']['coordinates'] = [ kwds['long'], kwds['lat'] ] 246 250 fct = conv.to_domain_object(kwds) trunk/microfacts/lib/cli.py
r206 r207 136 136 if cmd == 'describe': 137 137 uri = self.args[1] 138 result = dbp.describe(uri, verbose=self.verbose) 138 d = dbp.Describe(verbose=self.verbose, 139 recurse_for_location=True) 140 d.execute(uri) 141 result = str(d) 139 142 elif cmd == 'search': 140 143 category = self.args[1] trunk/microfacts/templates/factlet/edit_core.html
r199 r207 27 27 </dd> 28 28 <dt>Location</dt> 29 <dd> 30 <label>Long:</label> ${h.text_field('location__x', value=value_of(c.factlet.location.x, None))} <br /> 31 <label>Lat:</label> ${h.text_field('location__y', value=value_of(c.factlet.location.y, None))} 29 <dd py:with="tlocation=getattr(c.factlet, 'location', None)"> 30 <label>Long:</label> 31 ${h.text_field('location__x', value=getattr(tlocation, 'x', None))} 32 <br /> 33 <label>Lat:</label> 34 ${h.text_field('location__y', value=getattr(tlocation, 'y', None))} 32 35 </dd> 33 36 <dt>Source Url</dt> trunk/microfacts/tests/functional/test_factlet.py
r206 r207 110 110 assert str(fct.license) in response 111 111 assert fct.start in response 112 # *really* weird, value_of does not work in template now but plain 113 # ${c.factlet.location.x} does! 114 # assert fct.location.x in response 112 assert fct.location.x in response 115 113 assert '<label>' in response 116 114 # check no change to domain model ... trunk/microfacts/tests/getdata/test_dbpedia.py
r206 r207 40 40 def setup_class(self): 41 41 uri3 = 'http://dbpedia.org/resource/Battle_of_Austerlitz' 42 self.d = Describe( )42 self.d = Describe(recurse_for_location=True) 43 43 self.d.execute(uri3) 44 self.kwds = self.d.extract( recurse_for_location=True)44 self.kwds = self.d.extract() 45 45 self.fct = None 46 46 self.start = datetime.datetime(1805, 12, 2)
