diff --git a/horizon_mellanox/settingspanel/__init__.py b/horizon_mellanox/settingspanel/__init__.py new file mode 100644 index 0000000..e69de29 diff --git a/horizon_mellanox/settingspanel/forms.py b/horizon_mellanox/settingspanel/forms.py new file mode 100644 index 0000000..14e4a6c --- /dev/null +++ b/horizon_mellanox/settingspanel/forms.py @@ -0,0 +1,64 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mellanox Technologies, Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from datetime import datetime +from datetime import timedelta + +from django.forms import ValidationError # noqa +from django import shortcuts +from django.utils.translation import ugettext_lazy as _ +from django.views.decorators.debug import sensitive_variables # noqa + +from horizon import forms + + +def _one_year(): + now = datetime.utcnow() + return now + timedelta(days=365) + + +class SettingsForm(forms.SelfHandlingForm): + neo_host = forms.CharField(label=_('NEO Server'), required=False) + ufm_host = forms.CharField(label=_('UFM Server'), required=False) + neo_host_user = forms.CharField(label=_('NEO Username'), required=False) + n_a_ = forms.CharField(label=_('a'), required=False) + neo_host_password = forms.CharField(label=_('NEO Password'), + required=False, + widget=forms.PasswordInput( + render_value=False)) + no_autocomplete = False + + def handle(self, request, data): + response = shortcuts.redirect(request.build_absolute_uri()) + request.session['mellanox_neo_host'] = data['neo_host'] + response.set_cookie('mellanox_neo_host', data['neo_host'], + expires=_one_year()) + + request.session['mellanox_neo_host_user'] = data['neo_host_user'] + response.set_cookie('mellanox_neo_host_user', data['neo_host_user'], + expires=_one_year()) + + request.session['mellanox_neo_host_password'] = \ + data['neo_host_password'] + response.set_cookie('mellanox_neo_host_password', + data['neo_host_password'], + expires=_one_year()) + + request.session['mellanox_ufm_host'] = data['ufm_host'] + response.set_cookie('mellanox_ufm_host', data['ufm_host'], + expires=_one_year()) + + return response diff --git a/horizon_mellanox/settingspanel/panel.py b/horizon_mellanox/settingspanel/panel.py new file mode 100644 index 0000000..7c1031d --- /dev/null +++ b/horizon_mellanox/settingspanel/panel.py @@ -0,0 +1,28 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mellanox Technologies, Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.utils.translation import ugettext_lazy as _ + +import horizon + +from horizon_mellanox import dashboard + + +class SettingsPanel(horizon.Panel): + name = _("Settings") + slug = 'settingspanel' + +dashboard.MlnxDashboard.register(SettingsPanel) diff --git a/horizon_mellanox/settingspanel/templates/settingspanel/_change.html b/horizon_mellanox/settingspanel/templates/settingspanel/_change.html new file mode 100644 index 0000000..a65ba92 --- /dev/null +++ b/horizon_mellanox/settingspanel/templates/settingspanel/_change.html @@ -0,0 +1,4 @@ +{% extends "horizon/common/_modal_form.html" %} +{% load i18n %} + + diff --git a/horizon_mellanox/settingspanel/templates/settingspanel/change.html b/horizon_mellanox/settingspanel/templates/settingspanel/change.html new file mode 100644 index 0000000..9bae91b --- /dev/null +++ b/horizon_mellanox/settingspanel/templates/settingspanel/change.html @@ -0,0 +1,94 @@ +{% extends 'base.html' %} +{% load i18n %} +{% load static %} +{% block title %}{% trans "Mellanox Settings" %}{% endblock %} + +{% block main %} + + + + + + + + +
+ +
+
+ +
+
+ + + + + {% include "horizon_mellanox/settingspanel/_change.html" %} + + + + +{% endblock %} diff --git a/horizon_mellanox/settingspanel/urls.py b/horizon_mellanox/settingspanel/urls.py new file mode 100644 index 0000000..8ba455b --- /dev/null +++ b/horizon_mellanox/settingspanel/urls.py @@ -0,0 +1,26 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mellanox Technologies, Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.conf.urls import patterns +from django.conf.urls import url + + +from horizon_mellanox.settingspanel import views + + +urlpatterns = patterns( + '', + url(r'^$', views.SettingsView.as_view(), name='index')) diff --git a/horizon_mellanox/settingspanel/views.py b/horizon_mellanox/settingspanel/views.py new file mode 100644 index 0000000..97fbbe9 --- /dev/null +++ b/horizon_mellanox/settingspanel/views.py @@ -0,0 +1,34 @@ +# -*- coding: utf-8 -*- + +# Copyright 2016 Mellanox Technologies, Ltd +# +# Licensed under the Apache License, Version 2.0 (the "License"); you may +# not use this file except in compliance with the License. You may obtain +# a copy of the License at +# +# http://www.apache.org/licenses/LICENSE-2.0 +# +# Unless required by applicable law or agreed to in writing, software +# distributed under the License is distributed on an "AS IS" BASIS, WITHOUT +# WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the +# License for the specific language governing permissions and limitations +# under the License. + +from django.core.urlresolvers import reverse_lazy +from django.utils.translation import ugettext_lazy as _ + +from horizon import forms + +from horizon_mellanox.settingspanel \ + import forms as settings_forms + + +class SettingsView(forms.ModalFormView): + form_class = settings_forms.SettingsForm + form_id = "change_settings_modal_form" + modal_header = "" + modal_id = "change_settings_modal" + page_title = _("Settings") + submit_label = _("Save") + submit_url = reverse_lazy("horizon:horizon_mellanox:settingspanel:index") + template_name = 'horizon_mellanox/settingspanel/change.html' diff --git a/tox.ini b/tox.ini index d4cd6e3..42646f6 100644 --- a/tox.ini +++ b/tox.ini @@ -1,6 +1,6 @@ [tox] -minversion = 2.0 -envlist = py34-constraints,py27-constraints,pypy-constraints,pep8-constraints +minversion = 1.6 +envlist = py27,py33,py34,pep8 skipsdist = True [testenv]