Skip to content

Commit c603ff5

Browse files
committed
fixed the user input issue
1 parent bce4cbe commit c603ff5

File tree

9 files changed

+51
-14
lines changed

9 files changed

+51
-14
lines changed

.gitignore

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
node_modules/
1+
node_modules/
674 Bytes
Binary file not shown.

app.py

Lines changed: 14 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,9 +36,10 @@ def savehome():
3636
saved_text = request.form['hometext']
3737
# sanitized_text = saved_text.replace('','\n')
3838
# overwrite_file(str(SELECTED_COMP)+'/Home.md',saved_text)
39+
sanitized_text = saved_text.replace('\r\n', '\n').replace('\r', '\n') # Replace different newline formats
3940
print(saved_text)
4041
print(saved_text.count('\n'))
41-
overwrite_file(os.path.join('competitions',str(SELECTED_COMP),'Home.md'),saved_text)
42+
overwrite_file(os.path.join('competitions',str(SELECTED_COMP),'Home.md'),sanitized_text)
4243
return redirect(url_for('edithome'))
4344

4445
@app.route("/selectcomp", methods=('GET', 'POST'))
@@ -90,5 +91,17 @@ def get_home():
9091
return extract_text('competitions/'+str(SELECTED_COMP),'Home.md')
9192
return dict(get_home=get_home)
9293

94+
@app.context_processor
95+
def utility_processor():
96+
def get_all_environments():
97+
return get_all_environments()
98+
return dict(get_all_environments=get_all_environments)
99+
100+
@app.context_processor
101+
def utility_processor():
102+
def get_environments():
103+
return get_environments(SELECTED_COMP)
104+
return dict(get_environments=get_environments)
105+
93106
if __name__ == '__main__':
94107
app.run(debug=True)

app_utilities.py

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import os
22
import ruamel.yaml
3+
import json
34

45
# Creates a folder anywhere in the chalgen-online folder, paths deeper must be specified
56
def create_folder(name):
@@ -85,4 +86,26 @@ def overwrite_file(dir,text):
8586
pass
8687
create_file(os.path.join(current_directory,dir),text)
8788

89+
def get_all_environments():
90+
with open(os.path.join(os.getcwd(),'usable_chals.json'),'r') as file:
91+
data = json.load(file)
92+
return data['environments']
93+
94+
def get_environments(comp_name):
95+
directory = os.path.join(os.getcwd(),'competitions',comp_name,'chals')
96+
97+
all_environments = get_all_environments()
98+
99+
all_folders = [item for item in os.listdir(directory) if os.path.isdir(os.path.join(directory, item))]
100+
101+
existing_environments = []
102+
103+
for folder in all_folders:
104+
if folder in all_environments:
105+
existing_environments.append(folder)
106+
107+
return existing_environments
108+
109+
print(get_environments('mcpshsf2024'))
110+
88111
# print(extract_text('competitions'+'/KhetarKoinCompetition','Home.md'))
Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,3 @@
1-
hi
2-
3-
4-
5-
6-
7-
8-
9-
hi
1+
test
2+
3+
sfsef

competitions/mcpshsf2024/chals/CaesarCipher/chal.yaml

Whitespace-only changes.

competitions/mcpshsf2024/chals/Fesbuc/chal.yaml

Whitespace-only changes.

templates/sidebar.html

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -149,6 +149,7 @@ <h1 class="pt-2">Selected Comp: {{ get_selected_comp() }}</h1>
149149
<option value="Fesbuc">Fesbuc</option>
150150
<option value="Tweepy">Tweepy</option>
151151
<option value="Fileserver">File Server</option>
152+
<!-- TODO: make it so that all addable envs are read from the json and are added here -->
152153
</select>
153154
<div class="relative">
154155
<button type="submit"

usable_chals.json

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,13 @@
11
{
2-
"environments": ["Fesbuc","Tweepy","File Share"],
2+
"environments": [
3+
"Fesbuc",
4+
"Tweepy",
5+
"FileShare"
6+
],
37
"challenges": [
4-
"test1",
5-
"test2"
8+
"CaesarCipher",
9+
"Base64",
10+
"VigenereCipher",
11+
"DocxCarving"
612
]
713
}

0 commit comments

Comments
 (0)