Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Reorder the columns in the agency participation CSV #414

Merged
merged 1 commit into from
Mar 15, 2017
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions crime_data/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -117,10 +117,11 @@ def output_csv(data, code, headers=None):
return resp

api.add_resource(crime_data.resources.agencies.AgenciesList, '/agencies/')
api.add_resource(crime_data.resources.agencies.AgenciesParticipation,
'/agencies/participation',
'/agencies/participation/')
api.add_resource(crime_data.resources.agencies.AgenciesDetail,
'/agencies/<string:nbr>/')
api.add_resource(crime_data.resources.agencies.AgenciesParticipation,
'/agencies/participation')

# api.add_resource(crime_data.resources.incidents.IncidentsList,
# '/incidents/')
Expand Down
21 changes: 10 additions & 11 deletions crime_data/resources/agencies.py
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,15 @@ def get(self, args, nbr):

class AgenciesParticipation(CdeResource):

schema = marshmallow_schemas.AgencyParticipationSchema(many=True)
schema = marshmallow_schemas.AgencyParticipationSchema(many=True,
only=('state_name', 'year', 'agency_ori',
'agency_name', 'reported',
'months_reported',
'months_reported_nibrs',
'population_group_code',
'population_group',
'agency_population',)
)
tables = newmodels.AgencyAnnualParticipation
is_groupable = False

Expand All @@ -56,20 +64,11 @@ def postprocess_filters(self, filters, args):
print(filters)
if years:
y = years[0]
data_year = y[2][0]
match = re.search('(\d{4})-(\d{4})', str(data_year))
if match:
data_years = list(range(int(match.group(1)), int(match.group(2))))
else:
data_years = [data_years]

print(data_year)
filters = [x for x in filters if x[0] != 'year']
filters.append(('data_year', y[1], data_years))
filters.append(('data_year', y[1], y[2]))

return filters


@use_args(marshmallow_schemas.ArgumentsSchema)
@swagger.use_kwargs(marshmallow_schemas.ArgumentsSchema, apply=False, locations=['query'])
@swagger.doc(tags=['agencies', 'participation'],
Expand Down