-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathjobapp.py
More file actions
57 lines (52 loc) · 1.65 KB
/
Copy pathjobapp.py
File metadata and controls
57 lines (52 loc) · 1.65 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
from flask import Flask, request, render_template, jsonify
from flaskext.sqlalchemy import SQLAlchemy
import re
app = Flask(__name__)
app.config['SQLALCHEMY_DATABASE_URI'] = 'mysql://root:root@localhost/jobmapper'
db = SQLAlchemy(app)
from models import *
@app.route('/')
def index():
types = []
for post_type in PostType.query.all():
types.append({
'short':post_type.short,
'name':post_type.name,
'id':post_type.id
})
return render_template('index.html',types=types)
@app.route('/posts',methods=['GET','POST'])
def get_jobs():
posts = Post.query.all()
response_types = []
total = 0
if request.method == "POST" and 'region' in request.form:
region = Region.query.filter_by(short=request.form['region']).first()
if not region:
return jsonify(total=0,types=[])
count_list = PostCount.query.filter_by(region_id=region.id).all()
types = PostType.query.all()
for post_type in types:
post_count = None
for count in count_list:
if post_type and count.post_type_id == post_type.id:
response_types.append({
'short':post_type.short,
'size':count.count,
'name':post_type.name
})
if count.post_type_id == None:
total = count.count
return jsonify(total = total,types = response_types)
@app.route('/regions',methods=['GET','POST'])
def get_regions():
regions = []
if request.method == "POST" and 'term' in request.form:
exp = re.compile(request.form['term'])
for region in Region.query.filter_by(published=True).all():
if exp.search(region.short) or (region.name and exp.search(region.name)):
regions.append({
'short':region.short,
'name':region.name
})
return jsonify(regions = regions)