Skip to content

Commit

Permalink
Municipality-Industry-Year API
Browse files Browse the repository at this point in the history
  • Loading branch information
makmanalp committed Jun 29, 2015
1 parent 993b11d commit 39dfb51
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 1 deletion.
8 changes: 8 additions & 0 deletions colombia/api_schemas.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class Meta:
"department_id", "industry_id", "year")


class MunicipalityIndustryYearSchema(ma.Schema):

class Meta:
fields = ("employment", "wages", "rca", "distance", "cog", "coi",
"municipality_id", "industry_id", "year")


class DepartmentSchema(ma.Schema):

class Meta:
Expand Down Expand Up @@ -65,6 +72,7 @@ class ColombiaMetadataSchema(MetadataSchema):

department_product_year = DepartmentProductYearSchema(many=True)
department_industry_year = DepartmentIndustryYearSchema(many=True)
municipality_industry_year = MunicipalityIndustryYearSchema(many=True)
product_year = ProductYearSchema(many=True)
department = DepartmentSchema(many=True)
metadata = ColombiaMetadataSchema(many=True)
11 changes: 10 additions & 1 deletion colombia/data/views.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
from flask import Blueprint, request
from .models import (DepartmentProductYear, DepartmentIndustryYear,
ProductYear, Location, IndustryYear, DepartmentYear)
MunicipalityIndustryYear, ProductYear, Location,
IndustryYear, DepartmentYear)
from ..api_schemas import marshal
from .. import api_schemas as schemas

Expand Down Expand Up @@ -164,11 +165,19 @@ def industries_index(product_id=None):
q = DepartmentIndustryYear.query\
.filter_by(year=year, department_id=location_id)
return marshal(schemas.department_industry_year, q)
elif location_type == "municipality":
q = MunicipalityIndustryYear.query\
.filter_by(year=year, municipality_id=location_id)
return marshal(schemas.municipality_industry_year, q)
elif location_id is not None:
if location_type == "department":
q = DepartmentIndustryYear.query\
.filter_by(department_id=location_id)
return marshal(schemas.department_industry_year, q)
elif location_type == "municipality":
q = MunicipalityIndustryYear.query\
.filter_by(municipality_id=location_id)
return marshal(schemas.municipality_industry_year, q)

raise abort(400, body="Could not find data with the given parameters.")

Expand Down

0 comments on commit 39dfb51

Please sign in to comment.