This repository has been archived by the owner on Apr 3, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathadmin_views.py
125 lines (103 loc) · 3.68 KB
/
admin_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
import os
from flask import render_template, request, current_app as app
from CTFd.utils.decorators import admins_only, is_admin
from CTFd.models import db, Teams
from .db_tables import Attributes, AttributesSelectOptions, IntersectionTeamAttr
supported_input_types = {
"Checkbox":"checkbox",
"Text":"text",
"Secret": "password",
"Text Area": "textarea",
"Number": "number",
"Select": "select"
}
# set views
@app.route('/admin/attributes', methods=['GET'])
@admins_only
def view_attributes():
page = abs(request.args.get("page", 1, type=int))
page = abs(int(page))
results_per_page = 50
page_start = results_per_page * (page - 1)
page_end = results_per_page * (page - 1) + results_per_page
attributes = Attributes.query.order_by(Attributes.id.asc()).all()
count = db.session.query(db.func.count(Attributes.id)).first()[0]
pages = int(count / results_per_page) + (count % results_per_page > 0)
return render_template(
"view_attributes.html",
attributes = attributes,
curr_page = page,
pages = pages,
types = supported_input_types
)
@app.route('/admin/attributes/new', methods=['GET'])
@admins_only
def create_attribute():
return render_template(
'create_attribute.html',
types = supported_input_types
)
@app.route('/admin/attributes/<int:attribute_id>', methods=['GET'])
@admins_only
def attribute_details(attribute_id):
attribute = Attributes.query.filter_by(id=attribute_id).first_or_404()
teams = IntersectionTeamAttr.query.filter_by(attr_id=attribute_id).all()
teams_list = Teams.query.all()
return render_template(
'attribute_details.html',
attribute = attribute,
teams = teams,
teams_list = teams_list,
types = supported_input_types
)
@app.route('/admin/attributes/<int:attribute_id>/<int:team_id>', methods=['GET'])
@admins_only
def set_team_attribute(attribute_id, team_id):
attribute = Attributes.query.filter_by(id=attribute_id).first_or_404()
team = IntersectionTeamAttr.query.filter_by(attr_id=attribute_id).filter_by(team_id=team_id).first_or_404()
return render_template(
'set_team_attribute.html',
attribute = attribute,
team = team,
types = supported_input_types
)
@app.route('/admin/attributes/<int:attribute_id>/options', methods=['GET'])
@admins_only
def view_attribute_options(attribute_id):
page = abs(request.args.get("page", 1, type=int))
page = abs(int(page))
results_per_page = 50
page_start = results_per_page * (page - 1)
page_end = results_per_page * (page - 1) + results_per_page
attribute = Attributes.query.filter_by(id=attribute_id).first_or_404()
options = AttributesSelectOptions.query.filter_by(attr_id=attribute_id).all()
count = options.count(options)
pages = int(count / results_per_page) + (count % results_per_page > 0)
return render_template(
'view_attribute_select_options.html',
attribute = attribute,
options = options,
curr_page = page,
pages = pages,
types = supported_input_types
)
@app.route('/admin/attributes/<int:attribute_id>/options/new', methods=['GET'])
@admins_only
def create_attribute_options(attribute_id):
attribute = Attributes.query.filter_by(id=attribute_id).first_or_404()
return render_template(
'create_attribute_select_option.html',
attribute = attribute,
types = supported_input_types
)
@app.route('/admin/attributes/<int:attribute_id>/options/<int:option_id>', methods=['GET'])
@admins_only
def edit_attribute_options(attribute_id, option_id):
attribute = Attributes.query.filter_by(id=attribute_id).first_or_404()
option = AttributesSelectOptions.query.filter_by(attr_id=attribute_id).filter_by(id=option_id).first_or_404()
return render_template(
'edit_attribute_select_option.html',
attribute = attribute,
selectOption = option,
types = supported_input_types
)