app package

Submodules

app.daos module

Created on 03/02/2014 This file includes all the daos that support the access to the data

author:Weso
class app.daos.AuthDAO

Bases: app.daos.DAO

Dao for auth user entity

get_by_code(username)

Method that returns a country by its given code

Parameters:username – name of the username requested
Returns:user with given username
update(auth)

Method to update an existing auth user, its username will not be changed

Parameters:auth – user auth to be updated, with updated attributes
class app.daos.CountryDAO

Bases: app.daos.DAO

Dao for country entity

get_by_code(code)

Method that returns a country by its given code

Parameters:code – iso3 of the country requested
Returns:country with given iso3
get_by_id(code)

Method that returns a country by its given id

Parameters:code – id of the country requested
Returns:country with given id
get_countries_by_region(id)

Returns the list of countries that belong to a region

Parameters:id – id of the region
Returns:list of countries
get_countries_with_data_by_region(id)

Returns the countries that have data if they belong to a given region

Parameters:id – id of the given region
Returns:list of countries
get_country_by_region(region_id, iso3)

Returns the given country that belongs to the given region

Parameters:
  • region_id – id of the region to search
  • iso3 – iso3 of the country to search
Returns:

country

update(country)

Method to update an existing country, its code will not be changed

Parameters:country – country to be updated, with updated attributes
class app.daos.DAO(cls)

Bases: object

Generic DAO for all classes, only the class is needed

delete(code)

Method to delete an existing element by its code

Parameters:code – id of the object to be deleted
get_all()

Method that returns all countries in the database

Returns:a collection of all elements
get_by_code(code)

Method that returns a element by its given code

Parameters:code – id of the element requested
Returns:element with the given id
insert(object)

Method that inserts a new element

Parameters:object – element to be inserted
set_session(session)

Method to set the database to use

Parameters:session – session of the database used
update(object)

Method to update an existing element, its code will not be changed

Parameters:object – object to be updated, with updated attributes
class app.daos.IndicatorDAO

Bases: app.daos.DAO

Dao for indicator entity

get_average(indicator_id)

Returns the average of values for an indicator given

Parameters:indicator_id – indicator id of the given indicator
Returns:average
get_indicator_by_country(iso3, indicator_id)

Method to get an indicator of a given country

Parameters:
  • iso3 – iso3 code of the given country
  • indicator_id – indicator id to search
get_indicators_by_country(iso3)

Method to get all the indicators of a given country

Parameters:iso3 – iso3 code of the given country
Returns:indicators of the given country
get_indicators_by_datasource(datasource_id)

Returns the indicators of a datasource

Parameters:datasource_id – datasource id for the given datasource
Returns:indicators of the given datasource
get_starred_indicators()

Returns indicators that are starred

Returns:starred indicators
class app.daos.IndicatorTranslationDAO

Bases: app.daos.DAO

Dao for indicator translation entity

delete(indicator_id, lang_code)

Method that deletes the indicator translation by its given code

Parameters:indicator_id – id of requested indicator
Param:lang_code: code of the language like: ‘en’, ‘es’, ‘fr’
get_by_codes(indicator_id, lang_code)

Method that returns translated indicator

Parameters:indicator_id – id of requested indicator
Param:lang_code: code of the language like: ‘en’, ‘es’, ‘fr’
Returns:indicator translation
update(indicator_translation)

Method to update an existing indicator translation, its code will not be changed

Parameters:indicator_translation – updated indicator translation, with updated attributes
class app.daos.ObservationDAO

Bases: app.daos.DAO

get_by_country_and_indicator(indicator_id, iso3)

Returns observations of a given indicator and a given country

Parameters:
  • indicator_id – id of the given indicator
  • iso3 – iso3 of the given country
get_by_indicator(indicator_id)

Returns the observations of a given indicator

Parameters:indicator_id – id of the given indicator
Returns:list of observations
get_by_region_and_indicator(region_id, indicator_id, limit, offset)

Returns observations of a given region and a given indicator

Parameters:
  • region_id – id of the given region
  • indicator_id – id of the given indicator
  • limit – number of limit results
  • offset – number of results to skip
Returns:

list of observations

get_starred_observations_by_country(iso3, limit, offset)

Returns starred indicators of a country

Parameters:iso3 – iso3 of the given country
Returns:list of observations
get_top_by_region(indicator_id, region_id, top)

Returns observations of a given indicator and a given region.

Parameters:
  • indicator_id – id of the given indicator
  • region_id – id of the given region
  • top – number of results to be returned
Returns:

list of observations

class app.daos.RegionDAO

Bases: app.daos.DAO

