From 9104997e090d305909d139305be94c2736f90b9d Mon Sep 17 00:00:00 2001
From: Navan Chauhan <navanchauhan@gmail.com>
Date: Fri, 4 Jun 2021 22:25:31 +0530
Subject: added admin view

---
 app/views/admin.py | 20 ++++++++++++++++++++
 app/views/main.py  |  2 +-
 2 files changed, 21 insertions(+), 1 deletion(-)
 create mode 100644 app/views/admin.py

(limited to 'app/views')

diff --git a/app/views/admin.py b/app/views/admin.py
new file mode 100644
index 0000000..b971a1a
--- /dev/null
+++ b/app/views/admin.py
@@ -0,0 +1,20 @@
+from app import app, login_manager, db
+from flask import render_template, flash,url_for, redirect
+import flask_login
+from app.models import User
+
+from flask_admin import Admin
+from flask_admin.contrib.sqla import ModelView
+
+admin = Admin(app, name="Admin", template_mode="bootstrap4")
+
+class ModelView(ModelView):
+    def is_accessible(self):
+        try:
+            if flask_login.current_user.get_role() == "SUPERUSER":
+                return True
+            return False
+        except AttributeError:
+            return False
+
+admin.add_view(ModelView(User, db.session))
\ No newline at end of file
diff --git a/app/views/main.py b/app/views/main.py
index 4814007..003a46f 100644
--- a/app/views/main.py
+++ b/app/views/main.py
@@ -1,7 +1,7 @@
 from app import app
 from app.forms.app_forms import MyForm
 from flask import render_template, flash
-from app.views import auth, error_pages
+from app.views import auth, error_pages, admin
 from app.misc_func import flash_errors
 theme = "original"
 
-- 
cgit v1.2.3