Dynastie

Dynastie Commit Details

Date:2015-09-21 19:07:39 (4 years 10 months ago)
Author:Grégory Soutadé
Branch:master
Commit:cde08b8cfade6368c5c84c1c5fa5e9c6261fd795
Parents: dd6739461b341aa418d3aa88631b7b87fe64d4bf
Message:Add article inclusion (Mardown only)

Changes:
MChangeLog (1 diff)
Mdynastie/generators/generator.py (1 diff)
Mdynastie/generators/index.py (4 diffs)
Mdynastie/generators/post.py (3 diffs)

File differences

ChangeLog
1
2
3
4
5
6
7
8
9
110
211
312
v0.5 (21/09/2015)
** User **
Enable code coloration support with Markdown syntax
Add article inclusion (Mardown only)
** Dev **
Support Django 1.8
v0.4 (09/08/2015)
** User **
Redirect user to comment when it's added and not to begining of page
dynastie/generators/generator.py
5757
5858
5959
60
60
6161
6262
6363
URI = "http://indefero.soutade.fr/p/dynastie"
def __init__(self, hash_posts=None, hash_posts_content=None):
def __init__(self, hash_posts={}, hash_posts_content={}):
self.report = ''
self.somethingWrote = False
self.hash_posts = hash_posts
dynastie/generators/index.py
1818
1919
2020
21
2122
2223
2324
......
3031
3132
3233
33
34
3435
3536
3637
......
197198
198199
199200
200
201
201202
202203
203204
204205
205206
206
207
207208
208209
209210
210211
211212
212213
213
214
215
214
215
216216
217
218
219
217
218
219
220220
221
222
223
224
225
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
226251
227252
228253
......
238263
239264
240265
241
266
267
268
242269
243270
244271
245272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
246292
247293
248294
along with Dynastie. If not, see <http://www.gnu.org/licenses/>.
"""
import os
import re
import datetime
import hashlib
import xml
class Index(DynastieGenerator):
def __init__(self, hash_posts=None, hash_posts_content=None):
def __init__(self, hash_posts={}, hash_posts_content={}):
DynastieGenerator.__init__(self, hash_posts, hash_posts_content)
self.hooks = {'posts' : self.createPosts,
if end < start:
self.addError('Invalid <dyn:code> tags in ' + self.filename)
break
try:
dom = parseString(code[start:end+11])
except xml.dom.DOMException as e:
self.addError('Error parsing ' + self.filename)
break
res = self.createCode(dom, dom.firstChild)
if res:
code = code.replace(code[start:end+11], res)
return code
def createPost(self, posts, dom, post_elem, root):
from dynastie.models import Post
post = self.cur_post_obj
def _have_I_right(self, user, post_id):
from dynastie.models import Post, Blog
if post.id in self.hash_posts and not self.first_try:
node = self.hash_posts[post.id]
return node.cloneNode(0)
p = Post.objects.get(pk=post_id)
if p is None: return None
values = {'post_content': '', 'author': 'Unknown'}
try:
values['author'] = post.author.first_name + ' ' + post.author.last_name
except:
pass
blog_id = p.blog.id
if not user.is_superuser:
b = Blog.objects.filter(pk=blog_id, writers=user.id)
if not b: return None
b = b[0]
else:
b = Blog.objects.get(pk=blog_id)
if b is None: return None
return (b, p)
def _manageInternalPosts(self, post, text, parent_posts, user=None):
from dynastie.models import Post
if not user: user = post.author
if post and post.content_format != Post.CONTENT_TEXT: return text
internal_posts = re.search('\[\[([0-9]+)\]\]', text)
if not internal_posts: return text
for post_id in internal_posts.groups():
post_id = int(post_id)
if post_id in parent_posts: continue
_,post = self._have_I_right(user, post_id)
if not post: continue
new_content = self._loadPostContent(post, parent_posts)
if new_content:
text = text.replace('[[' + str(post_id) + ']]', new_content)
return text
def _loadPostContent(self, post, parent_posts):
from dynastie.models import Post
blog = post.blog
blog.create_paths()
post_content = f.read()
f.close()
if post.content_format == Post.CONTENT_TEXT:
post_content = markdown2.markdown(post_content)
parent_posts.append(post.id)
post_content = self._manageInternalPosts(post, post_content, parent_posts)
post_content = markdown2.markdown(post_content, extras=['fenced-code-blocks'])
self.hash_posts_content[filename] = post_content
else:
post_content = self.hash_posts_content[filename]
return post_content
def createPost(self, posts, dom, post_elem, root):
from dynastie.models import Post
post = self.cur_post_obj
if post.id in self.hash_posts and not self.first_try:
node = self.hash_posts[post.id]
return node.cloneNode(0)
values = {'post_content': '', 'author': 'Unknown'}
try:
values['author'] = post.author.first_name + ' ' + post.author.last_name
except:
pass
post_content = _loadPostContent(post, [])
if not post_content: return None
post_content = self.pygmentCode(post_content)
self.simpleTransform(values, dom, post_elem, root)
dynastie/generators/post.py
230230
231231
232232
233
233
234
234235
235236
236237
......
241242
242243
243244
244
245
245246
246247
247248
......
250251
251252
252253
253
254
254255
255256
257
258
256259
257260
258261
v['date'] = now.strftime("%A, %d %B %Y %H:%m")
v['post_content'] = ''
values['content'] = self.pygmentCode(values['content'])
post_content = self._manageInternalPosts(None, values['content'], [], self.user)
post_content = self.pygmentCode(post_content)
self.simpleTransform(v, dom, root, node)
if not the_class in post_transform:
continue
if the_class == 'post_content':
new_node = dom.createTextNode(values['content'])
new_node = dom.createTextNode(post_content)
content_node.appendChild(new_node)
post_nodes = dom.getElementsByTagNameNS(self.URI, "post")
return post_elem
def preview(self, src, values):
def preview(self, request, src, values):
from dynastie.models import Blog
self.user = request.user
# Override all hooks
self.hooks = {'post' : self.createPreview,
'tags' : self.createTags}

Archive Download the corresponding diff file

Branches

Tags