Dao for region entity

get_all_regions()

Returns a list of all regions, countries are not included

Returns:list of regions
get_by_artificial_code(code)

Method that returns a region by its given code

Parameters:code – id of the region
Returns:region with given id
get_by_code(code)

Method that returns a region by its given code

Parameters:code – un_code of the region
Returns:region with given un_ocde
get_regions_of_region(id)

Returns a list of regions that belong to a given region

Parameters:id – id of the given region
Returns:list of regions
get_regions_with_data(indicator_id)

Returns the regions that have data for a given indicator

Parameters:indicator_id – id of the given indicator
Returns:list of regions
update(region)

Method to update an existing country, its code will not be changed

Parameters:region – region to be updated, with updated attributes
class app.daos.RegionTranslationDAO

Bases: app.daos.DAO

Dao for region translation entity

delete(region_id, lang_code)

Method that deletes the region translation by its given code

Parameters:region_id – id of requested region
Param:lang_code: code of the language like: ‘en’, ‘es’, ‘fr’
get_by_codes(region_id, lang_code)

Method that returns translated region

Parameters:region_id – id of requested region
Param:lang_code: code of the language like: ‘en’, ‘es’, ‘fr’
Returns:region translation
update(region_translation)

Method to update an existing region translation, its code will not be changed

Parameters:region_translation – updated region translation, with updated attributes
class app.daos.TopicTranslationDAO

Bases: app.daos.DAO

Dao for topic translation entity

delete(topic_id, lang_code)

Method that deletes the topic translation by its given code calling the dao

Parameters:topic_id – id of requested indicator
Param:lang_code: code of the language like: ‘en’, ‘es’, ‘fr’
get_by_codes(topic_id, lang_code)

Method that returns translated topic

Parameters:topic_id – id of requested topic
Param:lang_code: code of the language like: ‘en’, ‘es’, ‘fr’
Returns:topic translation
update(topic_translation)

Method to update an existing country, its code will not be changed

Parameters:topic_translation – updated topic translation, with updated attributes
app.daos.desc(column)

Produce a descending ORDER BY clause element.

e.g.:

from sqlalchemy import desc

stmt = select([users_table]).order_by(desc(users_table.c.name))

will produce SQL as:

SELECT id, name FROM user ORDER BY name DESC

The desc() function is a standalone version of the ColumnElement.desc() method available on all SQL expressions, e.g.:

stmt = select([users_table]).order_by(users_table.c.name.desc())
Parameters:column – A ColumnElement (e.g. scalar SQL expression) with which to apply the desc() operation.

See also

asc()

nullsfirst()

nullslast()

Select.order_by()

app.daos.update_object_attributes(object_to_update, object_with_new_attributes)

Updates all the attributes of an object with other object values all attributes beginning with ‘_’ will not be updated

Parameters:
  • object_to_update – object to be updated
  • object_with_new_attributes – object with the new values

app.services module

Created on 03/02/2014 This file includes all the services that communicate views.py and daos.py

author:Weso
class app.services.AuthService

Bases: app.services.GenericService

Service for auth user dao

class app.services.CountryService

Bases: app.services.GenericService

Service for country dao

delete_all()

Method that deletes all countries by calling the dao

Attention:Take care of what you do, all countries will be destroyed
get_by_id(id)

Returns the country with the given id

Parameters:id – iso3 of the country to search
Returns:country
get_countries_by_regions(un_code)

Returns the countries that belong to the given region

Parameters:un_code – un_code of the given region
Returns:list of countries
get_countries_with_data_by_region(un_code)

Returns the countries that have data and belong to a given region

Parameters:un_code – un_code of the given region
Returns:list of countries
get_country_by_region(un_code, iso3)

Returns the country that belongs to a given region

Parameters:
  • un_code – un_code of the given region
  • iso3 – iso3 code of the country to search
class app.services.DataSourceService

Bases: app.services.GenericService

Service for DataSource dao

class app.services.DatasetService

Bases: app.services.GenericService

Service for Dataset dao

insert(dataset)

Method that inserts a dataset calling the dao

Parameters:dataset – dataset to be persisted
class app.services.GenericService

Bases: object

Generic Service, it provides all default methods that could be used with the majority of the daos

delete(code)

Method that deletes the element by its given code calling the dao

Parameters:code – id of the element to be deleted
delete_all()

Method that deletes all elements by calling the dao

Attention:Take care of what you do, all countries will be destroyed
get_all()

Method that returns all elements given by the dao

Returns:collection of elements
get_by_code(code)

Method that returns element given by the dao

Parameters:code – usually the id
Returns:element that owns the given id
insert(object)

