Add "dyn:meta" tag support
fix a bug (forgot self) disconnect now redirects in /
This commit is contained in:
parent
d07b3b645a
commit
fec7447d13
|
@ -122,6 +122,15 @@ class DynastieGenerator:
|
||||||
|
|
||||||
return div
|
return div
|
||||||
|
|
||||||
|
def createMeta(self, dom, name='', content=''):
|
||||||
|
div = dom.createElement('meta')
|
||||||
|
if name != '':
|
||||||
|
div.setAttribute('name', name)
|
||||||
|
if content != '':
|
||||||
|
div.setAttribute('content', content)
|
||||||
|
|
||||||
|
return div
|
||||||
|
|
||||||
def simpleTransform(self, values, dom, elem, root):
|
def simpleTransform(self, values, dom, elem, root):
|
||||||
for node in root.childNodes:
|
for node in root.childNodes:
|
||||||
if node.prefix == 'dyn':
|
if node.prefix == 'dyn':
|
||||||
|
@ -159,23 +168,23 @@ class DynastieGenerator:
|
||||||
return root
|
return root
|
||||||
|
|
||||||
if len(bases) != 1:
|
if len(bases) != 1:
|
||||||
addError('More than one base defined')
|
self.addError('More than one base defined')
|
||||||
return root
|
return root
|
||||||
|
|
||||||
base = bases[0]
|
base = bases[0]
|
||||||
|
|
||||||
if not base.hasAttribute('file'):
|
if not base.hasAttribute('file'):
|
||||||
addError('No \'file\' attribute defined')
|
self.addError('No \'file\' attribute defined')
|
||||||
return root
|
return root
|
||||||
filename = base.getAttribute('file')
|
filename = base.getAttribute('file')
|
||||||
|
|
||||||
if not base.hasAttribute('block'):
|
if not base.hasAttribute('block'):
|
||||||
addError('No \'block\' attribute defined')
|
self.addError('No \'block\' attribute defined')
|
||||||
return root
|
return root
|
||||||
target_block = base.getAttribute('block')
|
target_block = base.getAttribute('block')
|
||||||
|
|
||||||
if not os.path.exists(src + '/' + filename):
|
if not os.path.exists(src + '/' + filename):
|
||||||
addError('Base ' + filename + ' doesn\'t exists')
|
self.addError('Base ' + filename + ' doesn\'t exists')
|
||||||
return root
|
return root
|
||||||
|
|
||||||
dom2 = root
|
dom2 = root
|
||||||
|
@ -189,7 +198,7 @@ class DynastieGenerator:
|
||||||
block_found = False
|
block_found = False
|
||||||
for block in blocks:
|
for block in blocks:
|
||||||
if not block.hasAttribute('name'):
|
if not block.hasAttribute('name'):
|
||||||
addError('block has no attribute \'name\' in ' + filename)
|
self.addError('block has no attribute \'name\' in ' + filename)
|
||||||
return root
|
return root
|
||||||
blockname = block.getAttribute('name')
|
blockname = block.getAttribute('name')
|
||||||
if blockname != target_block:
|
if blockname != target_block:
|
||||||
|
@ -201,7 +210,7 @@ class DynastieGenerator:
|
||||||
block_found = True
|
block_found = True
|
||||||
|
|
||||||
if not block_found:
|
if not block_found:
|
||||||
addError('Block ' + target_block + ' not found in ' + src + '/' + filename)
|
self.addError('Block ' + target_block + ' not found in ' + src + '/' + filename)
|
||||||
return root
|
return root
|
||||||
|
|
||||||
root = dom2.firstChild
|
root = dom2.firstChild
|
||||||
|
|
|
@ -7,13 +7,34 @@ from django.db import models
|
||||||
|
|
||||||
class Post(Index):
|
class Post(Index):
|
||||||
|
|
||||||
|
def createMetas(self, post, dom, meta_elem, root):
|
||||||
|
name = root.getAttribute('name')
|
||||||
|
if name is None:
|
||||||
|
self.addError('Missing name attribute in dyn:meta')
|
||||||
|
return
|
||||||
|
|
||||||
|
new_elem = None
|
||||||
|
if name == 'keywords':
|
||||||
|
new_elem = self.createMeta(dom, name, post.keywords)
|
||||||
|
elif name == 'title':
|
||||||
|
new_elem = self.createMeta(dom, name, post.title)
|
||||||
|
elif name == 'description':
|
||||||
|
new_elem = self.createMeta(dom, name, post.description)
|
||||||
|
elif name == 'author':
|
||||||
|
new_elem = self.createMeta(dom, name, post.author.first_name + ' ' + post.author.last_name)
|
||||||
|
|
||||||
|
if not new_elem is None:
|
||||||
|
root.parentNode.replaceChild(new_elem, root)
|
||||||
|
else:
|
||||||
|
self.addError('name attribute \'' + name + '\' unknown for dyn:meta' )
|
||||||
|
|
||||||
def _createPost(self, post, dom, post_elem, root):
|
def _createPost(self, post, dom, post_elem, root):
|
||||||
self.createPost(post, dom, post_elem, root)
|
self.createPost(post, dom, post_elem, root)
|
||||||
post_nodes = dom.getElementsByTagNameNS(self.URI, "post")
|
post_nodes = dom.getElementsByTagNameNS(self.URI, 'post')
|
||||||
post_elem = post_nodes[0]
|
post_elem = post_nodes[0]
|
||||||
post_elem.parentNode.removeChild(post_elem)
|
post_elem.parentNode.removeChild(post_elem)
|
||||||
|
|
||||||
title_nodes = dom.getElementsByTagName("title")
|
title_nodes = dom.getElementsByTagName('title')
|
||||||
|
|
||||||
# Set title to be title's post
|
# Set title to be title's post
|
||||||
for node in title_nodes:
|
for node in title_nodes:
|
||||||
|
@ -24,7 +45,8 @@ class Post(Index):
|
||||||
def generate(self, blog, src, output):
|
def generate(self, blog, src, output):
|
||||||
from dynastie.models import Post, Blog
|
from dynastie.models import Post, Blog
|
||||||
|
|
||||||
hooks = {'post' : self._createPost}
|
hooks = {'post' : self._createPost,
|
||||||
|
'meta' : self.createMetas}
|
||||||
|
|
||||||
if not os.path.exists(src + '/_post.html'):
|
if not os.path.exists(src + '/_post.html'):
|
||||||
self.addError('No _post.html found, exiting')
|
self.addError('No _post.html found, exiting')
|
||||||
|
|
2
views.py
2
views.py
|
@ -30,7 +30,7 @@ def disconnect(request):
|
||||||
logout(request)
|
logout(request)
|
||||||
c = {'auth_key': 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',\
|
c = {'auth_key': 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',\
|
||||||
'login_failed' : False}
|
'login_failed' : False}
|
||||||
return render(request, 'templates/login.html', c)
|
return HttpResponseRedirect('/')
|
||||||
|
|
||||||
@login_required
|
@login_required
|
||||||
def user(request):
|
def user(request):
|
||||||
|
|
Loading…
Reference in New Issue
Block a user