Created
January 3, 2014 04:19
-
-
Save anxiousmodernman/8232631 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import os | |
from flask import Flask, request, Response | |
from flask import render_template, url_for, redirect, send_from_directory | |
from flask import send_file, make_response, abort, jsonify | |
from sqlalchemy.orm import sessionmaker | |
from shark import app | |
from settings import MSSQL_ENV_CONFIG | |
from datasource.engines import get_mssql_engine | |
from schemas.alchemy import BriefTable, LinkSubscriberBriefTable, SubscriberTable, SubscriberBriefProfileTable | |
from shark.interfaces import ContainsFieldValueSearch | |
engine = get_mssql_engine(MSSQL_ENV_CONFIG) | |
Session = sessionmaker(bind=engine) | |
db_session = Session() | |
# routing for basic pages (pass routing onto the Angular app) | |
@app.route('/') | |
@app.route('/bio') | |
@app.route('/routetest') | |
def basic_pages(**kwargs): | |
return make_response(open('shark/templates/index.html').read()) | |
@app.route('/search', methods=['POST']) | |
def handle_search_call(): | |
q = db_session.query(SubscriberTable.first_name, | |
SubscriberTable.last_name, | |
SubscriberTable.last_open, | |
SubscriberTable.email, | |
SubscriberTable.company).\ | |
join(SubscriberBriefProfileTable) | |
search = ContainsFieldValueSearch(fields=request.json) | |
for k, v in search.fields: | |
q = q.filter(getattr(SubscriberTable, v).like("%%%s%%" % v)) | |
q = q.limit(20) # todo raise limit | |
# result set | |
result_set = q.all() | |
print result_set |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
the query construction code was not working in this, but i got it working.