Repository URL to install this package:
Version:
4.2.64.2 ▾
|
python3-tvault-horizon-plugin
/
usr
/
lib
/
python3
/
dist-packages
/
dashboards
/
settings
/
workflows.py
|
---|
# Copyright (c) 2014 TrilioData, Inc.
# All Rights Reserved.
import logging
import netaddr
from datetime import date, timedelta, datetime, time
try:
from django.core.urlresolvers import reverse
except ImportError:
from django.urls import reverse
from django.utils.translation import ugettext_lazy as _
from django.core.exceptions import ValidationError
from horizon import exceptions
from horizon import forms
from horizon import messages
from horizon import workflows
try:
from horizon.utils import fields
except Exception as ex:
from horizon.forms import fields
pass
from openstack_dashboard import api
from dashboards import workloadmgr
from openstack_dashboard.api import nova
from openstack_dashboard.usage import quotas
LOG = logging.getLogger(__name__)
INDEX_URL = "horizon:project:settings:index"
class SetEmailAction(workflows.Action):
cleaned_data = []
smtp_email_enable = forms.BooleanField(label=_("Enable Email Alerts"),
required=False,
widget=forms.CheckboxInput(
attrs={
}),
initial=False)
"""receive_options = ((0, "daily"), (1, "weekly"), (2,"fortnight"))
receive_duration = forms.ChoiceField(label=_("Report receiving duration"),
initial = 0,
choices = receive_options,)"""
class Meta:
name = _(" ")
help_text_template = ("project/settings/"
"_email_settings_help.html")
def __init__(self, request, *args, **kwargs):
super(SetEmailAction, self).__init__(request,
*args, **kwargs)
configured = True
settings = workloadmgr.settings_list(request, get_hidden=True, get_smtp_settings=True)
for key in settings[1]['settings']:
if key == 'smtp_server_name' and str(settings[1]['settings'][key]).strip() == "":
configured = False
#user = api.keystone.user_get(request, request.user.id, admin=False)
user = workloadmgr.setting_get(request, 'user_email_address_'+request.user.id)
if user['email'] is None or str(user['email']).strip() == "":
try:
self.add_error("You can't enable email alerts as your account not linked with email address")
except Exception as ex:
self.add_error(None, "You can't enable email alerts as your account not linked with email address")
pass
self.fields['smtp_email_enable'].widget.attrs = {'disabled':'True'}
if configured is False:
try:
self.add_error("You can't enable email alerts as SMTP server not configured")
except Exception as ex:
self.add_error(None, "You can't enable email alerts as SMTP server not configured")
pass
self.fields['smtp_email_enable'].widget.attrs = {'disabled':'True'}
settings = workloadmgr.settings_list(request, get_hidden=False)
for key in settings[1]['settings']:
if key in self.fields:
value = settings[1]['settings'][key]
if key == 'smtp_email_enable':
if value == 'no':
value = False
value = bool(int(value))
self.fields[key].initial = value
def clean(self):
cleaned_data = super(SetEmailAction, self).clean()
return cleaned_data
class SetEmail(workflows.Step):
action_class = SetEmailAction
def contribute(self, data, context):
if data:
context = data
return context
class IndexSettings(workflows.Workflow):
slug = "index_settings"
name = _("Email Alerts Settings")
finalize_button_name = _("Change")
success_message = _('Changed Settings')
default_steps = (SetEmail,)
failure_message = _('Unable to change settings')
def get_success_url(self):
return reverse("horizon:project:settings:index")
def get_failure_url(self):
return reverse("horizon:project:settings:index")
def handle(self, request, data):
try:
workloadmgr.settings_create(request, context = data)
return True
except Exception as ex:
messages.error(request, str(ex))
return False