Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
allgo
allgo
Commits
52f58ccf
Commit
52f58ccf
authored
May 15, 2019
by
BAIRE Anthony
Browse files
Merge branch 'minor_refactoring' into 'django'
Minor refactoring See merge request
!168
parents
cd0e8ed4
fe432f46
Pipeline
#79357
passed with stages
in 2 minutes and 23 seconds
Changes
5
Pipelines
3
Hide whitespace changes
Inline
Side-by-side
django/allgo/api/v1/urls.py
View file @
52f58ccf
...
...
@@ -7,5 +7,5 @@ app_name = 'api'
urlpatterns
=
[
url
(
r
'^jobs$'
,
views
.
jobs
,
name
=
'jobs'
),
url
(
r
'^jobs/(?P<pk>\d+)'
,
views
.
APIJobView
.
as_view
(),
name
=
'job'
),
url
(
r
'^datastore/(?P<pk>\d+)/(.*)/(.*)'
,
views
.
APIDownloadView
,
name
=
'download'
),
url
(
r
'^datastore/(?P<pk>\d+)/(.*)/(.*)'
,
views
.
APIDownloadView
.
as_view
()
,
name
=
'download'
),
]
django/allgo/api/v1/views.py
View file @
52f58ccf
...
...
@@ -58,6 +58,10 @@ def jobs(request):
if
not
app
:
return
JsonResponse
({
'error'
:
'Application not found'
},
status
=
404
)
if
app
.
get_webapp_version
()
is
None
:
log
.
debug
(
'No usable versions'
)
return
JsonResponse
({
'error'
:
"This app is not yet published"
},
status
=
404
)
queue
=
app
.
job_queue
if
'job[queue]'
in
request
.
POST
:
try
:
...
...
@@ -67,9 +71,6 @@ def jobs(request):
log
.
info
(
"Job submit by user %s"
,
user
)
job
=
Job
.
objects
.
create
(
param
=
request
.
POST
.
get
(
'job[param]'
,
''
),
queue
=
queue
,
webapp
=
app
,
user
=
user
)
if
app
.
get_webapp_version
()
is
None
:
log
.
debug
(
'No usable versions'
)
return
JsonResponse
({
'error'
:
"This app is not yet published"
},
status
=
404
)
job
.
version
=
app
.
get_webapp_version
().
number
# TODO: add version selection in the api
upload_data
(
request
.
FILES
.
values
(),
job
)
...
...
django/allgo/main/mixins.py
View file @
52f58ccf
...
...
@@ -97,7 +97,11 @@ class JobAuthMixin(AllgoValidAccountMixin, UserPassesTestMixin):
if
user
is
None
:
return
False
self
.
raise_exception
=
True
# to return a 403
job
=
Job
.
objects
.
filter
(
pk
=
self
.
kwargs
[
'pk'
]).
first
()
try
:
job
=
Job
.
objects
.
get
(
id
=
self
.
kwargs
[
'pk'
])
except
Job
.
DoesNotExist
:
return
False
return
user
.
is_superuser
or
user
==
getattr
(
job
,
"user"
,
())
def
handle_no_permission
(
self
):
...
...
django/allgo/main/models.py
View file @
52f58ccf
...
...
@@ -307,6 +307,15 @@ class Webapp(TimeStampModel):
query
=
query
.
filter
(
number
=
number
)
return
query
.
order_by
(
"-state"
,
"-id"
).
first
()
def
get_sandbox_state
(
self
):
""""""
for
i
,
s
in
self
.
SANDBOX_STATE_CHOICES
:
if
i
==
self
.
sandbox_state
:
return
i
,
s
msg
=
"The current state {} is not defined in the model."
\
.
format
(
self
.
sandbox_state
)
raise
ValueError
(
msg
)
class
WebappParameter
(
TimeStampModel
):
...
...
django/allgo/main/views.py
View file @
52f58ccf
...
...
@@ -721,7 +721,7 @@ class WebappSandboxPanel(UserAccessMixin, TemplateView):
messages
.
success
(
request
,
"stopping sandbox %r"
%
webapp
.
name
)
log
.
debug
(
"new sandbox state: %r -> %r"
,
webapp
.
docker_name
,
webapp
.
sandbox_state
)
webapp
.
docker_name
,
webapp
.
get_
sandbox_state
()
)
# NOTE: we return a 302 redirect to the same page (instead of rendering
# it directly) to force the browser to make a separate GET request.
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a 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