Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
H
hub
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Deploy
Package registry
Operate
Terraform modules
Analyze
Contributor analytics
Help
Help
Support
GitLab documentation
Compare GitLab plans
GitLab community forum
Contribute to GitLab
Provide feedback
Terms and privacy
Keyboard shortcuts
?
Snippets
Groups
Projects
Show more breadcrumbs
thomasDOTwtf
hub
Commits
9c44ca1c
Unverified
Commit
9c44ca1c
authored
Dec 15, 2023
by
Andreas Hubel
Browse files
Options
Downloads
Patches
Plain Diff
feat: add i18n mechanism
parent
f669b6a5
No related branches found
No related tags found
No related merge requests found
Changes
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
src/core/schedules/schedulejson.py
+18
-5
18 additions, 5 deletions
src/core/schedules/schedulejson.py
with
18 additions
and
5 deletions
src/core/schedules/schedulejson.py
+
18
−
5
View file @
9c44ca1c
...
@@ -38,7 +38,8 @@ class ScheduleJSONSupport(BaseScheduleSupport):
...
@@ -38,7 +38,8 @@ class ScheduleJSONSupport(BaseScheduleSupport):
if the name of the event changes the identifier must not change!
if the name of the event changes the identifier must not change!
"""
"""
schedule
=
ScheduleJSON
.
from_url
(
self
.
remote_url
)
schedule
=
ScheduleJSON
.
from_url
(
self
.
remote_url
,
language
=
'
en
'
)
schedule_de
=
ScheduleJSON
.
from_url
(
self
.
remote_url
,
language
=
'
de
'
,
event_map
=
True
)
instance
=
urlparse
(
schedule
.
get
(
'
base_url
'
,
self
.
remote_url
))
instance
=
urlparse
(
schedule
.
get
(
'
base_url
'
,
self
.
remote_url
))
base_url
=
f
'
//
{
instance
.
netloc
}
'
base_url
=
f
'
//
{
instance
.
netloc
}
'
...
@@ -52,6 +53,8 @@ class ScheduleJSONSupport(BaseScheduleSupport):
...
@@ -52,6 +53,8 @@ class ScheduleJSONSupport(BaseScheduleSupport):
'
language
'
:
e
.
get
(
'
language
'
),
'
language
'
:
e
.
get
(
'
language
'
),
'
abstract
'
:
e
.
get
(
'
abstract
'
)
or
''
,
'
abstract
'
:
e
.
get
(
'
abstract
'
)
or
''
,
'
description
'
:
e
.
get
(
'
description
'
)
or
''
,
'
description
'
:
e
.
get
(
'
description
'
)
or
''
,
'
description_en
'
:
e
.
get
(
'
description
'
)
or
''
,
'
description_de
'
:
schedule_de
.
event
(
e
.
get
(
'
guid
'
)).
get
(
'
description
'
)
or
''
,
'
track
'
:
e
.
get
(
'
track
'
),
'
track
'
:
e
.
get
(
'
track
'
),
'
room
'
:
e
.
get
(
'
room
'
),
'
room
'
:
e
.
get
(
'
room
'
),
'
schedule_start
'
:
e
.
get
(
'
date
'
),
'
schedule_start
'
:
e
.
get
(
'
date
'
),
...
@@ -78,13 +81,18 @@ class ScheduleJSON:
...
@@ -78,13 +81,18 @@ class ScheduleJSON:
"""
"""
_schedule
=
None
_schedule
=
None
_events
=
None
def
__init__
(
self
,
json
):
def
__init__
(
self
,
json
,
event_map
=
False
):
self
.
_schedule
=
json
self
.
_schedule
=
json
if
event_map
:
self
.
_events
=
{
e
.
get
(
'
guid
'
):
e
for
e
in
self
.
events
()}
@classmethod
@classmethod
def
from_url
(
cls
,
url
):
def
from_url
(
cls
,
url
,
client
=
None
,
language
=
None
,
event_map
=
False
):
r
=
s
.
get
(
url
)
if
not
client
:
client
=
requests
r
=
client
.
get
(
url
,
headers
=
{
'
Accept-Language
'
:
language
}
if
language
else
None
)
if
r
.
ok
is
False
:
if
r
.
ok
is
False
:
raise
Exception
(
f
'
Request failed, HTTP
{
r
.
status_code
}
.
'
)
raise
Exception
(
f
'
Request failed, HTTP
{
r
.
status_code
}
.
'
)
...
@@ -92,7 +100,7 @@ class ScheduleJSON:
...
@@ -92,7 +100,7 @@ class ScheduleJSON:
# maintain order from input file
# maintain order from input file
schedule
=
json
.
JSONDecoder
(
object_pairs_hook
=
OrderedDict
).
decode
(
r
.
text
)
schedule
=
json
.
JSONDecoder
(
object_pairs_hook
=
OrderedDict
).
decode
(
r
.
text
)
return
ScheduleJSON
(
json
=
schedule
[
'
schedule
'
])
return
ScheduleJSON
(
json
=
schedule
[
'
schedule
'
]
,
event_map
=
event_map
)
def
__getitem__
(
self
,
key
):
def
__getitem__
(
self
,
key
):
return
self
.
_schedule
[
key
]
return
self
.
_schedule
[
key
]
...
@@ -128,5 +136,10 @@ class ScheduleJSON:
...
@@ -128,5 +136,10 @@ class ScheduleJSON:
for
room
in
day
.
get
(
'
rooms
'
):
for
room
in
day
.
get
(
'
rooms
'
):
yield
from
day
.
get
(
'
rooms
'
)[
room
]
yield
from
day
.
get
(
'
rooms
'
)[
room
]
def
event
(
self
,
guid
):
if
guid
in
self
.
_events
:
return
self
.
_events
[
guid
]
return
None
def
__str__
(
self
):
def
__str__
(
self
):
return
json
.
dumps
(
self
.
_schedule
,
indent
=
2
)
return
json
.
dumps
(
self
.
_schedule
,
indent
=
2
)
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