-
Notifications
You must be signed in to change notification settings - Fork 27
/
Copy pathviews.py
162 lines (127 loc) · 5.52 KB
/
views.py
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
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
import flask_login as login
import flask_admin as admin
from flask_admin import helpers, expose
from flask import redirect, url_for, request, render_template
from loginform import LoginForm
import stub as stub
# Create customized index view class that handles login & registration
class AdminIndexView(admin.AdminIndexView):
def _stubs(self):
self.nav = {
"tasks" : stub.get_tasks(),
"messages" : stub.get_messages_summary(),
"alerts" : stub.get_alerts()
}
(cols, rows) = stub.get_adv_tables()
(scols, srows, context) = stub.get_tables()
self.tables = {
"advtables" : { "columns" : cols, "rows" : rows },
"table" : { "columns" : scols, "rows" : srows, "context" : context}
}
self.panelswells = {
"accordion" : stub.get_accordion_items(),
"tabitems" : stub.get_tab_items()
}
@expose('/')
def index(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Dashboard"
return render_template('sb-admin/pages/dashboard.html', admin_view=self)
@expose('/blank')
def blank(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Blank"
return render_template('sb-admin/pages/blank.html', admin_view=self)
@expose('/flot')
def flot(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Flot Charts"
return render_template('sb-admin/pages/flot.html', admin_view=self)
@expose('/morris')
def morris(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Morris Charts"
return render_template('sb-admin/pages/morris.html', admin_view=self)
@expose('/tables')
def tables(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Tables"
return render_template('sb-admin/pages/tables.html', admin_view=self)
@expose('/forms')
def forms(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Forms"
return render_template('sb-admin/pages/forms.html', admin_view=self)
@expose('/ui/panelswells')
def panelswells(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Panels Wells"
return render_template('sb-admin/pages/ui/panels-wells.html', admin_view=self)
@expose('/ui/buttons')
def buttons(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Buttons"
return render_template('sb-admin/pages/ui/buttons.html', admin_view=self)
@expose('/ui/notifications')
def notifications(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Notifications"
return render_template('sb-admin/pages/ui/notifications.html', admin_view=self)
@expose('/ui/typography')
def typography(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Typography"
return render_template('sb-admin/pages/ui/typography.html', admin_view=self)
@expose('/ui/icons')
def icons(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Icons"
return render_template('sb-admin/pages/ui/icons.html', admin_view=self)
@expose('/ui/grid')
def grid(self):
if not login.current_user.is_authenticated:
return redirect(url_for('.login_view'))
self._stubs()
self.header = "Grid"
return render_template('sb-admin/pages/ui/grid.html', admin_view=self)
@expose('/login/', methods=('GET', 'POST'))
def login_view(self):
# handle user login
form = LoginForm(request.form)
if helpers.validate_form_on_submit(form):
user = form.get_user()
login.login_user(user)
if login.current_user.is_authenticated:
return redirect(url_for('.index'))
self._template_args['form'] = form
return render_template('sb-admin/pages/login.html', form=form)
@expose('/logout/')
def logout_view(self):
login.logout_user()
return redirect(url_for('.index'))
class BlankView(admin.BaseView):
@expose('/')
def index(self):
return render_template('sb-admin/pages/blank.html', admin_view=self)