Skip to content
GitLab
Explore
Sign in
Primary navigation
Search or go to…
Project
Maják
Manage
Activity
Members
Labels
Plan
Issues
Issue boards
Milestones
Wiki
Code
Merge requests
Repository
Branches
Commits
Tags
Repository graph
Compare revisions
Snippets
Build
Pipelines
Jobs
Pipeline schedules
Artifacts
Deploy
Releases
Container registry
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
TO
Maják
Commits
50e70acf
Commit
50e70acf
authored
3 years ago
by
jan.hosek
Browse files
Options
Downloads
Patches
Plain Diff
parametry pro id stranky clanku a kolekce
parent
ea202873
No related branches found
No related tags found
2 merge requests
!423
Release
,
!419
district import jekyll
Pipeline
#6782
passed
3 years ago
Stage: build
Changes
1
Pipelines
1
Show whitespace changes
Inline
Side-by-side
Showing
1 changed file
district/management/commands/district_import_jekyll.py
+22
-23
22 additions, 23 deletions
district/management/commands/district_import_jekyll.py
with
22 additions
and
23 deletions
district/management/commands/district_import_jekyll.py
+
22
−
23
View file @
50e70acf
...
@@ -44,8 +44,7 @@ Markdown.output_formats["plain"] = unmark_element
...
@@ -44,8 +44,7 @@ Markdown.output_formats["plain"] = unmark_element
plain_md
=
Markdown
(
output_format
=
"
plain
"
)
plain_md
=
Markdown
(
output_format
=
"
plain
"
)
plain_md
.
stripTopLevelTags
=
False
plain_md
.
stripTopLevelTags
=
False
global
path
params
=
{}
PATH
=
os
.
path
.
abspath
(
"
../cb.pirati.cz/
"
)
class
ImgProcessor
(
InlineProcessor
):
class
ImgProcessor
(
InlineProcessor
):
...
@@ -56,8 +55,8 @@ class ImgProcessor(InlineProcessor):
...
@@ -56,8 +55,8 @@ class ImgProcessor(InlineProcessor):
el
.
attrib
[
"
format
"
]
=
"
left
"
el
.
attrib
[
"
format
"
]
=
"
left
"
collection
=
get_collection
()
collection
=
get_collection
()
image_obj
=
get_or_create_image
(
image_obj
=
get_or_create_image
(
pa
th
,
m
.
group
(
2
),
collection
=
collection
pa
rams
[
"
path
"
]
,
m
.
group
(
2
),
collection
=
collection
)
# TODO path
)
el
.
attrib
[
"
id
"
]
=
str
(
image_obj
.
pk
)
el
.
attrib
[
"
id
"
]
=
str
(
image_obj
.
pk
)
return
el
,
m
.
start
(
0
),
m
.
end
(
0
)
return
el
,
m
.
start
(
0
),
m
.
end
(
0
)
...
@@ -86,7 +85,7 @@ def get_site_config(path):
...
@@ -86,7 +85,7 @@ def get_site_config(path):
return
config
return
config
def
import_post
(
path
,
file_path
,
parrent
,
title_suffix
):
def
import_post
(
path
,
file_path
,
parrent
,
title_suffix
,
command
):
with
open
(
os
.
path
.
join
(
path
,
file_path
),
"
rt
"
)
as
f
:
with
open
(
os
.
path
.
join
(
path
,
file_path
),
"
rt
"
)
as
f
:
r
=
re
.
split
(
r
"
^---\s*$
"
,
f
.
read
(),
maxsplit
=
3
,
flags
=
re
.
MULTILINE
)
r
=
re
.
split
(
r
"
^---\s*$
"
,
f
.
read
(),
maxsplit
=
3
,
flags
=
re
.
MULTILINE
)
meta
=
yaml
.
safe_load
(
r
[
1
])
meta
=
yaml
.
safe_load
(
r
[
1
])
...
@@ -96,6 +95,7 @@ def import_post(path, file_path, parrent, title_suffix):
...
@@ -96,6 +95,7 @@ def import_post(path, file_path, parrent, title_suffix):
if
DistrictArticlePage
.
objects
.
filter
(
title
=
meta
[
"
title
"
]).
exists
():
if
DistrictArticlePage
.
objects
.
filter
(
title
=
meta
[
"
title
"
]).
exists
():
for
article
in
DistrictArticlePage
.
objects
.
filter
(
title
=
meta
[
"
title
"
]):
for
article
in
DistrictArticlePage
.
objects
.
filter
(
title
=
meta
[
"
title
"
]):
if
article
.
date
==
parse_date
(
meta
[
"
date
"
].
split
()[
0
]):
if
article
.
date
==
parse_date
(
meta
[
"
date
"
].
split
()[
0
]):
command
.
stdout
.
write
(
"
Article already imported: %s
"
%
article
)
return
article
return
article
article
=
DistrictArticlePage
()
article
=
DistrictArticlePage
()
...
@@ -117,6 +117,7 @@ def import_post(path, file_path, parrent, title_suffix):
...
@@ -117,6 +117,7 @@ def import_post(path, file_path, parrent, title_suffix):
parrent
.
add_child
(
instance
=
article
)
parrent
.
add_child
(
instance
=
article
)
command
.
stdout
.
write
(
"
Creating article: %s
"
%
article
)
rev
=
article
.
save_revision
()
rev
=
article
.
save_revision
()
if
meta
[
"
published
"
]:
if
meta
[
"
published
"
]:
rev
.
publish
()
rev
.
publish
()
...
@@ -124,11 +125,7 @@ def import_post(path, file_path, parrent, title_suffix):
...
@@ -124,11 +125,7 @@ def import_post(path, file_path, parrent, title_suffix):
def
get_collection
():
def
get_collection
():
if
Collection
.
objects
.
filter
(
name
=
"
import
"
).
exists
():
return
params
[
"
kolekce
"
]
collection
=
Collection
.
objects
.
filter
(
name
=
"
import
"
).
first
()
else
:
collection
=
Collection
.
add_root
(
name
=
"
import
"
)
return
collection
def
get_or_create_image
(
path
,
file_path
,
collection
):
def
get_or_create_image
(
path
,
file_path
,
collection
):
...
@@ -156,20 +153,24 @@ class Command(BaseCommand):
...
@@ -156,20 +153,24 @@ class Command(BaseCommand):
)
)
parser
.
add_argument
(
parser
.
add_argument
(
"
--clanky-id
"
,
"
--clanky-id
"
,
default
=
Non
e
,
required
=
Tru
e
,
type
=
int
,
type
=
int
,
help
=
"
Id nadstránky článků, defaultně vezme první
"
,
help
=
"
Id nadstránky článků (DistrictArticlesPage), pod kterou se články naimportují
"
,
)
parser
.
add_argument
(
"
--kolekce-id
"
,
required
=
True
,
type
=
int
,
help
=
"
Id id koekce (Collection) pro import obrázků.
"
,
)
)
def
handle
(
self
,
*
args
,
**
options
):
def
handle
(
self
,
*
args
,
**
options
):
if
options
[
"
clanky_id
"
]
is
None
:
articles
=
DistrictArticlesPage
.
objects
.
first
()
else
:
articles
=
DistrictArticlesPage
.
objects
.
get
(
pk
=
options
[
"
clanky_id
"
])
articles
=
DistrictArticlesPage
.
objects
.
get
(
pk
=
options
[
"
clanky_id
"
])
params
[
"
kolekce
"
]
=
Collection
.
objects
.
get
(
pk
=
options
[
"
kolekce_id
"
])
site
=
articles
.
get_site
()
global
path
path
=
params
[
"
path
"
]
=
options
[
"
path
"
]
path
=
options
[
"
path
"
]
site_config
=
get_site_config
(
path
)
site_config
=
get_site_config
(
path
)
if
"
title
"
in
site_config
:
if
"
title
"
in
site_config
:
...
@@ -177,10 +178,6 @@ class Command(BaseCommand):
...
@@ -177,10 +178,6 @@ class Command(BaseCommand):
else
:
else
:
title_suffix
=
""
title_suffix
=
""
if
options
[
"
hostname
"
]
is
None
:
site
=
Site
.
objects
.
first
()
else
:
site
=
Site
.
objects
.
get
(
hostname
=
options
[
"
hostname
"
])
articlepath
=
site_config
[
"
articlepath
"
]
articlepath
=
site_config
[
"
articlepath
"
]
for
fn
in
os
.
listdir
(
os
.
path
.
join
(
path
,
POSTS_DIR
)):
for
fn
in
os
.
listdir
(
os
.
path
.
join
(
path
,
POSTS_DIR
)):
...
@@ -194,7 +191,9 @@ class Command(BaseCommand):
...
@@ -194,7 +191,9 @@ class Command(BaseCommand):
ext
=
match
.
group
(
5
)
ext
=
match
.
group
(
5
)
if
ext
==
"
md
"
:
if
ext
==
"
md
"
:
article
=
import_post
(
path
,
fname
,
articles
,
title_suffix
)
article
=
import_post
(
path
,
fname
,
articles
,
title_suffix
,
command
=
self
)
from
wagtail.contrib.redirects.models
import
Redirect
from
wagtail.contrib.redirects.models
import
Redirect
r
,
created
=
Redirect
.
objects
.
get_or_create
(
r
,
created
=
Redirect
.
objects
.
get_or_create
(
...
...
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