pep8 coding guidline adaption

This commit is contained in:
daniel steglich 2015-01-04 13:50:26 +01:00
parent 56208e007d
commit 3bf0079b3b

View File

@ -37,16 +37,19 @@ subsubmenu = [{'url': reverse_lazy('dynamicDNS:index'),
'text': _('Status')} 'text': _('Status')}
] ]
def init(): def init():
"""Initialize the dynamicDNS module""" """Initialize the dynamicDNS module"""
menu = cfg.main_menu.get('apps:index') menu = cfg.main_menu.get('apps:index')
menu.add_urlname('dynamicDNS', 'glyphicon-comment', 'dynamicDNS:index', 40) menu.add_urlname('dynamicDNS', 'glyphicon-comment', 'dynamicDNS:index', 40)
@login_required @login_required
def index(request): def index(request):
"""Serve dynamic DNS page""" """Serve dynamic DNS page"""
is_installed = actions.run('dynamicDNS', ['get-installed']).strip() == 'installed' is_installed = actions.run('dynamicDNS', ['get-installed']).strip() \
== 'installed'
if is_installed: if is_installed:
index_subsubmenu = subsubmenu index_subsubmenu = subsubmenu
@ -58,6 +61,7 @@ def index(request):
'is_installed': is_installed, 'is_installed': is_installed,
'subsubmenu': index_subsubmenu}) 'subsubmenu': index_subsubmenu})
class TrimmedCharField(forms.CharField): class TrimmedCharField(forms.CharField):
"""Trim the contents of a CharField""" """Trim the contents of a CharField"""
def clean(self, value): def clean(self, value):
@ -67,6 +71,7 @@ class TrimmedCharField(forms.CharField):
return super(TrimmedCharField, self).clean(value) return super(TrimmedCharField, self).clean(value)
class ConfigureForm(forms.Form): class ConfigureForm(forms.Form):
"""Form to configure the dynamic DNS client""" """Form to configure the dynamic DNS client"""
enabled = forms.BooleanField(label=_('Enable dynamicDNS'), enabled = forms.BooleanField(label=_('Enable dynamicDNS'),
@ -88,29 +93,35 @@ class ConfigureForm(forms.Form):
dynamicDNS_User = TrimmedCharField( dynamicDNS_User = TrimmedCharField(
label=_('Username'), label=_('Username'),
help_text=_('You should have been requested to select a username when you created the account')) help_text=_('You should have been requested to select a username \
when you created the account'))
dynamicDNS_Secret = TrimmedCharField( dynamicDNS_Secret = TrimmedCharField(
label=_('Password'), widget=forms.PasswordInput(), label=_('Password'), widget=forms.PasswordInput(),
required=False, required=False,
help_text=_('You should have been requested to select a password when you created the account. \ help_text=_('You should have been requested to select a password \
If you left this field empty your password will be unchanged.')) when you created the account. If you left this field \
empty your password will be unchanged.'))
dynamicDNS_Secret_repeat = TrimmedCharField( dynamicDNS_Secret_repeat = TrimmedCharField(
label=_('repeat Password'), widget=forms.PasswordInput(), label=_('repeat Password'), widget=forms.PasswordInput(),
required=False, required=False,
help_text=_('insert the password twice to avoid typos. If you left this field empty your password \ help_text=_('insert the password twice to avoid typos. If you left \
will be unchanged.'),) this field empty your password will be unchanged.'),)
dynamicDNS_IPURL = TrimmedCharField( dynamicDNS_IPURL = TrimmedCharField(
label=_('IP check URL'), label=_('IP check URL'),
required=False, required=False,
help_text=_('Optional Value. If your FreedomBox is not connected directly to the Internet (i.e. \ help_text=_('Optional Value. If your FreedomBox is not connected \
connected to a NAT router) this URL is used to figure out the real Internet IP. The URL should \ directly to the Internet (i.e. connected to a NAT \
simply return the IP where the client comes from. Example: http://myip.datasystems24.de'), router) this URL is used to figure out the real Internet \
IP. The URL should simply return the IP where the \
client comes from. Example: \
http://myip.datasystems24.de'),
validators=[ validators=[
validators.URLValidator(schemes=['http', 'https', 'ftp'])]) validators.URLValidator(schemes=['http', 'https', 'ftp'])])
@login_required @login_required
def configure(request): def configure(request):
"""Serve the configuration form""" """Serve the configuration form"""
@ -131,6 +142,7 @@ def configure(request):
'form': form, 'form': form,
'subsubmenu': subsubmenu}) 'subsubmenu': subsubmenu})
@login_required @login_required
def statuspage(request): def statuspage(request):
"""Serve the status page """ """Serve the status page """
@ -155,6 +167,7 @@ def statuspage(request):
'last_update': last_update, 'last_update': last_update,
'subsubmenu': subsubmenu}) 'subsubmenu': subsubmenu})
def get_status(): def get_status():
"""Return the current status""" """Return the current status"""
"""ToDo: use key/value instead of hard coded value list""" """ToDo: use key/value instead of hard coded value list"""
@ -189,17 +202,21 @@ def get_status():
return status return status
def _apply_changes(request, old_status, new_status): def _apply_changes(request, old_status, new_status):
"""Apply the changes to Dynamic DNS client""" """Apply the changes to Dynamic DNS client"""
LOGGER.info('New status is - %s', new_status) LOGGER.info('New status is - %s', new_status)
LOGGER.info('Old status was - %s', old_status) LOGGER.info('Old status was - %s', old_status)
FAIL = False FAIL = False
if new_status['dynamicDNS_Secret_repeat'] != new_status['dynamicDNS_Secret']: if new_status['dynamicDNS_Secret_repeat'] != \
new_status['dynamicDNS_Secret']:
messages.error(request, _('passwords does not match')) messages.error(request, _('passwords does not match'))
FAIL = True FAIL = True
if old_status['dynamicDNS_Secret'] == '' and new_status['dynamicDNS_Secret'] == '': if old_status['dynamicDNS_Secret'] == '' and \
new_status['dynamicDNS_Secret'] == '':
messages.error(request, _('please give a password')) messages.error(request, _('please give a password'))
FAIL = True FAIL = True
@ -210,11 +227,16 @@ def _apply_changes(request, old_status, new_status):
if new_status['dynamicDNS_IPURL'] == '': if new_status['dynamicDNS_IPURL'] == '':
new_status['dynamicDNS_IPURL'] = 'none' new_status['dynamicDNS_IPURL'] = 'none'
if old_status['dynamicDNS_Server'] != new_status['dynamicDNS_Server'] or \ if old_status['dynamicDNS_Server'] != \
old_status['dynamicDNS_Domain'] != new_status['dynamicDNS_Domain'] or \ new_status['dynamicDNS_Server'] or \
old_status['dynamicDNS_User'] != new_status['dynamicDNS_User'] or \ old_status['dynamicDNS_Domain'] != \
old_status['dynamicDNS_Secret'] != new_status['dynamicDNS_Secret'] or \ new_status['dynamicDNS_Domain'] or \
old_status['dynamicDNS_IPURL'] != new_status['dynamicDNS_IPURL']: old_status['dynamicDNS_User'] != \
new_status['dynamicDNS_User'] or \
old_status['dynamicDNS_Secret'] != \
new_status['dynamicDNS_Secret'] or \
old_status['dynamicDNS_IPURL'] != \
new_status['dynamicDNS_IPURL']:
_run(['configure', '-s', new_status['dynamicDNS_Server'], _run(['configure', '-s', new_status['dynamicDNS_Server'],
'-d', new_status['dynamicDNS_Domain'], '-d', new_status['dynamicDNS_Domain'],
@ -223,7 +245,8 @@ def _apply_changes(request, old_status, new_status):
'-I', new_status['dynamicDNS_IPURL']]) '-I', new_status['dynamicDNS_IPURL']])
_run(['stop']) _run(['stop'])
_run(['start']) _run(['start'])
messages.success(request, _('Dynamic DNS configuration is updated!')) messages.success(request, \
_('Dynamic DNS configuration is updated!'))
if old_status['enabled'] != new_status['enabled']: if old_status['enabled'] != new_status['enabled']:
if new_status['enabled']: if new_status['enabled']:
@ -233,7 +256,9 @@ def _apply_changes(request, old_status, new_status):
_run(['stop']) _run(['stop'])
messages.success(request, _('Dynamic DNS is disabled now!')) messages.success(request, _('Dynamic DNS is disabled now!'))
else: else:
messages.error(request, _('At least on failure occured, please check your input.')) messages.error(request, \
_('At least on failure occured, please check your input.'))
def _run(arguments, superuser=False): def _run(arguments, superuser=False):
"""Run a given command and raise exception if there was an error""" """Run a given command and raise exception if there was an error"""