-
Notifications
You must be signed in to change notification settings - Fork 25
/
Copy pathadmin.py
209 lines (173 loc) · 6.42 KB
/
admin.py
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
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
from app import webapp
from app.models import *
from flask import request, make_response
from flask.ext.jsonpify import jsonify
import csv
import StringIO
@webapp.route('/push', methods=['POST'])
def pushNotification():
if 'gcm_id' in request.form:
temp_gcm_id = request.form['gcm_id']
else:
temp_gcm_id = ''
notification_data = json.loads(str(request.form['data']))
status = Notifications(temp_gcm_id).sendNotification(notification_data)
return jsonify(status)
@webapp.route('/currentOrders')
def getCurrentOrders():
current_order = Admin.getCurrentOrders()
return jsonify(orders=current_order)
@webapp.route('/fetchInventoryDetail/<int:inventory_id>')
def fetchItemDetail(inventory_id):
inv_data = Admin.getItemDetail(inventory_id)
return jsonify(inv_data)
@webapp.route('/setInventoryData')
def setInventoryData():
Admin.setInventoryData(request.args)
return jsonify(status=True)
@webapp.route('/currentRentals')
def getCurrentRentals():
current_rentals = Admin.getCurrentRentals()
return jsonify(orders=current_rentals)
@webapp.route('/getPickups')
def getPickups():
pickups = Admin.getPickups()
return jsonify(orders=pickups)
@webapp.route('/removeItem')
def removeItem():
item_ids = [int(_) for _ in request.args.get('item_id').split(",")]
for item_id in item_ids:
Item.removeItem(item_id)
return jsonify({'status': 'True'})
@webapp.route('/deleteOrder', methods=['POST'])
def deleteOrder():
orders = [int(_) for _ in request.form['order_id'].split(",")]
for order in orders:
Order.deleteOrder(order)
return jsonify(status=True)
@webapp.route('/deleteRental', methods=['POST'])
def deleteRentals():
lenders = [int(_) for _ in request.form['order_id'].split(",")]
for lender_id in lenders:
Lend.deleteRental(lender_id)
return jsonify(status=True)
'''
Update status of order in various status
Statuses defined in getOrderStatusDetails method in order model
@params
order_id, status_id
'''
@webapp.route('/updateOrderStatus', methods=['GET'])
def updateOrderStatus():
response = {'status': 'false', 'message': 'Wrong Status Id'}
order_id = Utils.getParam(request.args, 'order_id', 'int')
status_id = Utils.getParam(request.args, 'status_id', 'int')
order_type = Utils.getParam(request.args, 'order_type')
# Asking for user_id to double check
if not(order_id and status_id):
return Utils.errorResponse(response, webapp.config['HTTP_STATUS_CODE_DATA_MISSING'])
if order_type not in ['borrow', 'lend']:
return Utils.errorResponse(response, webapp.config['HTTP_STATUS_CODE_DATA_MISSING'])
if order_type == 'borrow':
if Order.getOrderStatusDetails(status_id):
order_info = Order(order_id).updateOrderStatus(status_id)
return jsonify({'order': order_info})
else:
if Lend.updateLendStatus(order_id, status_id):
return jsonify({'status':'true'})
return Utils.errorResponse(response)
@webapp.route('/crawl')
def crawlItem():
amzn_url = Utils.getParam(request.args, 'url')
book_data = getAggregatedBookDetails(amzn_url)
if book_data['amazon'] and book_data['goodreads']:
final_data = Admin.insertItem(book_data)
else:
final_data = {'status': 'error'}
return jsonify(final_data)
@webapp.route('/authorCrawl')
def authorCrawl():
amzn_url = Utils.getParam(request.args, 'url')
return jsonify(crawlAuthor(amzn_url))
@webapp.route('/getCollectionsList')
def getCollectionsList():
return jsonify(Collection.getPreview())
@webapp.route('/getCollection')
def getCollection():
return jsonify(Collection(request.args.get('id')).getObj())
@webapp.route('/saveCollection')
def setCollection():
item_ids = []
if int(request.args.get('collection_id')):
coll = Collection(int(request.args.get('collection_id')))
item_ids = coll.item_ids if coll.item_ids is not None else item_ids
Collection.saveCollectionData(request.args, item_ids)
return jsonify(status=True)
@webapp.route('/addCollectionCategory')
def addCollectionCategory():
category = Collection.addCategory(request.args)
return jsonify(category)
@webapp.route('/deleteCollection')
def deleteCollection():
Collection.removeCollection(request.args.get('collection_id'))
return jsonify(status=True)
@webapp.route('/getContent')
def getContent():
return jsonify(Search().getContentData())
@webapp.route('/getNewContent')
def getNewContent():
all_content = []
# NOTE make this generic in dashboard
# hard coded panel ids for now
for panel_id in [3,4,5]:
all_content.append(Collection(panel_id).getObj())
return jsonify(all_content)
@webapp.route('/saveContent')
def saveContent():
Admin.savePanelData(request.args)
return jsonify(status=True)
@webapp.route('/getSearchFails')
def getSearchFails():
return jsonify(data=Admin.getSearchFailedQueries())
@webapp.route('/searchFailItem')
def searchFailItem():
Admin.submitSearchFailItem(request.args)
return jsonify(status=True)
@webapp.route('/searchFailNotification')
def searchFailNotification():
Admin.sendSearchFailNotification(request.args)
return jsonify(status=True)
@webapp.route('/incrementInventory')
def incrementInventory():
item_data = Admin.addItemToInventory(int(request.args.get('item_id')))
return jsonify(item_data)
@webapp.route('/updateAreas', methods=['POST'])
def updateAreas():
Admin.updateAreas(request.form)
return jsonify(status='True')
@webapp.route('/orderComment')
def orderComment():
comment_data = {}
for key in request.args:
comment_data[key] = request.args[key]
Admin.updateOrderComment(comment_data)
return jsonify(status=True)
@webapp.route('/uploadBookshotsData', methods=['POST'])
def upload():
uploaded_file = request.files['0']
reader = [row for row in csv.reader(uploaded_file.read().splitlines())]
rows = [row for row in reader[1:] if ''.join(row)]
rows = Admin.updateBookShotsData(rows)
'''
si = StringIO.StringIO()
writer = csv.writer(si)
writer.writerows(rows)
output = make_response(si.getvalue())
output.headers["Content-Disposition"] = "attachment; filename=bs_items.csv"
output.headers["Content-type"] = "text/csv"
return output
'''
return jsonify(status=True)
@webapp.route('/getAllWishlist')
def getAllWishlist():
return jsonify(wishlists=Admin.getAdminWishlist())