Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature/setup wizard 92627304 #85

Merged
merged 14 commits into from
Apr 29, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions conf/requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
bottle>=0.12.7
python-dateutil==2.2
pytz==2015.2
Babel==1.3
gevent==1.0.1
Mako==1.0.1
Expand Down
5 changes: 1 addition & 4 deletions librarian/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -287,10 +287,7 @@ def start(databases, config, no_auth=False, repl=False, debug=False):
default_locale=lang.DEFAULT_LOCALE,
domain='librarian', locale_dir=in_pkg('locales'))
app.install(lock_plugin)
app.install(setup.setup_plugin(
setup_path=i18n_url('setup:main'),
step_param=setup_route.setup_wizard.step_param
))
app.install(setup.setup_plugin(setup_path=i18n_url('setup:main')))
app.install(content_resolver_plugin(
root_url=config['librarian.root_url'],
ap_client_ip_range=config['librarian.ap_client_ip_range']
Expand Down
29 changes: 20 additions & 9 deletions librarian/lib/wizard.py
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ class Wizard(object):
prefix = 'wizard_'
step_param = 'step'
start_index = 0
allow_back = False
allow_override = False

def __init__(self, name):
self.name = name
Expand Down Expand Up @@ -61,6 +61,9 @@ def step_count(self):
def current_step_index(self):
return self.state['step']

def set_step_index(self, step_index):
self.state['step'] = step_index

def load_state(self):
state = request.session.get(self.id)
if not state:
Expand All @@ -83,7 +86,7 @@ def next(self):
raise MissingStepHandler(self.current_step_index, 'GET')

def override_next_step(self):
if self.allow_back:
if self.allow_override:
override_step = request.params.get(self.step_param)
if override_step is not None:
try:
Expand All @@ -94,9 +97,17 @@ def override_next_step(self):
is_existing_step = step_index in self.steps
is_valid_step = step_index <= self.current_step_index
if is_existing_step and is_valid_step:
self.state['step'] = step_index
self.set_step_index(step_index)

def redirect_to_step(self):
query = '?{0}={1}'.format(self.step_param, self.current_step_index)
return redirect(request.fullpath + query)

def start_next_step(self):
# in case the step param is missing, redirect to same url to include it
if request.params.get('step') is None:
return self.redirect_to_step()

try:
step = next(self)
except StopIteration:
Expand All @@ -106,6 +117,8 @@ def start_next_step(self):
return template(step['template'],
step_index=self.current_step_index,
step_count=self.step_count,
step_param=self.step_param,
start_index=self.start_index,
**step_context)

def process_current_step(self):
Expand All @@ -120,16 +133,14 @@ def process_current_step(self):
return template(step['template'],
step_index=self.current_step_index,
step_count=self.step_count,
step_param=self.step_param,
start_index=self.start_index,
**step_result)

self.state['data'][self.current_step_index] = step_result
self.state['step'] += 1
self.set_step_index(self.current_step_index + 1)
self.save_state()
if self.allow_back:
query = '?{0}={1}'.format(self.step_param, self.current_step_index)
return redirect(request.fullpath + query)

return self.start_next_step()
return self.redirect_to_step()

def wizard_finished(self, data):
raise NotImplementedError()
Expand Down
72 changes: 25 additions & 47 deletions librarian/plugins/ondd/plugin.py
Original file line number Diff line number Diff line change
Expand Up @@ -112,10 +112,7 @@ def get_signal_status():
return dict(status=ipc.get_status())


@view('ondd/settings', vals={}, errors={}, **CONST)
def set_settings():
errors = {}
original_route = request.forms.get('backto', i18n_url('dashboard:main'))
def validate_params(errors):
lnb_type = keyof('lnb', LNB_TYPES,
# Translators, error message when LNB type is incorrect
_('Invalid choice for LNB type'), errors)
Expand Down Expand Up @@ -146,20 +143,37 @@ def set_settings():
# polarization is selected
_('Invalid choice for polarization'), errors)
# TODO: Add support for DiSEqC azimuth value
return dict(lnb_type=lnb_type,
frequency=frequency,
symbolrate=symbolrate,
delivery=delivery,
modulation=modulation,
polarization=polarization)

if errors:
return dict(errors=errors, vals=request.forms)

def setup_ipc(lnb_type, frequency, symbolrate, delivery, modulation,
polarization):
needs_tone = ipc.needs_tone(frequency, lnb_type)
frequency = ipc.freq_conv(frequency, lnb_type)

resp = ipc.set_settings(frequency=frequency,
return ipc.set_settings(frequency=frequency,
symbolrate=symbolrate,
delivery=delivery,
tone=needs_tone,
modulation=dict(MODULATION)[modulation],
voltage=VOLTS[polarization])


@view('ondd/settings', vals={}, errors={}, **CONST)
def set_settings():
errors = {}
original_route = request.forms.get('backto', i18n_url('dashboard:main'))
params = validate_params(errors)

if errors:
return dict(errors=errors, vals=request.forms)

resp = setup_ipc(**params)

if not resp.startswith('2'):
# Translators, error message shown when setting transponder
# configuration is not successful
Expand All @@ -184,36 +198,7 @@ def setup_ondd_form():
@setup_wizard.register_step('ondd', template='ondd_wizard.tpl', method='POST')
def setup_ondd():
errors = {}
lnb_type = keyof('lnb', LNB_TYPES,
# Translators, error message when LNB type is incorrect
_('Invalid choice for LNB type'), errors)
frequency = posint('frequency',
# Translators, error message when frequency value is
# wrong
_('Frequency must be a positive number'),
# Translators, error message when frequency value is
# wrong
_('Please type in a number'), errors)
symbolrate = posint('symbolrate',
# Translators, error message when symbolrate value is
# wrong
_('Symbolrate must be a positive number'),
# Translators, error message when symbolrate value is
# wrong
_('Please type in a number'), errors)
delivery = keyof('delivery', DELIVERY,
# Translators, error message shown when wrong delivery
# system is selected
_('Invalid choice for delivery system'), errors)
modulation = keyof('modulation', MODULATION,
# Translators, error message shown when wrong modulation
# mode is selected
_('Invalid choice for modulation mode'), errors)
polarization = keyof('polarization', POLARIZATION,
# Translators, error message shown when wrong
# polarization is selected
_('Invalid choice for polarization'), errors)
# TODO: Add support for DiSEqC azimuth value
params = validate_params(errors)

if errors:
return dict(successful=False,
Expand All @@ -222,15 +207,7 @@ def setup_ondd():
status=ipc.get_status(),
**CONST)

needs_tone = ipc.needs_tone(frequency, lnb_type)
frequency = ipc.freq_conv(frequency, lnb_type)

resp = ipc.set_settings(frequency=frequency,
symbolrate=symbolrate,
delivery=delivery,
tone=needs_tone,
modulation=dict(MODULATION)[modulation],
voltage=VOLTS[polarization])
resp = setup_ipc(**params)

if not resp.startswith('2'):
# Translators, error message shown when setting transponder
Expand All @@ -244,6 +221,7 @@ def setup_ondd():

logging.info('ONDD: tuner settings updated')

request.app.setup.append({'ondd': True})
return dict(successful=True)


Expand Down
28 changes: 20 additions & 8 deletions librarian/plugins/ondd/static/ondd.js
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,32 @@
};

fields.before(satSelection);
$(function() {
setInterval(doRefresh, refreshInterval);
setInterval(doRefreshFileList, fileRefreshInterval);
})
doRefresh(refreshInterval);
doRefreshFileList(fileRefreshInterval);

satSelector.on('change', updateForm);
updateForm();

function doRefresh() {
signalStatus.load(url);
function doRefresh(interval) {
setTimeout(function () {
$.get(url).done(function (result) {
signalStatus.html(result);
}).always(function () {
doRefresh(interval);
});
}, interval);
}

function doRefreshFileList() {
fileList.load(filesUrl);
function doRefreshFileList(interval) {
if (fileList.length > 0) {
setTimeout(function () {
$.get(filesUrl).done(function (result) {
fileList.html(result);
}).always(function () {
doRefreshFileList(interval);
});
}, interval);
}
}

function updateForm(e) {
Expand Down
22 changes: 2 additions & 20 deletions librarian/plugins/ondd/views/ondd.tpl
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@
<%namespace name="settings_form" file="ondd/_settings_form.tpl"/>
<%namespace name="signal" file="ondd/_signal.tpl"/>
<%namespace name="file_list" file="ondd/_file_list.tpl"/>
<%namespace name="presets" file="ondd/_presets.tpl"/>

<style>@import "${url('plugins:ondd:static', path='ondd.css')}";</style>

Expand All @@ -21,24 +22,5 @@ ${_('Downloads in progress')}
</div>
% endif

<script type="text/template" id="satPresets">
<p class="transponder-selection">
## Translators, label for select list that allows user to pick a satellite to tune into
<label for="transponders">${_('Satellite:')}</label>
<select name="preset" id="transponders" class="transponders">
## Translators, placeholder for satellite selection select list
<option value="0">${_('Select a satellite')}</option>
% for pname, index, preset in PRESETS:
<option value="${index}"
data-frequency="${preset['frequency']}"
data-symbolrate="${preset['symbolrate']}"
data-polarization="${preset['polarization']}"
data-delivery="${preset['delivery']}"
data-modulation="${preset['modulation']}">${pname}</option>
% endfor
## Translators, label for option that allows user to set custom transponder parameters
<option value="-1">${_('Custom...')}</option>
</select>
</p>
</script>
${presets.body()}

20 changes: 20 additions & 0 deletions librarian/plugins/ondd/views/ondd/_presets.tpl
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
<script type="text/template" id="satPresets">
<p class="transponder-selection">
## Translators, label for select list that allows user to pick a satellite to tune into
<label for="transponders">${_('Satellite:')}</label>
<select name="preset" id="transponders" class="transponders">
## Translators, placeholder for satellite selection select list
<option value="0">${_('Select a satellite')}</option>
% for pname, index, preset in PRESETS:
<option value="${index}"
data-frequency="${preset['frequency']}"
data-symbolrate="${preset['symbolrate']}"
data-polarization="${preset['polarization']}"
data-delivery="${preset['delivery']}"
data-modulation="${preset['modulation']}">${pname}</option>
% endfor
## Translators, label for option that allows user to set custom transponder parameters
<option value="-1">${_('Custom...')}</option>
</select>
</p>
</script>
44 changes: 2 additions & 42 deletions librarian/plugins/ondd/views/ondd/_settings_form.tpl
Original file line number Diff line number Diff line change
@@ -1,48 +1,8 @@
<%namespace name="settings_fields" file="_settings_fields.tpl"/>
${h.form('post', action=i18n_url('plugins:ondd:settings'), _class='settings-form', _id='settings-form')}
${h.form_errors(errors)}
<input type="hidden" name="backto" value="${request.original_path}">
<input type="hidden" name="preset">
<div class="lnb-settings">
<p class="lnb">
## Translators, form label for LNB type selection
<label for="lnb">${_('LNB type:')}</label>
${h.vselect('lnb', LNB_TYPES, vals)}
${h.field_error('lnb', errors)}
</p>
</div>
<div class="settings-fields">
<p class="frequency">
## Translators, form label for transponder frequency
<label for="frequency">${_('Frequency:')}</label>
${h.vinput('frequency', vals, type='text')}
${h.field_error('frequency', errors)}
</p>
<p class="symbolrate">
## Translators, form label for transponder symbol rate
<label for="symbolrate">${_('Symbol rate:')}</label>
${h.vinput('symbolrate', vals, type='text')}
${h.field_error('symbolrate', errors)}
</p>
<p class="delivery">
## Translators, form label for transponder delivery system (DVB-S or DVB-S2)
<label for="delivery">${_('Delivery system:')}</label>
${h.vselect('delivery', DELIVERY, vals)}
${h.field_error('delivery', errors)}
</p>
<p class="modulation">
## Translators, form label for transponder modulation mode (QPSK, etc)
<label for="modulation">${_('Modulation:')}</label>
${h.vselect('modulation', MODULATION, vals)}
${h.field_error('modulation', errors)}
</p>
<p class="polarization">
## Translation, form label for transpornder polarization (Vertical/Horizontal)
<label for="polarization">${_('Polarization:')}</label>
${h.vselect('polarization', POLARIZATION, vals)}
${h.field_error('polarization', errors)}
</p>
## TODO: Add support for DiSEqC azimuth value
</div>
${settings_fields.body()}
<p class="buttons-left">
## Translators, button label that confirms tuner settings
<button type="submit">${_('Tune in')}</button>
Expand Down
22 changes: 2 additions & 20 deletions librarian/plugins/ondd/views/ondd_wizard.tpl
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
<%inherit file='/setup/main.tpl'/>
<%namespace name="settings_fields" file="ondd/_settings_fields.tpl"/>
<%namespace name="signal" file="ondd/_signal.tpl"/>
<%namespace name="presets" file="ondd/_presets.tpl"/>

<%block name="step">
<h3>${_("Please select the satellite you'd like to receive data from.")}</h3>
Expand All @@ -16,26 +17,7 @@
${settings_fields.body()}
</div>
</div>
<script type="text/template" id="satPresets">
<p class="transponder-selection">
## Translators, label for select list that allows user to pick a satellite to tune into
<label for="transponders">${_('Satellite:')}</label>
<select name="preset" id="transponders" class="transponders">
## Translators, placeholder for satellite selection select list
<option value="0">${_('Select a satellite')}</option>
% for pname, index, preset in PRESETS:
<option value="${index}"
data-frequency="${preset['frequency']}"
data-symbolrate="${preset['symbolrate']}"
data-polarization="${preset['polarization']}"
data-delivery="${preset['delivery']}"
data-modulation="${preset['modulation']}">${pname}</option>
% endfor
## Translators, label for option that allows user to set custom transponder parameters
<option value="-1">${_('Custom...')}</option>
</select>
</p>
</script>
${presets.body()}
</%block>

<%block name="extra_scripts">
Expand Down
Loading