Skip to content
GitLab
Explore
Sign in
Register
Primary navigation
Search or go to…
Project
C
core
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Requirements
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Locked files
Build
Pipelines
Jobs
Pipeline schedules
Test cases
Artifacts
Deploy
Releases
Package Registry
Container Registry
Model registry
Operate
Environments
Terraform modules
Monitor
Incidents
Service Desk
Analyze
Value stream analytics
Contributor analytics
CI/CD analytics
Repository analytics
Code review analytics
Issue analytics
Insights
Model experiments
Help
Help
Support
GitLab documentation
Compare GitLab plans
Community forum
Contribute to JiHu GitLab
Provide feedback
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
Chenhao Ma
core
Commits
bdea9b7c
Commit
bdea9b7c
authored
9 years ago
by
Gunnar Schaefer
Browse files
Options
Downloads
Patches
Plain Diff
Fix /config.js endpoint
parent
d9ce5e37
No related branches found
Branches containing commit
No related tags found
Tags containing commit
No related merge requests found
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
api/api.py
+2
-11
2 additions, 11 deletions
api/api.py
api/core.py
+5
-1
5 additions, 1 deletion
api/core.py
api/util.py
+10
-0
10 additions, 0 deletions
api/util.py
with
17 additions
and
12 deletions
api/api.py
+
2
−
11
View file @
bdea9b7c
import
sys
import
sys
import
json
import
json
import
pytz
import
webapp2
import
webapp2
import
datetime
import
datetime
import
bson.objectid
import
webapp2_extras.routes
import
webapp2_extras.routes
from
.
import
core
from
.
import
core
from
.
import
jobs
from
.
import
jobs
from
.
import
util
from
.
import
config
from
.
import
config
from
handlers
import
listhandler
from
handlers
import
listhandler
from
handlers
import
userhandler
from
handlers
import
userhandler
...
@@ -115,18 +114,10 @@ routes = [
...
@@ -115,18 +114,10 @@ routes = [
]
]
def
custom_json_serializer
(
obj
):
if
isinstance
(
obj
,
bson
.
objectid
.
ObjectId
):
return
str
(
obj
)
elif
isinstance
(
obj
,
datetime
.
datetime
):
return
pytz
.
timezone
(
'
UTC
'
).
localize
(
obj
).
isoformat
()
raise
TypeError
(
repr
(
obj
)
+
"
is not JSON serializable
"
)
def
dispatcher
(
router
,
request
,
response
):
def
dispatcher
(
router
,
request
,
response
):
rv
=
router
.
default_dispatcher
(
request
,
response
)
rv
=
router
.
default_dispatcher
(
request
,
response
)
if
rv
is
not
None
:
if
rv
is
not
None
:
response
.
write
(
json
.
dumps
(
rv
,
default
=
custom_json_serializer
))
response
.
write
(
json
.
dumps
(
rv
,
default
=
util
.
custom_json_serializer
))
response
.
headers
[
'
Content-Type
'
]
=
'
application/json; charset=utf-8
'
response
.
headers
[
'
Content-Type
'
]
=
'
application/json; charset=utf-8
'
...
...
This diff is collapsed.
Click to expand it.
api/core.py
+
5
−
1
View file @
bdea9b7c
...
@@ -26,7 +26,11 @@ class Config(base.RequestHandler):
...
@@ -26,7 +26,11 @@ class Config(base.RequestHandler):
return
config
.
get_public_config
()
return
config
.
get_public_config
()
def
get_js
(
self
):
def
get_js
(
self
):
self
.
response
.
write
(
'
config =
'
+
json
.
dumps
(
self
.
get
(),
sort_keys
=
True
,
indent
=
4
,
separators
=
(
'
,
'
,
'
:
'
))
+
'
;
'
)
self
.
response
.
write
(
'
config =
'
+
json
.
dumps
(
self
.
get
(),
sort_keys
=
True
,
indent
=
4
,
separators
=
(
'
,
'
,
'
:
'
),
default
=
util
.
custom_json_serializer
,)
+
'
;
'
)
class
Core
(
base
.
RequestHandler
):
class
Core
(
base
.
RequestHandler
):
...
...
This diff is collapsed.
Click to expand it.
api/util.py
+
10
−
0
View file @
bdea9b7c
...
@@ -9,6 +9,7 @@ import pymongo
...
@@ -9,6 +9,7 @@ import pymongo
import
zipfile
import
zipfile
import
datetime
import
datetime
import
mimetypes
import
mimetypes
import
bson.objectid
import
tempdir
as
tempfile
import
tempdir
as
tempfile
MIMETYPES
=
[
MIMETYPES
=
[
...
@@ -87,6 +88,7 @@ def guess_filetype(filepath, mimetype):
...
@@ -87,6 +88,7 @@ def guess_filetype(filepath, mimetype):
else
:
else
:
return
subtype
return
subtype
def
path_from_hash
(
hash_
):
def
path_from_hash
(
hash_
):
"""
"""
create a filepath from a hash
create a filepath from a hash
...
@@ -98,3 +100,11 @@ def path_from_hash(hash_):
...
@@ -98,3 +100,11 @@ def path_from_hash(hash_):
path
=
[
hash_
[
i
]
for
i
in
xrange
(
8
)]
path
=
[
hash_
[
i
]
for
i
in
xrange
(
8
)]
path
.
append
(
hash_
)
path
.
append
(
hash_
)
return
os
.
path
.
join
(
*
path
)
return
os
.
path
.
join
(
*
path
)
def
custom_json_serializer
(
obj
):
if
isinstance
(
obj
,
bson
.
objectid
.
ObjectId
):
return
str
(
obj
)
elif
isinstance
(
obj
,
datetime
.
datetime
):
return
pytz
.
timezone
(
'
UTC
'
).
localize
(
obj
).
isoformat
()
raise
TypeError
(
repr
(
obj
)
+
"
is not JSON serializable
"
)
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