diff --git a/generators/generator.py b/generators/generator.py index 6cde8b8..1747bd1 100644 --- a/generators/generator.py +++ b/generators/generator.py @@ -122,6 +122,15 @@ class DynastieGenerator: 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): for node in root.childNodes: if node.prefix == 'dyn': @@ -159,23 +168,23 @@ class DynastieGenerator: return root if len(bases) != 1: - addError('More than one base defined') + self.addError('More than one base defined') return root base = bases[0] if not base.hasAttribute('file'): - addError('No \'file\' attribute defined') + self.addError('No \'file\' attribute defined') return root filename = base.getAttribute('file') if not base.hasAttribute('block'): - addError('No \'block\' attribute defined') + self.addError('No \'block\' attribute defined') return root target_block = base.getAttribute('block') if not os.path.exists(src + '/' + filename): - addError('Base ' + filename + ' doesn\'t exists') + self.addError('Base ' + filename + ' doesn\'t exists') return root dom2 = root @@ -189,7 +198,7 @@ class DynastieGenerator: block_found = False for block in blocks: if not block.hasAttribute('name'): - addError('block has no attribute \'name\' in ' + filename) + self.addError('block has no attribute \'name\' in ' + filename) return root blockname = block.getAttribute('name') if blockname != target_block: @@ -201,7 +210,7 @@ class DynastieGenerator: block_found = True 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 root = dom2.firstChild diff --git a/generators/post.py b/generators/post.py index c2ae0e3..227837b 100644 --- a/generators/post.py +++ b/generators/post.py @@ -7,13 +7,34 @@ from django.db import models 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): 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.parentNode.removeChild(post_elem) - title_nodes = dom.getElementsByTagName("title") + title_nodes = dom.getElementsByTagName('title') # Set title to be title's post for node in title_nodes: @@ -24,7 +45,8 @@ class Post(Index): def generate(self, blog, src, output): 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'): self.addError('No _post.html found, exiting') diff --git a/views.py b/views.py index 2a766ee..eda3ab3 100644 --- a/views.py +++ b/views.py @@ -30,7 +30,7 @@ def disconnect(request): logout(request) c = {'auth_key': 'AAAAAAAAAAAAAAAAAAAAAAAAAAAAAAAA',\ 'login_failed' : False} - return render(request, 'templates/login.html', c) + return HttpResponseRedirect('/') @login_required def user(request):