Method that inserts a element calling the dao

Parameters:object – element to be persisted
update(object)

Method that updates the element by calling the dao

Parameters:object – element to be updated with updated attributes
update_all(objects)

Method that updates all the elements given by calling the dao

Params objects:list of objects to be updated with updated attributes
class app.services.IndicatorRelationshipService

Bases: app.services.GenericService

Service for IsPartOf dao

class app.services.IndicatorService

Bases: app.services.GenericService

Service for indicator dao

get_average(indicator_id)

Returns the values averages of a given indicator

Parameters:indicator_id – id of the given indicator
Returns:average
get_indicator_by_country(iso3, indicator_id)

Returns the indicator with the given id and also that belongs to the given country

Parameters:
  • iso3 – iso3 code of the given country
  • indicator_id – id of the indicator to search
get_indicators_by_country(iso3)

Returns the indicators of a given country

Parameters:iso3 – iso3 code of the given country
Returns:list of indicators
get_indicators_by_datasource(datasource_id)

Returns the indicators of a given datasource

Parameters:datasource_id – id of the given datasource
Returns:list of indicators
get_starred_indicators()

Returns the indicators that are starred

Returns:list of indicators
class app.services.IndicatorTranslationService

Bases: app.services.GenericService

Service for indicator translation dao

delete(indicator_id, lang_code)

Method that deletes the indicator translation by its given code calling the dao

Parameters:
  • indicator_id – id of requested indicator
  • lang_code – code of the language like: ‘en’, ‘es’, ‘fr’
delete_all()

Method that deletes all indicator translations by calling the dao

Attention:Take care of what you do, all countries will be destroyed
get_by_codes(indicator_id, lang_code)

Method that returns translated indicator given by the dao

Parameters:
  • indicator_id – id of requested indicator
  • lang_code – code of the language like: ‘en’, ‘es’, ‘fr’
Returns:

indicator translation

class app.services.MeasurementUnitService

Bases: app.services.GenericService

Service for measurement unit dao

class app.services.ObservationService

Bases: app.services.GenericService

Service for organization dao

get_by_country_and_indicator(indicator_id, iso3)

Returns observations of a given country and a given indicator

Parameters:
  • indicator_id – id of the given indicator
  • iso3 – iso3 code of the given country
Returns:

list of observations

get_by_indicator(indicator_id)

Returns observations of a given indicator

Parameters:indicator_id – id of the given indicator
Returns:list of observations
get_by_region_and_indicator(region_id, indicator_id, limit, offset)

Returns observations of a given region and indicator

Parameters:
  • region_id – id of the given region
  • indicator_id – id of the given indicator
  • limit – number of limit results
  • offset – number of results to skip
Returns:

list of observations

get_starred_observations_by_country(iso3, limit, offset)

Returns observations of starred indicators for a given country

Parameters:
  • iso3 – iso3 code of a given country
  • limit – number of limit results
  • offset – number of results to skip
Returns:

list of observations

get_top_by_region(indicator_id, region_id, top)

Returns observations of a given indicator and a given region, with a top

Parameters:
  • indicator_id – id of the given indicator
  • region_id – id of the given region
  • top – number of results to return
Returns:

list of observations

class app.services.OrganizationService

Bases: app.services.GenericService

Service for organization dao

class app.services.RegionService

Bases: app.services.GenericService

Service for region dao

delete_all()

Method that deletes all regions by calling the dao

Attention:Take care of what you do, all regions will be destroyed
get_all_regions()

Returns all regions. Countries are not included

Returns:list of regions
get_by_artificial_code(code)

Returns the region that owns the given code

Parameters:code – id of the region to search
get_regions_of_region(un_code)

Returns regions that belong to a given region

Parameters:un_code – un_code of the given region
Returns:list of regions
get_regions_with_data(indicator_id)

Returns regions with countries that have data for a given indicator

Parameters:indicator_id – id of the given indicator
Returns:list of regions
class app.services.RegionTranslationService

Bases: app.services.GenericService

Service for region translation dao

delete(region_id, lang_code)

Method that deletes the region translation by its given code calling the dao

Parameters:
  • region_id – id of requested region
  • lang_code – code of the language like: ‘en’, ‘es’, ‘fr’
delete_all()

Method that deletes all region translation by calling the dao

Attention:Take care of what you do, all countries will be destroyed
get_by_codes(region_id, lang_code)

Method that returns translated region given by the dao

Parameters:
  • region_id – id of requested region
  • lang_code – code of the language like: ‘en’, ‘es’, ‘fr’
Returns:

region translation

class app.services.TopicService

