Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- @mod.route('/data' ,methods = ['GET'] )
- def data():
- offset = int(request.args['offset'])
- limit = int(request.args['limit'])
- s = coll_gazora.count() #Elemek számolása
- button_list = list(range(s//5+2)) # gombok száma
- #gombok és url összeállítása
- d = []
- for u in button_list:
- d.append({'u':u+1, 'url':'?limit=5&offset='+str(int(u)*5)})
- #rendezés
- start_id = coll_gazora.find().sort('_id',pymongo.ASCENDING)
- last_id = start_id[offset]['_id']
- res = coll_gazora.find({'_id': {'$gte': last_id}}).sort('_id',pymongo.ASCENDING).limit(limit)
- output = []
- for i in res:
- output.append ({'_id':i['_id'],'date':i['date'],'clock_position':i['clock_position'],'consumption':i['consumption']})
- # Hibakezelés
- if (offset+limit) < s:
- next_url = '?limit=' + str(limit) + '&offset='+ str(offset+limit)
- else: next_url = ""
- if (offset-limit) >= 0:
- prev_url = '?limit=' + str(limit) + '&offset='+ str(offset-limit)
- else: prev_url = ""
- return render_template('gasmeter/data.html ', d = d[:-1] ,output = output, next_url = next_url, prev_url = prev_url )
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement