Changeset 168:6b19e9df4328
- Timestamp:
- 08/21/08 17:58:53 (2 years ago)
- Author:
- rgrp
- Branch:
- default
- convert_revision:
- svn:10edda23-d834-0410-9182-b00384516d49/trunk@178
- Message:
-
[model][m]: add image, source and license attributes to factlet and license attribute to thread. As yet have not extended support (or tests) for these new items to WUI.
- Location:
- microfacts
- Files:
-
Legend:
- Unmodified
- Added
- Removed
-
|
r127
|
r168
|
|
| 24 | 24 | # properly once we have postgis installed |
| 25 | 25 | class GeometryPlain(types.TypeDecorator): |
| 26 | | impl = types.String |
| | 26 | impl = types.Text |
| 27 | 27 | def __init__(self, srid, geom_type, dims=2): |
| 28 | 28 | super(GeometryPlain, self).__init__() |
| … |
… |
|
| 49 | 49 | factlet_table = Table('factlet', metadata, |
| 50 | 50 | Column('id', types.Integer, primary_key=True), |
| 51 | | Column('title', types.Unicode(255)), |
| | 51 | Column('title', types.UnicodeText), |
| 52 | 52 | Column('description', types.UnicodeText), |
| | 53 | Column('image', types.UnicodeText), |
| 53 | 54 | Column('start', types.DateTime), |
| 54 | 55 | Column('end', types.DateTime), |
| 55 | | Column('location', GeometryPlain(4326, 'POINT')) |
| | 56 | Column('location', GeometryPlain(4326, 'POINT')), |
| | 57 | Column('license', types.UnicodeText, default=u'CC-BY'), |
| | 58 | Column('source', types.UnicodeText), |
| 56 | 59 | ) |
| 57 | 60 | |
| 58 | 61 | thread_table = Table('thread', metadata, |
| 59 | 62 | Column('id', types.Integer, primary_key=True), |
| 60 | | Column('title', types.Unicode(255)), |
| | 63 | Column('title', types.UnicodeText), |
| | 64 | Column('license', types.UnicodeText, default=u'CC-BY'), |
| 61 | 65 | ) |
| 62 | 66 | |
-
|
r157
|
r168
|
|
| 1 | 1 | { |
| 2 | | "dev-comments" : "JSON does not allow normal js comments so I am wrapping them in here: |
| 3 | | 1. Could have multiple threads in which case one needs |
| 4 | | { |
| 5 | | threads : [ |
| 6 | | { |
| 7 | | title : |
| 8 | | factlets : [ |
| 9 | | ] |
| 10 | | } |
| 11 | | ] |
| 12 | | } |
| 13 | | |
| 14 | | 2. Below is a single thread. |
| 15 | | * Note that there is no uuid/uri on the thread. When this is not present it will be autogenerated on import. |
| 16 | | ", |
| 17 | | |
| 18 | 2 | "title" : "Battles in the Napoleonic Wars", |
| 19 | 3 | "factlets" : [ |
| … |
… |
|
| 22 | 6 | "description" : |
| 23 | 7 | "The Battle of Austerlitz (Czech: 'Battle of Slavkov'), also known as the Battle of the Three Emperors, was one of Napoleon's greatest victories, effectively destroying the Third Coalition against the French Empire. On December 2 1805, French troops, commanded by Emperor Napoleon I, decisively defeated a Russo-Austrian army, commanded by Tsar Alexander I, after nearly nine hours", |
| 24 | | "url" : "http://en.wikipedia.org/wiki/Battle_of_Austerlitz", |
| | 8 | "source" : "http://en.wikipedia.org/wiki/Battle_of_Austerlitz", |
| 25 | 9 | "start" : "1805-12-02", |
| 26 | 10 | "location" : {"type": "Point", "coordinates": [16.7622 , 49.1281] } |
| … |
… |
|
| 30 | 14 | "description" : "The Battle of Borodino (September 7, 1812, or August 26 in the Julian calendar then used in Russia), was the largest and bloodiest single-day battle of the Napoleonic Wars, involving more than a quarter of a million soldiers. It was fought by the French ''Grande Armée'' under Napoleon I and the Imperial Russian army of General Mikhail Kutusov near the village of Borodino, west", |
| 31 | 15 | "start" : "1812-09-07", |
| 32 | | "url" : "http://en.wikipedia.org/wiki/Battle_of_Borodino", |
| | 16 | "source" : "http://en.wikipedia.org/wiki/Battle_of_Borodino", |
| 33 | 17 | "location" : [35.8212 , 55.5085] |
| 34 | 18 | }, |
| 35 | 19 | { |
| 36 | 20 | "title" : "Battle of Waterloo", |
| 37 | | "url" : "http://en.wikipedia.org/wiki/Battle_of_Waterloo", |
| | 21 | "source" : "http://en.wikipedia.org/wiki/Battle_of_Waterloo", |
| 38 | 22 | "description" : "1815, was Napoleon Bonaparte's last battle. His defeat put a final end to his rule as Emperor of France. The Battle of Waterloo also marked the end of the period known as the Hundred Days, which began in March 1815 after Napoleon's return from Elba, where he had been exiled after his defeat at the battle of Leipzig in 1813", |
| 39 | 23 | "start" : "1815-06-18", |
| … |
… |
|
| 42 | 26 | { |
| 43 | 27 | "title" : "Battle of Trafalgar", |
| 44 | | "url" : "http://en.wikipedia.org/wiki/Battle_of_Trafalgar", |
| | 28 | "source" : "http://en.wikipedia.org/wiki/Battle_of_Trafalgar", |
| 45 | 29 | "description" : "", |
| 46 | 30 | "start" : "1805-10-21" |
| … |
… |
|
| 48 | 32 | { |
| 49 | 33 | "title" : "Battle of Jena", |
| 50 | | "url" : "http://en.wikipedia.org/wiki/Battle_of_Jena", |
| | 34 | "source" : "http://en.wikipedia.org/wiki/Battle_of_Jena", |
| 51 | 35 | "start" : "1806-10-14" |
| 52 | 36 | }, |
| 53 | 37 | { |
| 54 | 38 | "title" : "Battle of Friedland", |
| 55 | | "url" : "1807-06-14", |
| | 39 | "start" : "1807-06-14", |
| 56 | 40 | "description" : "The Battle of Friedland, fought on June 14, 1807 about twenty-seven miles (43 km) southeast of the modern Russian city of Kaliningrad, just north of Poland, was a major engagement in the Napoleonic Wars effectively ending the War of the Fourth Coalition. The conflict involved forces of the First French Empire against the army of the Russian Empire", |
| 57 | 41 | "location" : {"type": "Point", "coordinates": [21.0167 , 54.45] } |
-
|
r158
|
r168
|
|
| 13 | 13 | |
| 14 | 14 | class TestJsonFactlet(object): |
| | 15 | image_url = u'http://www.microfacts.org/images/anna.png' |
| | 16 | source_url = u'http://en.wikipedia.org/wiki/Battle_of_Austerlitz' |
| 15 | 17 | factlet_json = \ |
| 16 | 18 | ''' |
| … |
… |
|
| 19 | 21 | "description" : |
| 20 | 22 | "The Battle of Austerlitz (Czech: 'Battle of Slavkov'), also known as the Battle of the Three Emperors, was one of Napoleon's greatest victories, effectively destroying the Third Coalition against the French Empire. On December 2 1805, French troops, commanded by Emperor Napoleon I, decisively defeated a Russo-Austrian army, commanded by Tsar Alexander I, after nearly nine hours", |
| 21 | | "url" : "http://en.wikipedia.org/wiki/Battle_of_Austerlitz", |
| | 23 | "source" : "%s", |
| | 24 | "image" : "%s", |
| 22 | 25 | "start" : "1805-12-02", |
| 23 | | "location" : {"type": "Point", "coordinates": [49.1281, 16.7622]} |
| | 26 | "location" : {"type": "Point", "coordinates": [49.1281, 16.7622]}, |
| | 27 | "license" : "GFDL" |
| 24 | 28 | } |
| 25 | | ''' |
| | 29 | ''' % (source_url, image_url) |
| 26 | 30 | |
| 27 | 31 | def setUp(self, name=''): |
| … |
… |
|
| 45 | 49 | assert ftout |
| 46 | 50 | assert ftout.title == u'Battle of Austerlitz' |
| | 51 | assert ftout.image == self.image_url |
| | 52 | assert ftout.source == self.source_url |
| 47 | 53 | expdt = dateutil.parser.parse('1805-12-02') |
| 48 | 54 | assert ftout.start == expdt |
| 49 | 55 | explocation = shapely.geometry.Point(49.1281, 16.7622) |
| 50 | 56 | assert ftout.location.x == explocation.x |
| | 57 | assert ftout.license == u'GFDL' |
| 51 | 58 | |
| 52 | 59 | def test_load_factlet(self): |
| … |
… |
|
| 181 | 188 | assert out['id'] == self.factlet.id |
| 182 | 189 | assert out['title'] == self.factlet.title |
| | 190 | assert out['image'] and out['image'] == self.factlet.image |
| 183 | 191 | print out['location'] |
| 184 | 192 | assert out['location']['type'] == u'Point' |
| 185 | 193 | assert out['location']['coordinates'][0] == -0.12553 |
| | 194 | assert out['license'] and out['license'] == self.factlet.license |
| 186 | 195 | |
| 187 | 196 | def test_dump_thread(self): |
-
|
r127
|
r168
|
|
| 24 | 24 | title2 = u'War and Peace' |
| 25 | 25 | russia = shapely.geometry.Point(55.0,37.0) |
| | 26 | image_url = u'http://www.microfacts.org/images/anna.png' |
| | 27 | source = u'http://en.wikipedia.org/wiki/Anna_Karenina' |
| 26 | 28 | fct1 = model.Factlet( |
| 27 | 29 | title=title1, |
| … |
… |
|
| 31 | 33 | tragic love affair between the eponymous heroine and Count Vronsky.''', |
| 32 | 34 | location=russia, |
| | 35 | image=image_url, |
| | 36 | source=source, |
| 33 | 37 | ) |
| 34 | 38 | fct2 = model.Factlet( |
| … |
… |
|
| 41 | 45 | Napoleonic Era.''', |
| 42 | 46 | location=russia, |
| | 47 | license=u'GFDL', |
| 43 | 48 | ) |
| 44 | 49 | title3 = u"Tolstoy's Life and Works" |
| … |
… |
|
| 57 | 62 | outfct1 = model.Factlet.query.filter_by(title=title1).one() |
| 58 | 63 | outfct2 = model.Factlet.query.filter_by(title=title2).one() |
| | 64 | assert outfct1.image == image_url |
| | 65 | # check default value |
| | 66 | assert outfct1.license == u'CC-BY' |
| | 67 | assert outfct2.license == u'GFDL' |
| 59 | 68 | assert outfct1.start == start1 |
| 60 | 69 | # simple equality does not work ... |
| 61 | 70 | assert outfct1.location.x == russia.x |
| 62 | 71 | assert outfct1.location.y == russia.y |
| | 72 | assert outfct1.source == source |
| 63 | 73 | |
| 64 | 74 | outthread1 = model.Thread.query.filter_by(title=title3).one() |
| 65 | 75 | assert outfct1 in outthread1.factlets |
| 66 | 76 | assert outfct2 in outthread1.factlets |
| | 77 | assert outthread1.license == u'CC-BY' |
| 67 | 78 | |
| 68 | 79 | def test_Session_and_flush(self): |
| … |
… |
|
| 73 | 84 | |
| 74 | 85 | def test_as_json(self): |
| | 86 | # don't get too carried away here as much of this under test in |
| | 87 | # converter code |
| 75 | 88 | fct = model.Factlet.query.filter_by(title=u'Anna Karenina').one() |
| 76 | 89 | out = fct.as_json() |