Bases: app.services.GenericService

Service for Topic dao

class app.services.TopicTranslationService

Bases: app.services.GenericService

Service for topic translation dao

delete(topic_id, lang_code)

Method that deletes the topic translation by its given code calling the dao

Parameters:
  • topic_id – id of requested indicator
  • lang_code – code of the language like: ‘en’, ‘es’, ‘fr’
delete_all()

Method that deletes all countries by calling the dao

Attention:Take care of what you do, all topic translations will be destroyed
get_by_codes(topic_id, lang_code)

Method that returns translated topic given by the dao

Parameters:
  • topic_id – id of requested topic
  • lang_code – code of the language like: ‘en’, ‘es’, ‘fr’
Returns:

topic translation

class app.services.TransactionManager

Bases: object

Transaction manager that helps to abstract from the execution

execute(dao, function, *args)

Abstraction for all calls to the dao methods, like command executor

class app.services.UserService

Bases: app.services.GenericService

Service for user dao

class app.services.ValueService

Bases: app.services.GenericService

Service for Value dao

app.utils module

Created on 03/02/2014 This file includes some util features like marshalling

author:Weso
class app.utils.CSVConverter

Bases: object

CSV converter from objects and list

list_to_csv(elements_list)

Convert a list to its csv equivalent

Parameters:elements_list – collection to be converted
Returns:csv string
object_to_csv(element, header=True, keys=None)

Convert a object to its csv equivalent

Parameters:
  • element – object to be converted
  • header – True if headers are desired, False if not, by default True
  • keys – Header keys to use if method used by list_to_csv, default None
Returns:

csv string

class app.utils.DictionaryList2ObjectList

Bases: object

Class to convert from a list of dictionaries to a list of objects

convert(given_list)

Convert a list of dictionaries in a list of objects

Parameters:given_list – list of dictionaries
Returns:list of object
class app.utils.JSONConverter

Bases: object

JSON converter from objects and list

list_to_json(elements_list)

Convert a list to its json equivalent

Parameters:elements_list – list of elements to be converted
Returns:json array ready be returned as string
object_to_json(element)

Convert a object to its json equivalent

Parameters:element – element to be converted
Returns:json object in string format
class app.utils.Struct(**entries)

Bases: object

Class to convert from dictionary to object

See:http://stackoverflow.com/questions/1305532/convert-python-dict-to-object/1305663#1305663
class app.utils.XMLConverter

Bases: object

XML converter from objects and list

list_to_xml(elements_list, root_node='elements', child_node='element')

Convert a list to its XML equivalent

Parameters:
  • elements_list – list of elements to be converted
  • root_node – name for the root tag in the xml, by default elements
  • child_node – name for object tag in every element of the list, by default element
Returns:

Xml string

object_to_xml(element, root_node='element')

Convert a object to its XML equivalent

Parameters:
  • element – element to be converted
  • root_node – name for root tag on xml, by default element
Returns:

Xml string

app.utils.check_if_date(field_name, object, row)

Convert a date field into long format

Parameters:
  • field_name – name of the field where the date is
  • object – object to store the date in long format
  • row – object, usually a SQLAlchemy row where field is stored
app.utils.get_user_attrs(object)

Return the attributes of an object

Parameters:object – the object to get attributes from
Returns:list of attributes
app.utils.is_primitive(thing)

Check whether a object is of a primitive type or not

Parameters:thing – object to check if its type is primitive
Returns:True if it is primitive, else False
app.utils.row2dict(row)

Converts a row of SQLAlchemy into a dictionary

See:http://stackoverflow.com/questions/1958219/convert-sqlalchemy-row-object-to-python-dict
Parameters:row – SQLAlchemy row
Returns:dictionary

app.views module

Created on 03/02/2014 This file includes all the URI implementation and calls

author:Weso
class app.views.AuthAPI

Bases: flask_restful.Resource

Auth URI

