File: views.py

package info (click to toggle)
mistral-dashboard 20.0.0-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 848 kB
  • sloc: python: 3,383; sh: 376; makefile: 27
file content (79 lines) | stat: -rw-r--r-- 2,708 bytes parent folder | download | duplicates (2)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
# Copyright 2016 - Nokia.
#
# 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.urls import reverse
from django.urls import reverse_lazy

from django.utils.translation import gettext_lazy as _
from django.views import generic

from horizon import forms
from horizon import tables

from mistraldashboard import api
from mistraldashboard.cron_triggers import forms as mistral_forms
from mistraldashboard.cron_triggers import tables as mistral_tables


class OverviewView(generic.TemplateView):
    template_name = 'mistral/cron_triggers/detail.html'
    page_title = _("Cron Trigger Details")
    workflow_url = 'horizon:mistral:workflows:detail'
    list_url = 'horizon:mistral:cron_triggers:index'

    def get_context_data(self, **kwargs):
        context = super(OverviewView, self).get_context_data(**kwargs)
        cron_trigger = {}
        cron_trigger = api.cron_trigger_get(
            self.request,
            kwargs['cron_trigger_name']
        )
        cron_trigger.workflow_url = reverse(
            self.workflow_url,
            args=[cron_trigger.workflow_name]
        )
        cron_trigger.list_url = reverse_lazy(self.list_url)
        breadcrumb = [(cron_trigger.name, reverse(
            'horizon:mistral:cron_triggers:detail',
            args=[cron_trigger.name]
        ))]

        context["custom_breadcrumb"] = breadcrumb
        context['cron_trigger'] = cron_trigger

        return context


class CreateView(forms.ModalFormView):
    template_name = 'mistral/cron_triggers/create.html'
    modal_header = _("Create Cron Trigger")
    form_id = "create_cron_trigger"
    form_class = mistral_forms.CreateForm
    submit_label = _("Create Cron Trigger")
    submit_url = reverse_lazy("horizon:mistral:cron_triggers:create")
    success_url = reverse_lazy('horizon:mistral:cron_triggers:index')
    page_title = _("Create Cron Trigger")

    def get_form_kwargs(self):
        kwargs = super(CreateView, self).get_form_kwargs()

        return kwargs


class IndexView(tables.DataTableView):
    table_class = mistral_tables.CronTriggersTable
    template_name = 'mistral/cron_triggers/index.html'

    def get_data(self):
        return api.cron_trigger_list(self.request)