Skip to content
This repository has been archived by the owner on Oct 5, 2024. It is now read-only.

Commit

Permalink
Merge pull request #168 from doudz/dev
Browse files Browse the repository at this point in the history
Fix 404 error
  • Loading branch information
doudz authored Jan 21, 2020
2 parents 1093026 + ff73d28 commit 3b049a1
Show file tree
Hide file tree
Showing 2 changed files with 13 additions and 7 deletions.
18 changes: 12 additions & 6 deletions zigate/adminpanel/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,12 @@ def get_url(routename, **kwargs):
url += '{}_={}'.format(append, time.time())
return url

def redirect(routename, **kwargs):
'''
convenient function to redirect using routename instead of url
'''
return bottle.redirect(get_url(routename, redirect=True, **kwargs))

bottle.BaseTemplate.defaults['get_url'] = get_url
bottle.BaseTemplate.defaults['zigate'] = zigate_instance
app.zigate = zigate_instance
Expand Down Expand Up @@ -105,35 +111,35 @@ def networkmap():
def device(addr):
device = zigate_instance.get_device_from_addr(addr)
if not device:
return bottle.redirect(get_url('index'))
return redirect('index')
return {'device': device}

@app.route('/api/permit_join', name='api_permit_join')
def permit_join():
zigate_instance.permit_join()
return bottle.redirect(get_url('index'))
return redirect('index')

@app.route('/api/led', name='api_led')
def set_led():
on = bottle.request.query.get('on', 'true') == 'true'
zigate_instance.set_led(on)
return bottle.redirect(get_url('index'))
return redirect('index')

@app.route('/api/discover/<addr>', name='api_discover')
def api_discover(addr):
zigate_instance.discover_device(addr, True)
return bottle.redirect(get_url('device', addr=addr, redirect=True))
return redirect('device', addr=addr)

@app.route('/api/refresh/<addr>', name='api_refresh')
def api_refresh(addr):
zigate_instance.refresh_device(addr)
return bottle.redirect(get_url('device', addr=addr, redirect=True))
return redirect('device', addr=addr)

@app.route('/api/remove/<addr>', name='api_remove')
def api_remove(addr):
force = bottle.request.query.get('force', 'false') == 'true'
zigate_instance.remove_device(addr, force)
return bottle.redirect(get_url('index'))
return redirect('index')

@app.route('/api/devices', name='api_devices')
def devices():
Expand Down
2 changes: 1 addition & 1 deletion zigate/version.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,4 +6,4 @@
#


__version__ = '0.38.2'
__version__ = '0.38.3'

0 comments on commit 3b049a1

Please sign in to comment.