Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
B
Backend
Manage
Activity
Members
Code
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Locked files
Deploy
Releases
Package Registry
Model registry
Operate
Terraform modules
Analyze
Contributor 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
swp-unisport
team-warumkeinrust
Backend
Commits
59927cd3
Commit
59927cd3
authored
3 years ago
by
borzechof99
Browse files
Options
Downloads
Patches
Plain Diff
Sportlist and Single Sports in ViewSet
parent
42aae181
No related branches found
No related tags found
No related merge requests found
Changes
2
Hide whitespace changes
Inline
Side-by-side
Showing
2 changed files
unisportomat/quiz/views.py
+48
-66
48 additions, 66 deletions
unisportomat/quiz/views.py
unisportomat/unisportomat/urls.py
+0
-3
0 additions, 3 deletions
unisportomat/unisportomat/urls.py
with
48 additions
and
69 deletions
unisportomat/quiz/views.py
+
48
−
66
View file @
59927cd3
...
@@ -6,6 +6,7 @@ Defines the views for the API
...
@@ -6,6 +6,7 @@ Defines the views for the API
from
rest_framework
import
viewsets
from
rest_framework
import
viewsets
from
rest_framework.views
import
APIView
from
rest_framework.views
import
APIView
from
rest_framework.response
import
Response
from
rest_framework.response
import
Response
from
django.http
import
JsonResponse
from
.serializers
import
(
from
.serializers
import
(
SmallSportListSerializer
,
SmallSportListSerializer
,
SportListSerializer
,
SportListSerializer
,
...
@@ -57,49 +58,10 @@ class SmallSportListView(viewsets.ViewSet):
...
@@ -57,49 +58,10 @@ class SmallSportListView(viewsets.ViewSet):
TODO: More Documentation
TODO: More Documentation
"""
"""
# GET for api/admin/sport/
def
list
(
self
,
request
):
return
Response
({
"
test
"
:
"
Showing all Entries
"
})
# POST for api/admin/sport/
def
create
(
self
,
request
):
return
Response
({
"
test
"
:
"
Creating a new Entry
"
})
# GET for api/admin/sport/<id>/
def
retrieve
(
self
,
request
,
pk
=
None
):
return
Response
({
"
test
"
:
"
Getting a Single Entry
"
})
# PUT for api/admin/sport/<id>/
def
update
(
self
,
request
,
pk
=
None
):
return
Response
({
"
test
"
:
"
Updating a Single Entry
"
})
# DELETE for api/admin/sport/<id>/
def
destroy
(
self
,
request
,
pk
=
None
):
return
Response
({
"
test
"
:
"
Removing a Single Entry
"
})
# Dev Notes:
# - This is a singular APIView which isn't meant to expose complete lists
# - It cannot be written into the Router, as it isn't a Viewset, so it is written directly into the urls.py's urlspatterns like this:
# path(r"api/admin/single-small-sport-list", views.SmallSportListAPIView.as_view())
# - The API isn't in the list in /api/admin because of that, but needs to be called manually here:
# http://localhost:8000/api/admin/single-small-sport-list
class
SmallSportListAPIView
(
APIView
):
"""
View for the List of Sports on the Sport Homepage
TODO: More Documentation
"""
authentication_classes
=
[]
authentication_classes
=
[]
def
get
(
self
,
request
):
# GET for api/admin/sport/
def
list
(
self
,
request
):
sports
=
Sport
.
objects
.
all
()
sports
=
Sport
.
objects
.
all
()
criteria
=
Criterion
.
objects
.
all
()
criteria
=
Criterion
.
objects
.
all
()
...
@@ -128,31 +90,8 @@ class SmallSportListAPIView(APIView):
...
@@ -128,31 +90,8 @@ class SmallSportListAPIView(APIView):
return
Response
(
serializer
.
data
)
return
Response
(
serializer
.
data
)
# POST for api/admin/sport/
class
SingleSportAPIView
(
APIView
):
def
create
(
self
,
request
):
authentication_classes
=
[]
def
get
(
self
,
request
,
pk
):
return
Response
(
SingleSportSerializer
(
Sport
.
objects
.
get
(
pk
=
pk
)).
data
)
def
put
(
self
,
request
,
pk
):
data_dict
=
SingleSportSerializer
().
to_internal_value
(
request
)
sport
=
Sport
.
objects
.
get
(
pk
=
pk
)
print
(
data_dict
)
return
Response
([])
class
CreateSportAPIView
(
APIView
):
authentication_classes
=
[]
def
post
(
self
,
request
):
data_dict
=
SingleSportSerializer
().
to_internal_value
(
request
)
data_dict
=
SingleSportSerializer
().
to_internal_value
(
request
)
...
@@ -176,3 +115,46 @@ class CreateSportAPIView(APIView):
...
@@ -176,3 +115,46 @@ class CreateSportAPIView(APIView):
response
=
SingleSportSerializer
(
new_sport
)
response
=
SingleSportSerializer
(
new_sport
)
return
Response
(
response
.
data
)
return
Response
(
response
.
data
)
# GET for api/admin/sport/<id>/
def
retrieve
(
self
,
request
,
pk
=
None
):
try
:
sport
=
Sport
.
objects
.
get
(
pk
=
pk
)
except
:
return
JsonResponse
(
{
"
status_code
"
:
404
,
"
error
"
:
f
"
No Sport with ID
{
pk
}
found
"
,
},
status
=
404
,
)
return
Response
(
SingleSportSerializer
(
sport
).
data
)
# PUT for api/admin/sport/<id>/
def
update
(
self
,
request
,
pk
=
None
):
"""
TODO
"""
data_dict
=
SingleSportSerializer
().
to_internal_value
(
request
)
sport
=
Sport
.
objects
.
get
(
pk
=
pk
)
print
(
data_dict
)
return
Response
({
"
test
"
:
"
Updating a Single Entry
"
})
# DELETE for api/admin/sport/<id>/
def
destroy
(
self
,
request
,
pk
=
None
):
return
Response
({
"
test
"
:
"
Removing a Single Entry
"
})
# Dev Notes:
# - This is a singular APIView which isn't meant to expose complete lists
# - It cannot be written into the Router, as it isn't a Viewset, so it is written directly into the urls.py's urlspatterns like this:
# path(r"api/admin/single-small-sport-list", views.SmallSportListAPIView.as_view())
# - The API isn't in the list in /api/admin because of that, but needs to be called manually here:
# http://localhost:8000/api/admin/single-small-sport-list
This diff is collapsed.
Click to expand it.
unisportomat/unisportomat/urls.py
+
0
−
3
View file @
59927cd3
...
@@ -27,7 +27,4 @@ router.register(r"small-sport-list", views.SmallSportListView, "small-sport-list
...
@@ -27,7 +27,4 @@ router.register(r"small-sport-list", views.SmallSportListView, "small-sport-list
urlpatterns
=
[
urlpatterns
=
[
path
(
"
admin/
"
,
admin
.
site
.
urls
),
path
(
"
admin/
"
,
admin
.
site
.
urls
),
path
(
"
api/admin/
"
,
include
(
router
.
urls
)),
path
(
"
api/admin/
"
,
include
(
router
.
urls
)),
path
(
"
api/admin/single-small-sport-list
"
,
views
.
SmallSportListAPIView
.
as_view
()),
path
(
"
api/admin/single-sport/<int:pk>
"
,
views
.
SingleSportAPIView
.
as_view
()),
path
(
"
api/admin/single-sport
"
,
views
.
CreateSportAPIView
.
as_view
()),
]
]
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