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
51848982
Commit
51848982
authored
3 years ago
by
Ondrej Rehounek
Committed by
jan.bednarik
3 years ago
Browse files
Options
Downloads
Patches
Plain Diff
district: Misc fixes
parent
7bfb104e
No related branches found
No related tags found
2 merge requests
!442
Release
,
!432
Feature/majak imports
Changes
3
Show whitespace changes
Inline
Side-by-side
Showing
3 changed files
district/forms.py
+1
-2
1 addition, 2 deletions
district/forms.py
district/jekyll_import.py
+31
-21
31 additions, 21 deletions
district/jekyll_import.py
district/models.py
+0
-3
0 additions, 3 deletions
district/models.py
with
32 additions
and
26 deletions
district/forms.py
+
1
−
2
View file @
51848982
...
@@ -79,8 +79,7 @@ class JekyllImportForm(WagtailAdminPageForm):
...
@@ -79,8 +79,7 @@ class JekyllImportForm(WagtailAdminPageForm):
return
cleaned_data
return
cleaned_data
def
handle_import
(
self
):
def
handle_import
(
self
):
# import_jekyll_articles.delay( # TODO
import_jekyll_articles
.
delay
(
import_jekyll_articles
(
article_parent_page_id
=
self
.
instance
.
id
,
article_parent_page_id
=
self
.
instance
.
id
,
collection_id
=
self
.
cleaned_data
[
"
collection
"
].
id
,
collection_id
=
self
.
cleaned_data
[
"
collection
"
].
id
,
url
=
self
.
cleaned_data
[
"
jekyll_repo_url
"
],
url
=
self
.
cleaned_data
[
"
jekyll_repo_url
"
],
...
...
This diff is collapsed.
Click to expand it.
district/jekyll_import.py
+
31
−
21
View file @
51848982
import
logging
import
logging
import
os
import
os
import
random
import
re
import
re
import
string
import
urllib
import
urllib
import
xml.etree.ElementTree
as
ET
import
xml.etree.ElementTree
as
ET
import
zipfile
import
zipfile
...
@@ -129,7 +131,11 @@ def get_or_create_image(
...
@@ -129,7 +131,11 @@ def get_or_create_image(
image
.
save
()
image
.
save
()
return
image
,
""
return
image
,
""
except
FileNotFoundError
:
except
FileNotFoundError
:
img_name
=
file_path
.
split
(
"
/
"
)[
-
1
]
fallback_name
=
(
""
.
join
(
random
.
choice
(
string
.
ascii_lowercase
)
for
_
in
range
(
10
))
+
"
.jpg
"
)
# i PNG...?
img_name
=
file_path
.
split
(
"
/
"
)[
-
1
]
or
fallback_name
img_assets_folder
=
repo_name
.
split
(
"
.
"
)[
0
]
img_assets_folder
=
repo_name
.
split
(
"
.
"
)[
0
]
img_url
=
"
https://a.pirati.cz/{}/img/{}
"
.
format
(
img_url
=
"
https://a.pirati.cz/{}/img/{}
"
.
format
(
img_assets_folder
,
file_path
.
split
(
"
#
"
)[
0
]
img_assets_folder
,
file_path
.
split
(
"
#
"
)[
0
]
...
@@ -298,6 +304,27 @@ class JekyllArticleImporter:
...
@@ -298,6 +304,27 @@ class JekyllArticleImporter:
image_params
[
"
collection
"
]
=
self
.
collection
image_params
[
"
collection
"
]
=
self
.
collection
image_params
[
"
repo_name
"
]
=
self
.
repo_name
image_params
[
"
repo_name
"
]
=
self
.
repo_name
def
create_redirects
(
self
,
article
,
match
):
y
=
match
.
group
(
1
)
m
=
match
.
group
(
2
)
d
=
match
.
group
(
3
)
slug
=
match
.
group
(
4
)
if
article
and
self
.
article_path
:
# asi jenom Ceske Budejovice
Redirect
.
objects
.
get_or_create
(
site
=
self
.
site
,
old_path
=
"
/%s/%s/%s/%s/%s
"
%
(
self
.
article_path
,
y
,
m
.
zfill
(
2
),
d
.
zfill
(
2
),
slug
),
defaults
=
{
"
is_permanent
"
:
True
,
"
redirect_page
"
:
article
},
)
elif
article
and
self
.
permalink
:
Redirect
.
objects
.
get_or_create
(
site
=
self
.
site
,
old_path
=
self
.
permalink
.
replace
(
"
:title
"
,
slug
),
defaults
=
{
"
is_permanent
"
:
True
,
"
redirect_page
"
:
article
},
)
def
create_summary_log
(
self
):
def
create_summary_log
(
self
):
"""
"""
Podle (aktuálních) hodnot counterů přidá do self.page_log
Podle (aktuálních) hodnot counterů přidá do self.page_log
...
@@ -408,7 +435,7 @@ class JekyllArticleImporter:
...
@@ -408,7 +435,7 @@ class JekyllArticleImporter:
# article.text = html
# article.text = html
article
.
content
=
[(
"
text
"
,
RichText
(
html
))]
article
.
content
=
[(
"
text
"
,
RichText
(
html
))]
article
.
perex
=
self
.
get_perex
(
md
)
article
.
perex
=
self
.
get_perex
(
md
)
or
"
...
"
if
meta
.
get
(
"
date
"
,
None
):
if
meta
.
get
(
"
date
"
,
None
):
meta_date
=
meta
[
"
date
"
]
meta_date
=
meta
[
"
date
"
]
...
@@ -485,10 +512,6 @@ class JekyllArticleImporter:
...
@@ -485,10 +512,6 @@ class JekyllArticleImporter:
def
process_article
(
self
,
file_name
:
str
,
file_path
:
str
):
def
process_article
(
self
,
file_name
:
str
,
file_path
:
str
):
match
=
re
.
match
(
r
"
(\d*)-(\d*)-(\d*)-(.*)\.(.*)
"
,
file_name
)
match
=
re
.
match
(
r
"
(\d*)-(\d*)-(\d*)-(.*)\.(.*)
"
,
file_name
)
if
match
:
if
match
:
y
=
match
.
group
(
1
)
m
=
match
.
group
(
2
)
d
=
match
.
group
(
3
)
slug
=
match
.
group
(
4
)
ext
=
match
.
group
(
5
)
ext
=
match
.
group
(
5
)
if
ext
==
"
md
"
:
if
ext
==
"
md
"
:
...
@@ -497,21 +520,8 @@ class JekyllArticleImporter:
...
@@ -497,21 +520,8 @@ class JekyllArticleImporter:
if
self
.
dry_run
:
if
self
.
dry_run
:
return
return
if
article
and
self
.
article_path
:
# asi hlavne Ceske Budejovice
article
.
save
()
# ujistím se, že mám "redirect_page" pro Redirect uloženou
Redirect
.
objects
.
get_or_create
(
self
.
create_redirects
(
article
,
match
)
site
=
self
.
site
,
old_path
=
"
/%s/%s/%s/%s/%s
"
%
(
self
.
article_path
,
y
,
m
.
zfill
(
2
),
d
.
zfill
(
2
),
slug
),
defaults
=
{
"
is_permanent
"
:
True
,
"
redirect_page
"
:
article
},
)
elif
article
and
self
.
permalink
:
Redirect
.
objects
.
get_or_create
(
site
=
self
.
site
,
old_path
=
self
.
permalink
.
replace
(
"
:title
"
,
slug
),
defaults
=
{
"
is_permanent
"
:
True
,
"
redirect_page
"
:
article
},
)
else
:
else
:
msg
=
"
Nepodporovaná přípona souboru: %s
"
%
ext
msg
=
"
Nepodporovaná přípona souboru: %s
"
%
ext
logger
.
warning
(
msg
)
logger
.
warning
(
msg
)
...
...
This diff is collapsed.
Click to expand it.
district/models.py
+
0
−
3
View file @
51848982
...
@@ -433,9 +433,6 @@ class DistrictArticlesPage(SubpageMixin, MetadataPageMixin, Page):
...
@@ -433,9 +433,6 @@ class DistrictArticlesPage(SubpageMixin, MetadataPageMixin, Page):
).
get_page
(
request
.
GET
.
get
(
"
page
"
))
).
get_page
(
request
.
GET
.
get
(
"
page
"
))
return
context
return
context
def
save
(
self
,
clean
=
True
,
user
=
None
,
log_action
=
False
,
**
kwargs
):
super
(
DistrictArticlesPage
,
self
).
save
()
class
DistrictContactPage
(
SubpageMixin
,
MetadataPageMixin
,
Page
):
class
DistrictContactPage
(
SubpageMixin
,
MetadataPageMixin
,
Page
):
### FIELDS
### FIELDS
...
...
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