the files of the settings panel of Mellanox dashboard

this commit contains of the settings panel, that is responsible for configuring the settings
of Mellanox products.

this commit also contains pep8 fixes

Change-Id: Ia2803e78e5138efd7fc3f5102360faab361d67c3
This commit is contained in:
Murad Awawdeh 2016-05-03 14:26:06 +03:00
parent fbdbc15460
commit 201ce8d351
8 changed files with 252 additions and 2 deletions

View File

@ -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

View File

@ -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)

View File

@ -0,0 +1,4 @@
{% extends "horizon/common/_modal_form.html" %}
{% load i18n %}

View File

@ -0,0 +1,94 @@
{% extends 'base.html' %}
{% load i18n %}
{% load static %}
{% block title %}{% trans "Mellanox Settings" %}{% endblock %}
{% block main %}
<style>
#content_body .container-fluid .row .col-xs-12 .page-header{
display: none !important;
}
.modal-header{
display: none;
}
.static_page{
float: none;
width: 600px;
}
.form-group{
float: left;
width: 220px;
margin-right: 60px;
}
label[for^="id_n_a_"]{
visibility: hidden;
}
#id_n_a_{
visibility: hidden;
}
.col-sm-6{
width: 100%;
}
.product_header_neo{
background-color:#428BCA;
width:250px;
padding:7px;
margin-top:30px;
float: left;
height: 50px;
margin-right: 30px;
}
.product_header_ufm{
background-color:#428BCA;
width:250px;
margin-top:30px;
float: left;
height: 50px;
}
.ufm_lable{
color: #fff;
font-size: 27px;
font-style: italic;
font-weight: normal;
margin: 5px;
}
</style>
<div class="product_header_neo">
<img height=32 src="{% static 'horizon_mellanox/images/neo_logo_trans.png' %}">
</div>
<div class="product_header_ufm">
<label class="ufm_lable">UFM</label>
</div>
<div style="clear:both;height:0px;"></div>
{% include "horizon_mellanox/settingspanel/_change.html" %}
<script src="https://code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$( document ).ready(function() {
horizon.horizon_mellanox.prepareSettingsPanel();
});
</script>
{% endblock %}

View File

@ -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'))

View File

@ -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'

View File

@ -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]