Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
K
kszkepzes-backend
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
JetBrains YouTrack
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
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
KSZK
DevTeam
kszkepzes
old
kszkepzes-backend
Commits
58e53ab8
Commit
58e53ab8
authored
6 years ago
by
Bodor Mate
Browse files
Options
Downloads
Patches
Plain Diff
Solution create and view
parent
7238d48c
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
src/homework/serializers.py
+4
-1
4 additions, 1 deletion
src/homework/serializers.py
src/homework/views.py
+11
-3
11 additions, 3 deletions
src/homework/views.py
with
15 additions
and
4 deletions
src/homework/serializers.py
+
4
−
1
View file @
58e53ab8
...
...
@@ -32,5 +32,8 @@ class SolutionSerializer(serializers.ModelSerializer):
def
validate
(
self
,
data
):
if
timezone
.
now
()
>
data
[
'
task
'
].
deadline
:
raise
serializers
.
ValidationError
(
'
You late.
'
)
data
[
'
accepted
'
]
=
False
return
data
def
create
(
self
,
validated_data
):
validated_data
[
'
accepted
'
]
=
False
return
self
.
Meta
.
model
.
objects
.
create
(
**
validated_data
)
This diff is collapsed.
Click to expand it.
src/homework/views.py
+
11
−
3
View file @
58e53ab8
from
rest_framework
import
viewsets
from
common
import
permissions
from
rest_framework.permissions
import
IsAuthenticated
from
.
import
serializers
from
.
import
models
...
...
@@ -13,7 +14,14 @@ class TasksViewSet(viewsets.ModelViewSet):
class
SolutionsViewSet
(
viewsets
.
ModelViewSet
):
serializer_class
=
serializers
.
SolutionSerializer
queryset
=
models
.
Solution
.
objects
.
all
()
permission_classes
=
(
permissions
.
IsStaffOrReadOnlyForAuthenticated
,
)
permission_classes
=
(
IsAuthenticated
,
)
# view
def
get_queryset
(
self
):
user
=
self
.
request
.
user
queryset
=
models
.
Solution
.
objects
.
filter
(
created_by
=
user
)
if
user
.
has_perm
(
permissions
.
IsStaffUser
):
queryset
=
models
.
Solution
.
objects
.
all
()
user_id
=
self
.
request
.
query_params
.
get
(
'
userID
'
,
None
)
if
user_id
is
not
None
:
queryset
=
queryset
.
filter
(
created_by
=
user_id
)
return
queryset
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