endpoint = 'auth'
mediatypes(resource_cls)
methods = ['POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.CountriesIndicatorAPI

Bases: flask_restful.Resource

Countries Indicator element URI

endpoint = 'countries_indicators'
get(*args, **kwargs)

Show a indicators by its country id and its indicator id If found Response 200 OK Else Response 404 NOT FOUND

mediatypes(resource_cls)
methods = ['GET']
class app.views.CountriesIndicatorLastUpdateAPI

Bases: flask_restful.Resource

More recent indicators of a country collection URI

endpoint = 'countries_indicators_last_update'
get(*args, **kwargs)

Show indicators last_update by a given country Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.CountriesIndicatorListAPI

Bases: flask_restful.Resource

Countries Indicator collection URI

endpoint = 'countries_indicators_list'
get(*args, **kwargs)

List all indicators of a given country Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.CountryAPI

Bases: flask_restful.Resource

Countries element URI

delete(*args, **kwargs)
endpoint = 'countries'
get(*args, **kwargs)

Show country Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.CountryListAPI

Bases: flask_restful.Resource

Countries collection URI

delete(*args, **kwargs)
endpoint = 'countries_list'
get(*args, **kwargs)

List all countries Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.DataSourceAPI

Bases: flask_restful.Resource

Datasources element URI

delete(*args, **kwargs)
endpoint = 'datasources'
get(*args, **kwargs)

Show datasource Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.DataSourceIndicatorAPI

Bases: flask_restful.Resource

Datasource Indicator element URI

endpoint = 'datasources_indicators'
get(*args, **kwargs)

Show indicator by its datasource id and indicator id Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.DataSourceIndicatorListAPI

Bases: flask_restful.Resource

DataSource Indicator collection URI

endpoint = 'datasources_indicators_list'
get(*args, **kwargs)

List all indicators of a given datasource Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.DataSourceListAPI

Bases: flask_restful.Resource

DataSource collection URI

delete(*args, **kwargs)
endpoint = 'datasources_list'
get(*args, **kwargs)

List all datasources Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.DatasetAPI

Bases: flask_restful.Resource

Dataset element URI

delete(*args, **kwargs)
endpoint = 'datasets'
get(*args, **kwargs)

Show dataset Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.DatasetListAPI

Bases: flask_restful.Resource

Dataset collection URI

delete(*args, **kwargs)
endpoint = 'datasets_list'
get(*args, **kwargs)

List all datasets Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.DeleteCacheAPI

Bases: flask_restful.Resource

Delete cache URI

delete(*args, **kwargs)
endpoint = 'delete_cache'
mediatypes(resource_cls)
methods = ['DELETE']
class app.views.EmptyObject

Class to create object without attributes, to be included dynamically

class app.views.IndicatorAPI

Bases: flask_restful.Resource

Indicators element URI

delete(*args, **kwargs)
endpoint = 'indicators'
get(*args, **kwargs)

Show indicator Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.IndicatorAverageAPI

Bases: flask_restful.Resource

Indicator average api

endpoint = 'indicators_average'
get(*args, **kwargs)

Show the average value for a indicator of all countries Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorAverageByPeriodAPI

Bases: flask_restful.Resource

Average of indicator observation by period range

endpoint = 'indicators_average_by_period'
get(*args, **kwargs)

Show average of indicator observations Observations will be filtered between two dates, if they are not supplied whole range will be returned Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorByCountryAndPeriodAPI

Bases: flask_restful.Resource

Countries element URI

endpoint = 'indicators_by_country_and_period'
get(*args, **kwargs)

Show observations by its indicator id and countyr id Observations will be filtered between two dates, if they are not supplied whole range will be returned Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorByPeriodAPI

Bases: flask_restful.Resource

Indicator by period element URI

endpoint = 'indicators_by_period'
get(*args, **kwargs)

Show observations by its given indicator Observations will be filtered between two dates, if they are not supplied whole range will be returned Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorCompatibleAPI

Bases: flask_restful.Resource

Indicator compatible api

endpoint = 'indicators_compatible'
get(*args, **kwargs)

Show the compatible indicators of the given indicator Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorCountryTendencyAPI

Bases: flask_restful.Resource

Indicator country tendency element URI

endpoint = 'indicator_country_tendency'
get(*args, **kwargs)

Show indicator tendency for a country and indicator Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorListAPI

Bases: flask_restful.Resource

Indicators collection URI

delete(*args, **kwargs)
endpoint = 'indicators_list'
get(*args, **kwargs)

List all indicators Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.IndicatorRegionsWihtoutDataAPI

Bases: flask_restful.Resource

Indicator regions without data element URI

endpoint = 'indicators_regions_without_data'
get(*args, **kwargs)

Show observations by its given indicator Observations will be filtered between two dates, if they are not supplied whole range will be returned Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorRegionsWithDataAPI

Bases: flask_restful.Resource

Indicator by period element URI

endpoint = 'indicators_regions_with_data'
get(*args, **kwargs)

Show regions with data for the given indicator Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorRelatedAPI

Bases: flask_restful.Resource

Indicator related collection URI

endpoint = 'indicators_related'
get(*args, **kwargs)

Show related indicators Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorStarredAPI

Bases: flask_restful.Resource

Indicators starred URI

endpoint = 'indicator_starred'
get(*args, **kwargs)

List starred indicators Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorTopAPI

Bases: flask_restful.Resource

Indicator top api

endpoint = 'indicators_top'
get(*args, **kwargs)

Show top 10 countries with the highest value for a given indicator Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.IndicatorTranslationAPI

Bases: flask_restful.Resource

Indicators translations element URI

delete(*args, **kwargs)
endpoint = 'indicator_translations'
get(*args, **kwargs)

Show indicator translation Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.IndicatorTranslationListAPI

Bases: flask_restful.Resource

Indicators translations collection URI

delete(*args, **kwargs)
endpoint = 'indicator_translation_list'
get(*args, **kwargs)

List all indicators translations Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.IndicatorsCountryLastUpdateAPI

Bases: flask_restful.Resource

More recent indicator of a country element URI

endpoint = 'indicators_countries_last_update'
get(*args, **kwargs)

Show indicator last_update by its country id and indicator id Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.MeasurementUnitAPI

Bases: flask_restful.Resource

Measurement unit element URI

delete(*args, **kwargs)
endpoint = 'measurement_unit'
get(*args, **kwargs)

Show measurement unit Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.MeasurementUnitListAPI

Bases: flask_restful.Resource

Measurement unit collection URI

delete(*args, **kwargs)
endpoint = 'measurement_units_list'
get(*args, **kwargs)

List all measurement untis Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.ObservationAPI

Bases: flask_restful.Resource

Observations element URI

delete(*args, **kwargs)
endpoint = 'observations'
get(*args, **kwargs)

Show observations Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.ObservationByCountryStarred

Bases: flask_restful.Resource

Observation by country and starred indicator collection URI

endpoint = 'observations_by_country_starred'
get(*args, **kwargs)

Show observations filtering by country and showed if the indicator is starred. Response 200 OK

Parameters:iso3 – iso3 of the country to filter
mediatypes(resource_cls)
methods = ['GET']
class app.views.ObservationByPeriodAPI

Bases: flask_restful.Resource

Observations by period element URI

endpoint = 'observations_by_period'
get(*args, **kwargs)

Show observations of one of this given as parameter: * Country as iso3 * Indicator as indicator id * Region as un_code Observations will be filtered between two dates, if they are not supplied whole range will be returned Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.ObservationByTwoAPI

Bases: flask_restful.Resource

Observation by two collection URI

endpoint = 'observations_by_two'
get(*args, **kwargs)

Show observations filtering by two ids. It could be one of three next:

  • Indicator id and country iso3
  • Country iso3 and indicator id
  • Region un_code and indicator id
Parameters:
  • id_first_filter – first filter
  • id_second_filter – second filter

Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.ObservationByTwoAverageAPI

Bases: flask_restful.Resource

Observations by two average URI

endpoint = 'observations_by_two_average'
get(*args, **kwargs)

Show observations average filtering by two ids. It could be one of three next:

  • Indicator id and country iso3
  • Country iso3 and indicator id
  • Region un_code and indicator id
Parameters:
  • id_first_filter – first filter
  • id_second_filter – second filter

Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.ObservationListAPI

Bases: flask_restful.Resource

Observations collection URI

delete(*args, **kwargs)
endpoint = 'observations_list'
get(*args, **kwargs)
mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.OrganizationAPI

Bases: flask_restful.Resource

Organizations element URI

delete(*args, **kwargs)
endpoint = 'organizations'
get(*args, **kwargs)

Show organization Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.OrganizationListAPI

Bases: flask_restful.Resource

Organizations collection URI

delete(*args, **kwargs)
endpoint = 'organizations_list'
get(*args, **kwargs)

List all organizations Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.OrganizationUserAPI

Bases: flask_restful.Resource

Organizations users element URI

endpoint = 'organizations_users'
get(*args, **kwargs)

Show a user by its organization id and its user id If found Response 200 OK Else Response 404 NOT FOUND

mediatypes(resource_cls)
methods = ['GET']
class app.views.OrganizationUserListAPI

Bases: flask_restful.Resource

Organizations users collection URI

endpoint = 'organizations_users_list'
get(*args, **kwargs)

List all users of a given organization Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.RegionAPI

Bases: flask_restful.Resource

Regions element URI

delete(*args, **kwargs)
endpoint = 'regions'
get(*args, **kwargs)

Show region Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.RegionCountriesWithDataAPI

Bases: flask_restful.Resource

Countries with data by region element URI

endpoint = 'regions_countries_with_data'
get(*args, **kwargs)

Show country that have some observations by a given region (country is_part_of region) Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.RegionListAPI

Bases: flask_restful.Resource

Regions collection URI

delete(*args, **kwargs)
endpoint = 'regions_list'
get(*args, **kwargs)

List all region Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.RegionTranslationAPI

Bases: flask_restful.Resource

Region translation element URI

delete(*args, **kwargs)
endpoint = 'region_translations'
get(*args, **kwargs)

Show region translation Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.RegionTranslationListAPI

Bases: flask_restful.Resource

Region translation collection URI

delete(*args, **kwargs)
endpoint = 'region_translation_list'
get(*args, **kwargs)

List all translations of a region Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.RegionsCountryAPI

Bases: flask_restful.Resource

Countries Indicator element URI

endpoint = 'regions_countries'
get(*args, **kwargs)

Show country by its region id and its country id Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.RegionsCountryListAPI

Bases: flask_restful.Resource

Regions Country collection URI

endpoint = 'regions_countries_list'
get(*args, **kwargs)

List all countries of a given region Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.RegionsRegionListAPI

Bases: flask_restful.Resource

Regions Region collection URI

endpoint = 'regions_regions_list'
get(*args, **kwargs)

List all regions of a given region Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.TopicAPI

Bases: flask_restful.Resource

Topic element URI

delete(*args, **kwargs)
endpoint = 'topics'
get(*args, **kwargs)

Show topic Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.TopicIndicatorAPI

Bases: flask_restful.Resource

Topics Indicator element URI

endpoint = 'topics_indicators'
get(*args, **kwargs)

Show indicators by its topic id and indicator id Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.TopicIndicatorListAPI

Bases: flask_restful.Resource

Topics Indicator collection URI

endpoint = 'topics_indicators_list'
get(*args, **kwargs)

List all indicators by a given topic Response 200 OK

mediatypes(resource_cls)
methods = ['GET']
class app.views.TopicListAPI

Bases: flask_restful.Resource

Topic collection URI

delete(*args, **kwargs)
endpoint = 'topic_list'
get(*args, **kwargs)

List all topics Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.TopicTranslationAPI

Bases: flask_restful.Resource

Topic translations element URI

delete(*args, **kwargs)
endpoint = 'topic_translations'
get(*args, **kwargs)

Show country topic translation Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.TopicTranslationListAPI

Bases: flask_restful.Resource

Topic translations collection URI

delete(*args, **kwargs)
endpoint = 'topic_translation_list'
get(*args, **kwargs)

List all topic translations Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.UserAPI

Bases: flask_restful.Resource

Users element URI

delete(*args, **kwargs)
endpoint = 'users'
get(*args, **kwargs)

Show user Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.UserListAPI

Bases: flask_restful.Resource

Users collection URI

delete(*args, **kwargs)
endpoint = 'users_list'
get(*args, **kwargs)

List all users Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
class app.views.ValueAPI

Bases: flask_restful.Resource

Value element URI

delete(*args, **kwargs)
endpoint = 'values'
get(*args, **kwargs)

Show value Response 200 OK

mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'PUT']
put(*args, **kwargs)
class app.views.ValueListAPI

