Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
Hodor Web Applicaton
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
Model registry
Operate
Environments
Monitor
Incidents
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Vasanth Viswanath S
Hodor Web Applicaton
Commits
8e08619d
Commit
8e08619d
authored
7 years ago
by
Vasanth Viswanath S
Browse files
Options
Downloads
Patches
Plain Diff
Add challenges module controllers
parent
8754f570
No related branches found
No related tags found
No related merge requests found
Changes
2
Show whitespace changes
Inline
Side-by-side
Showing
2 changed files
hodor/controllers/challenges.py
+12
-11
12 additions, 11 deletions
hodor/controllers/challenges.py
hodor/models/challenges.py
+1
-1
1 addition, 1 deletion
hodor/models/challenges.py
with
13 additions
and
12 deletions
hodor/controllers/challenges.py
+
12
−
11
View file @
8e08619d
...
...
@@ -16,7 +16,7 @@ def add_new_chall():
if
request
.
method
==
"
POST
"
:
try
:
newchall
[
'
c
hall_
id
'
]
=
request
.
data
.
get
(
'
c
hall_
id
'
).
strip
()
newchall
[
'
cid
'
]
=
request
.
data
.
get
(
'
cid
'
).
strip
()
newchall
[
'
name
'
]
=
str
(
request
.
data
.
get
(
'
name
'
).
strip
())
newchall
[
'
points
'
]
=
request
.
data
.
get
(
'
points
'
).
strip
()
newchall
[
'
description
'
]
=
str
(
request
.
data
.
get
(
'
description
'
).
strip
())
...
...
@@ -26,23 +26,23 @@ def add_new_chall():
abort
(
500
)
chall
=
Challenges
(
**
newchall
)
chall
.
save
()
return
make_response
(
jsonify
(
status
=
201
,
msg
=
"
Challenge {} successfully added
"
.
format
(
chall
.
c
hall_
id
)
+
return
make_response
(
jsonify
(
status
=
201
,
msg
=
"
Challenge {} successfully added
"
.
format
(
chall
.
cid
)
+
"
to database
"
),
201
)
###########################
# Edit an existing challenge
###########################
@app.route
(
'
/challenges/edit
'
,
methods
=
[
'
PUT
'
])
def
edit_chall
():
@app.route
(
'
/challenges/edit
/<id_slug>
'
,
methods
=
[
'
PUT
'
])
def
edit_chall
(
id_slug
):
"""
This function enables to edit existing challenges
:return: Response Code
"""
chall_id
=
request
.
data
.
get
(
'
chall_id
'
).
strip
()
get_id
=
Challenges
.
query
.
get
(
chall_id
)
chall
=
{}
check_id
=
id_slug
.
strip
()
get_id
=
Challenges
.
query
.
filter_by
(
cid
=
check_id
)
if
(
get_id
):
try
:
get_id
.
cid
=
check_id
get_id
.
name
=
str
(
request
.
data
.
get
(
'
name
'
).
strip
())
get_id
.
points
=
str
(
request
.
data
.
get
(
'
points
'
).
strip
())
get_id
.
description
=
str
(
request
.
data
.
get
(
'
description
'
).
strip
())
...
...
@@ -51,7 +51,8 @@ def edit_chall():
print
(
e
)
abort
(
500
)
get_id
.
commit
()
return
make_response
(
jsonify
(
status
=
200
,
msg
=
"
Record succesfully edited
"
),
200
)
edited_data
=
_extract_required_fields
(
get_id
)
return
make_response
(
jsonify
(
status
=
200
,
data
=
edited_data
),
200
)
else
:
return
make_response
(
jsonify
(
status
=
404
,
msg
=
"
No such challenge ID found
"
),
404
)
...
...
@@ -65,9 +66,9 @@ def del_chall(id_slug):
:return: Response Code
"""
check_id
=
id_slug
.
strip
()
get_id
=
Challenges
.
query
.
filter_by
(
c
hall_
id
=
check_id
)
get_id
=
Challenges
.
query
.
filter_by
(
cid
=
check_id
)
if
get_id
:
Challenges
.
query
.
filter_by
(
c
hall_id
=
id_slug
).
delete
()
Challenges
.
query
.
filter_by
(
c
id
=
check_id
).
delete
()
return
make_response
(
jsonify
(
status
=
200
,
msg
=
"
Record succesfully deleted
"
),
200
)
else
:
return
make_response
(
jsonify
(
status
=
404
,
msg
=
"
No such challenge ID found
"
),
404
)
...
...
@@ -85,7 +86,7 @@ def _extract_required_fields(chall):
filter_chall
[
'
description
'
]
=
chall
.
description
filter_chall
[
'
points
'
]
=
chall
.
points
filter_chall
[
'
hints
'
]
=
chall
.
hints
filter_chall
[
'
c
hall_
id
'
]
=
chall
.
c
hall_
id
filter_chall
[
'
cid
'
]
=
chall
.
cid
return
filter_chall
...
...
This diff is collapsed.
Click to expand it.
hodor/models/challenges.py
+
1
−
1
View file @
8e08619d
...
...
@@ -7,7 +7,7 @@ class Challenges(db.Model):
__tablename__
=
'
challenges
'
# Data variables for each challenge
c
hall_
id
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
unique
=
True
,
nullable
=
False
)
cid
=
db
.
Column
(
db
.
Integer
,
primary_key
=
True
,
unique
=
True
,
nullable
=
False
)
name
=
db
.
Column
(
db
.
String
(
32
),
nullable
=
False
)
points
=
db
.
Column
(
db
.
Integer
,
nullable
=
False
)
description
=
db
.
Column
(
db
.
String
(
2048
),
nullable
=
False
)
...
...
This diff is collapsed.
Click to expand it.
Preview
0%
Loading
Try again
or
attach a new file
.
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Save comment
Cancel
Please
register
or
sign in
to comment