1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161 | === modified file 'md_importer/importer/__init__.py'
--- md_importer/importer/__init__.py 2016-01-28 16:31:37 +0000
+++ md_importer/importer/__init__.py 2016-02-26 17:02:57 +0000
@@ -13,6 +13,6 @@
'pymdownx.tilde',
'pymdownx.githubemoji',
'pymdownx.tasklist',
- 'pymdownx.headeranchor',
+# 'pymdownx.headeranchor',
'pymdownx.superfences',
]
=== modified file 'md_importer/importer/article.py'
--- md_importer/importer/article.py 2016-02-25 16:16:18 +0000
+++ md_importer/importer/article.py 2016-02-26 16:57:54 +0000
@@ -6,6 +6,8 @@
import re
import sys
+from djangocms_text_ckeditor.html import clean_html
+
from . import (
DEFAULT_LANG,
MARKDOWN_EXTENSIONS,
@@ -30,6 +32,7 @@
self.slug = os.path.basename(self.full_url)
self.links_rewritten = False
self.local_images = []
+ print(self.slug, 'article.__init__')
def _find_local_images(self):
'''Local images are currently not supported.'''
@@ -80,6 +83,9 @@
r'\s*<\/body>\s*<\/html>\s*',
# This is added by BeautifulSoup.prettify
r'\s*<html>\s*<head>\s*<\/head>\s*<body>\s*',
+ # These are added on the fly and we don't need them - they cause
+ # issues...
+ r'\s*aria\-hidden\=\"true\"',
]:
self.html = re.sub(regex, '', self.html,
flags=re.MULTILINE)
@@ -113,6 +119,7 @@
self._remove_body_and_html_tags()
def add_to_db(self):
+ print(self.slug, 'article.add_to_db')
'''Publishes pages in their branch alias namespace.'''
self.page = get_or_create_page(
title=self.title, full_url=self.full_url, menu_title=self.title,
@@ -123,10 +130,13 @@
return True
def publish(self):
+ print(self.slug, 'article.publish')
if self.links_rewritten:
+ print(self.slug, 'links rewritten, so updating page')
update_page(self.page, title=self.title, full_url=self.full_url,
menu_title=self.title, html=self.html)
if self.page.is_dirty(DEFAULT_LANG):
+ print(self.slug, 'page is dirty')
self.page.publish(DEFAULT_LANG)
if self.page.get_public_object():
self.page = self.page.get_public_object()
=== modified file 'md_importer/importer/publish.py'
--- md_importer/importer/publish.py 2016-02-25 14:02:28 +0000
+++ md_importer/importer/publish.py 2016-02-26 16:40:46 +0000
@@ -32,6 +32,17 @@
return parent_pages[0].page
+def find_text_plugin(page):
+ # We create the page, so we know there's just one placeholder
+ placeholder = page.placeholders.all()[0]
+ if placeholder.get_plugins():
+ return (
+ placeholder,
+ placeholder.get_plugins()[0].get_plugin_instance()[0]
+ )
+ return (placeholder, None)
+
+
def update_page(page, title, full_url, menu_title=None,
in_navigation=True, redirect=None, html=None):
if page.get_title() != title:
@@ -43,11 +54,35 @@
if page.get_redirect() != redirect:
page.redirect = redirect
if html:
- # We create the page, so we know there's just one placeholder
- placeholder = page.placeholders.all()[0]
- if placeholder.get_plugins():
- plugin = placeholder.get_plugins()[0].get_plugin_instance()[0]
- if plugin.body != clean_html(html, full=False):
+ update = True
+ (placeholder, plugin) = find_text_plugin(page)
+ if plugin:
+ clean_content = clean_html(html, full=False)
+ new = [html, clean_content]
+ old = [plugin.body]
+ if page.get_public_object():
+ (dummy, published_plugin) = \
+ find_text_plugin(page.get_public_object())
+ if published_plugin:
+ old += [published_plugin.body]
+ if published_plugin.body not in new:
+ print(page.get_slug(), 'public page differs from new draft')
+ for item in old:
+ if item in new:
+ update = False
+ if plugin.body not in new:
+ print(page.get_slug(), 'draft page differs from considered html')
+ print(page.get_slug(), 'update', update)
+ if update:
+ if page.get_public_object():
+ print('===================PUBLISHED==========================')
+ print(published_plugin.body.encode('utf-8'))
+ print('===================DRAFT==============================')
+ print(plugin.body.encode('utf-8'))
+ print('===================SUGGESTED==========================')
+ print(html.encode('utf-8'))
+ print('===================CLEANED============================')
+ print(clean_content.encode('utf-8'))
plugin.body = html
plugin.save()
else:
@@ -70,6 +105,7 @@
if not parent:
return None
slug = os.path.basename(full_url)
+ print(slug, 'creating page')
page = create_page(
title, 'default.html', DEFAULT_LANG, slug=slug, parent=parent,
menu_title=menu_title, in_navigation=in_navigation,
=== modified file 'md_importer/tests/test_branch_import.py'
--- md_importer/tests/test_branch_import.py 2016-02-25 14:51:40 +0000
+++ md_importer/tests/test_branch_import.py 2016-02-26 16:39:53 +0000
@@ -110,8 +110,8 @@
'''Run import on the same contents twice, make sure we don't
update the HTML in the pages over and over again.'''
def runTest(self):
- self.create_repo('data/snapcraft-test')
- self.repo.add_directive('docs', '')
+ self.create_repo('data/link-test')
+ self.repo.add_directive('', '')
self.assertTrue(self.repo.execute_import_directives())
self.assertTrue(self.repo.publish())
self.assertEqual(
@@ -121,8 +121,8 @@
now = datetime.now(pytz.utc)
shutil.rmtree(self.tempdir)
# Run second import
- self.create_repo('data/snapcraft-test')
- self.repo.add_directive('docs', '')
+ self.create_repo('data/link-test')
+ self.repo.add_directive('', '')
self.assertEqual(len(self.repo.directives), 1)
self.assertEqual(len(self.repo.imported_articles), 0)
self.assertTrue(self.repo.execute_import_directives())
|