Bases: flask_restful.Resource

Value collection URI

delete(*args, **kwargs)
endpoint = 'value_list'
get(*args, **kwargs)
mediatypes(resource_cls)
methods = ['DELETE', 'GET', 'POST', 'PUT']
post(*args, **kwargs)
put(*args, **kwargs)
app.views.areachart()

Visualization of areachart

app.views.authenticate()

Sends a 401 response that enables basic auth

app.views.barChart()

Visualization of barchart

app.views.check_auth(username, password)

This function is called to check if a username / password combination is valid.

app.views.donutchart()

Visualization of donutchart

app.views.filter_by_region_and_top(id)

Filter by region and a top given

Returns:countries top and top observations
app.views.filter_observations_by_date_range(observations, from_date=None, to_date=None)

Filters observations by a given date range

Parameters:
  • observations – list of observations to filter
  • from_date – beginning of the date range
  • to_date – end of the date range
Returns:

filtered list of observations

app.views.get_intervals(times)

Return intervals to xAxis on the graphic

Parameters:times – times collection
Returns:times in the format of the graphic
app.views.get_limit_and_offset()

Returns limit and offset in the request, if not provided limit=30 and offset=0

Returns:limit and offset
app.views.get_observations_by_two_filters(id_first_filter, id_second_filter)

