
from pyramid.view import view_config

from openchordcharts import model


@view_config(route_name='charts.json', renderer='jsonp')
def charts_json(request):
    return [chart.to_json() for chart in model.Chart.find()]


from pyramid.view import view_config

from openchordcharts import model


@view_config(route_name='charts.json', renderer='jsonp')
def charts_json(request):
    title = request.GET.get('title')
    user = request.GET.get('user')
    spec = {}
    if title:
        spec['title'] = title
    if user:
        spec['user'] = user
    return [chart.to_json() for chart in model.Chart.find(spec)]

Add search by title and user for API.
Add search by title and user for API.

  
  from pyramid.view import view_config
  
  from openchordcharts import model
  
  
  @view_config(route_name='charts.json', renderer='jsonp')
  def charts_json(request):
+     title = request.GET.get('title')
+     user = request.GET.get('user')
+     spec = {}
+     if title:
+         spec['title'] = title
+     if user:
+         spec['user'] = user
-     return [chart.to_json() for chart in model.Chart.find()]
+     return [chart.to_json() for chart in model.Chart.find(spec)]
  
Add search by title and user for API.
## Code Before:

from pyramid.view import view_config

from openchordcharts import model


@view_config(route_name='charts.json', renderer='jsonp')
def charts_json(request):
    return [chart.to_json() for chart in model.Chart.find()]

## Instruction:
Add search by title and user for API.
## Code After:

from pyramid.view import view_config

from openchordcharts import model


@view_config(route_name='charts.json', renderer='jsonp')
def charts_json(request):
    title = request.GET.get('title')
    user = request.GET.get('user')
    spec = {}
    if title:
        spec['title'] = title
    if user:
        spec['user'] = user
    return [chart.to_json() for chart in model.Chart.find(spec)]
