Changeset 168:6b19e9df4328

Show
Ignore:
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:
4 modified

Legend:

Unmodified
Added
Removed
  • microfacts/model/__init__.py

    r127 r168  
    2424# properly once we have postgis installed 
    2525class GeometryPlain(types.TypeDecorator): 
    26     impl = types.String 
     26    impl = types.Text 
    2727    def __init__(self, srid, geom_type, dims=2): 
    2828        super(GeometryPlain, self).__init__() 
     
    4949factlet_table = Table('factlet', metadata, 
    5050    Column('id', types.Integer, primary_key=True), 
    51     Column('title', types.Unicode(255)), 
     51    Column('title', types.UnicodeText), 
    5252    Column('description', types.UnicodeText), 
     53    Column('image', types.UnicodeText), 
    5354    Column('start', types.DateTime), 
    5455    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), 
    5659) 
    5760 
    5861thread_table = Table('thread', metadata, 
    5962    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'), 
    6165) 
    6266 
  • microfacts/tests/data/napoleon.js

    r157 r168  
    11{ 
    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  
    182  "title" : "Battles in the Napoleonic Wars", 
    193  "factlets" : [ 
     
    226      "description" : 
    237        "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", 
    259      "start" : "1805-12-02", 
    2610      "location" : {"type": "Point", "coordinates": [16.7622 , 49.1281] } 
     
    3014      "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", 
    3115      "start" : "1812-09-07", 
    32       "url" : "http://en.wikipedia.org/wiki/Battle_of_Borodino", 
     16      "source" : "http://en.wikipedia.org/wiki/Battle_of_Borodino", 
    3317      "location" : [35.8212 , 55.5085] 
    3418    }, 
    3519    { 
    3620      "title" : "Battle of Waterloo", 
    37       "url" : "http://en.wikipedia.org/wiki/Battle_of_Waterloo", 
     21      "source" : "http://en.wikipedia.org/wiki/Battle_of_Waterloo", 
    3822      "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", 
    3923      "start" : "1815-06-18", 
     
    4226    { 
    4327      "title" : "Battle of Trafalgar", 
    44       "url" : "http://en.wikipedia.org/wiki/Battle_of_Trafalgar", 
     28      "source" : "http://en.wikipedia.org/wiki/Battle_of_Trafalgar", 
    4529      "description" : "", 
    4630      "start" : "1805-10-21" 
     
    4832    { 
    4933      "title" : "Battle of Jena", 
    50       "url" : "http://en.wikipedia.org/wiki/Battle_of_Jena", 
     34      "source" : "http://en.wikipedia.org/wiki/Battle_of_Jena", 
    5135      "start" : "1806-10-14" 
    5236    }, 
    5337    { 
    5438      "title" : "Battle of Friedland", 
    55       "url" : "1807-06-14", 
     39      "start" : "1807-06-14", 
    5640      "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", 
    5741      "location" : {"type": "Point", "coordinates": [21.0167 , 54.45] } 
  • microfacts/tests/test_json.py

    r158 r168  
    1313 
    1414class 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' 
    1517    factlet_json = \ 
    1618''' 
     
    1921  "description" : 
    2022    "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", 
    2225  "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" 
    2428} 
    25 ''' 
     29''' % (source_url, image_url) 
    2630 
    2731    def setUp(self, name=''): 
     
    4549        assert ftout 
    4650        assert ftout.title == u'Battle of Austerlitz' 
     51        assert ftout.image == self.image_url 
     52        assert ftout.source == self.source_url 
    4753        expdt = dateutil.parser.parse('1805-12-02') 
    4854        assert ftout.start == expdt 
    4955        explocation = shapely.geometry.Point(49.1281, 16.7622) 
    5056        assert ftout.location.x == explocation.x 
     57        assert ftout.license == u'GFDL' 
    5158 
    5259    def test_load_factlet(self): 
     
    181188        assert out['id'] == self.factlet.id 
    182189        assert out['title'] == self.factlet.title 
     190        assert out['image'] and out['image'] == self.factlet.image 
    183191        print out['location'] 
    184192        assert out['location']['type'] == u'Point' 
    185193        assert out['location']['coordinates'][0] == -0.12553 
     194        assert out['license'] and out['license'] == self.factlet.license 
    186195 
    187196    def test_dump_thread(self): 
  • microfacts/tests/test_models.py

    r127 r168  
    2424        title2 = u'War and Peace' 
    2525        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' 
    2628        fct1 = model.Factlet( 
    2729                title=title1, 
     
    3133tragic love affair between the eponymous heroine and Count Vronsky.''', 
    3234                location=russia, 
     35                image=image_url, 
     36                source=source, 
    3337                ) 
    3438        fct2 = model.Factlet( 
     
    4145Napoleonic Era.''', 
    4246                location=russia, 
     47                license=u'GFDL', 
    4348                ) 
    4449        title3 = u"Tolstoy's Life and Works" 
     
    5762        outfct1 = model.Factlet.query.filter_by(title=title1).one()  
    5863        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' 
    5968        assert outfct1.start == start1 
    6069        # simple equality does not work ... 
    6170        assert outfct1.location.x == russia.x 
    6271        assert outfct1.location.y == russia.y 
     72        assert outfct1.source == source 
    6373 
    6474        outthread1 = model.Thread.query.filter_by(title=title3).one() 
    6575        assert outfct1 in outthread1.factlets 
    6676        assert outfct2 in outthread1.factlets 
     77        assert outthread1.license == u'CC-BY' 
    6778 
    6879    def test_Session_and_flush(self): 
     
    7384 
    7485    def test_as_json(self): 
     86        # don't get too carried away here as much of this under test in 
     87        # converter code  
    7588        fct = model.Factlet.query.filter_by(title=u'Anna Karenina').one() 
    7689        out = fct.as_json()