Return observations filtering by two ids. It could be one of three next:

  • Indicator id and country iso3
  • Country iso3 and indicator id
  • Region un_code and indicator id
Parameters:
  • id_first_filter – id of the first filter
  • id_second_filter – id of the second filter
Returns:

Filtered observations

app.views.get_regions_of_region(id)

Returns the regions that belong to another region

Parameters:id – id of the region
Returns:list of regions
app.views.get_regions_with_data(id)

Return all the regions with data for a given indicator

Parameters:id – id of the given indicator
Returns:list of regions with data
app.views.get_requested_lang()

Returns the lang request

Returns:language requested by the client if not given en as default
app.views.get_visualization_json(request, chartType)

Create json object through a dict by request parameters given

Parameters:
  • request – request object from the client
  • chartType – type of chart to be showed
Returns:

json_object, dict to make json.dumps; title, title of the graphic; description, descriptions of the graphic

app.views.get_visualization_map_json(request)

Create json object for map through a dict by request parameters given

Parameters:request – request object from the client
Returns:json_object, dict to make json.dumps; title, title of the graphic; description, descriptions of the graphic
app.views.group_observations_by_years(observations)

Returns a list of observations grouped by years

Parameters:observations – list of observations to group
Returns:list of grouped observations
app.views.help()

