Skip to content
GitLab
Projects
Groups
Snippets
/
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Sign in
Toggle navigation
Menu
Open sidebar
Kontr 2.0
Portal API Backend
Commits
217ef570
Unverified
Commit
217ef570
authored
Sep 22, 2018
by
Peter Stanko
Browse files
Use the association proxy instead of the hybrid property
parent
74c0fa76
Pipeline
#13273
canceled with stage
in 16 minutes and 20 seconds
Changes
2
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
portal/database/models.py
View file @
217ef570
...
...
@@ -9,6 +9,7 @@ from typing import List
from
flask_sqlalchemy
import
BaseQuery
from
sqlalchemy
import
event
from
sqlalchemy.ext.associationproxy
import
association_proxy
from
sqlalchemy.ext.hybrid
import
hybrid_property
from
werkzeug.security
import
check_password_hash
,
generate_password_hash
...
...
@@ -888,20 +889,13 @@ class Submission(db.Model, EntityBase):
passive_deletes
=
True
,
uselist
=
False
)
async_task_id
=
db
.
Column
(
db
.
String
(
length
=
36
))
course
=
association_proxy
(
'project'
,
'course'
)
@
property
def
log_name
(
self
):
return
f
"
{
self
.
id
}
(
{
self
.
course
.
codename
}
/
{
self
.
project
.
codename
}
for "
\
f
"
{
self
.
user
.
username
}
)"
@
hybrid_property
def
course
(
self
):
return
self
.
project
.
course
@
course
.
expression
def
course
(
cls
):
return
Project
.
course
def
change_state
(
self
,
new_state
):
# open to extension (state transition validation, ...)
self
.
state
=
new_state
...
...
tests/rest/test_submission.py
View file @
217ef570
...
...
@@ -54,7 +54,7 @@ def test_list_all_avail_for_user(rest_service, client):
def
test_list_all_avail_for_course
(
rest_service
,
client
):
course
=
rest_service
.
find
.
course
(
'testcourse1'
)
db_subm
=
Submission
.
query
.
filter
(
Submission
.
course
==
course
.
id
).
all
()
db_subm
=
Submission
.
query
.
filter
(
Submission
.
course
==
course
).
all
()
response
=
utils
.
make_request
(
client
,
f
'/submissions?course=testcourse1'
,
method
=
'get'
)
assert
response
.
status_code
==
200
assert
response
.
mimetype
==
'application/json'
...
...
@@ -62,6 +62,7 @@ def test_list_all_avail_for_course(rest_service, client):
resp_submissions
=
utils
.
extract_data
(
response
)
num_of_submissions
=
len
(
resp_submissions
)
assert
num_of_submissions
==
len
(
db_subm
)
assert
num_of_submissions
==
4
def
test_list_all_avail_for_project
(
rest_service
,
client
):
...
...
Write
Preview
Supports
Markdown
0%
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!
Cancel
Please
register
or
sign in
to comment