-
Notifications
You must be signed in to change notification settings - Fork 3
/
auth.py
78 lines (57 loc) · 2.56 KB
/
auth.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
from flask_admin.contrib.sqla.view import ModelView, func
from flask_admin import AdminIndexView, expose
from flask import redirect, url_for, request, session
from utils import session_secret
from models import QA, Likes
class AnoMeAdminIndexView(AdminIndexView):
@expose()
def index(self):
public_count = QA.query.filter(QA.answer != None).filter(QA.is_public == True).count()
private_count = QA.query.filter(QA.answer != None).filter(QA.is_public == False).count()
empty_count = QA.query.filter(QA.answer == None).count()
self._template_args["public_count"] = public_count
self._template_args["private_count"] = private_count
self._template_args["empty_count"] = empty_count
return super(AnoMeAdminIndexView, self).index()
def is_visible(self):
return False
def is_accessible(self):
return session.get("admin", "") == session_secret["admin"]
def inaccessible_callback(self, name, **kwargs):
return redirect(url_for("login", next=request.full_path))
class AnoMeView(ModelView):
def is_accessible(self):
return session.get("admin", "") == session_secret["admin"]
def inaccessible_callback(self, name, **kwargs):
return redirect(url_for("login", next=request.full_path))
class AnoMeAllQaView(AnoMeView):
column_searchable_list = ("question", "answer", "secret")
column_filters = ("question", "answer", "secret")
form_widget_args = {
"question": {
"rows": 3
},
"answer": {
"rows": 10
},
"secret": {
"readonly": True
},
}
class AnoMeEmptyQaView(AnoMeAllQaView):
def get_query(self):
return self.session.query(self.model).filter(self.model.answer == None)
def get_count_query(self):
return self.session.query(func.count("*")).filter(self.model.answer == None)
class AnoMePublicQaView(AnoMeAllQaView):
def get_query(self):
return self.session.query(self.model).filter(self.model.answer != None).filter(self.model.is_public == True)
def get_count_query(self):
return self.session.query(func.count("*")).filter(self.model.answer != None).filter(
self.model.is_public == True)
class AnoMePrivateQaView(AnoMeAllQaView):
def get_query(self):
return self.session.query(self.model).filter(self.model.answer != None).filter(self.model.is_public == False)
def get_count_query(self):
return self.session.query(func.count("*")).filter(self.model.answer != None).filter(
self.model.is_public == False)