Main URI with the documentation redirection

app.views.is_csv_accepted(request)

Returns if csv is accepted or not

Returns:True if csv is accepted, False otherwise
app.views.is_jsonp_accepted(request)

Returns if jsonp is accepted or not

Returns:True if jsonp is accepted, False otherwise
app.views.is_xml_accepted(request)

Returns if xml is accepted or not

Returns:True if xml is accepted, False otherwise
app.views.linechart()

Visualization of linechart

app.views.localhost_decorator(f)

Decorator that allows connections only from localhost, if not it will return a 403 FORBIDDEN error code

app.views.make_cache_key(*args, **kwargs)

Function that allows creating a unique id for every request There was a problem caching and changing arguments of the URL, so this is one possible solution

See:http://stackoverflow.com/questions/9413566/flask-cache-memoize-url-query-string-parameters-as-well
app.views.map(*args, **kwargs)

Visualization of map

app.views.observations_average(observations)

Returns the average of observations values

Parameters:observations – observations to calculate the average
Returns:average
app.views.piechart()

Visualization of piechart

app.views.polarchart()

Visualization of polarchart

app.views.requires_auth(f)
app.views.response_graphics(options, title, description)

Reponses with a page containing the requested graphic

Parameters:
  • options – options dict
  • title – title for the graphic
  • description – description for the graphic
app.views.response_table(options, title, description)

Reponses with a page containing the requested graphic

Parameters:
  • options – options dict
  • title – title for the graphic
  • description – description for the graphic
app.views.response_xml_or_json_item(request, item, item_string)

Return response with the content in the format requested Available formats: * JSON * XML * JSONP * CSV

Parameters:
  • request – the request object
  • item – the object to be converted
  • item_string – the string text to show in the root node, only needed for xml
Returns:

response in the requested format

app.views.response_xml_or_json_list(request, collection, collection_string, item_string)

Return response with the content in the format requested Available formats: * JSON * XML * JSONP * CSV

Parameters:
  • request – the request object
  • collection – the collection to be converted
  • collection_string – the string text to show in the root node, only needed for xml
  • item_string – the string in the root node of the object, only needed for xml
Returns:

response in the requested format

app.views.scatterchart()

Visualization of scatterchart

app.views.slice_by_limit_and_offset(list, limit, offset)

Returns the sliced list

app.views.stackchart()

Visualization of stackedchart

app.views.statitics(*args, **kwargs)

Statitics URI, json returned

app.views.str_date_to_date(date_from, date_to)

Convert two dates in str format to date object Format: YYYYMMDD

Parameters:
  • date_from – beginning of the interval
  • date_to – end of the interval
Returns:

from_date and to_date equivalent of given in date objects

app.views.table()

Visualization of table

app.views.translate_indicator(*args, **kwargs)

Translate an indicator object into given language

Parameters:
  • indicator – indicator object to be translated
  • lang – language of translation, by default en
app.views.translate_indicator_list(*args, **kwargs)

Translate an indicator list into given language

Parameters:indicators – list of indicators to be translated
app.views.translate_region(*args, **kwargs)

Translate a region object into given language

Parameters:
  • region – region object to be translated
  • lang – language of translation, by default en
app.views.translate_region_list(*args, **kwargs)

Translate a region list into given language

Parameters:regions – list of regions to be translated
app.views.translate_topic(*args, **kwargs)

Translate a topic object into given language

Parameters:
  • topic – topic object to be translated
  • lang – language of translation, by default en
app.views.translate_topic_list(*args, **kwargs)

Translate a topic list into given language

Parameters:topics – list of topics to be translated

Module contents

Created on 03/02/2014 This file make the setup configuration for the Flask-Server

author:Weso

Table Of Contents

Previous topic

API

Next topic

model package

This Page