2014-03-27 18:29:06 +01:00
|
|
|
# -*- coding: utf-8 -*-
|
|
|
|
"""
|
|
|
|
Copyright 2012-2014 Grégory Soutadé
|
|
|
|
|
|
|
|
This file is part of Dynastie.
|
|
|
|
|
|
|
|
Dynastie is free software: you can redistribute it and/or modify
|
|
|
|
it under the terms of the GNU General Public License as published by
|
|
|
|
the Free Software Foundation, either version 3 of the License, or
|
|
|
|
(at your option) any later version.
|
|
|
|
|
|
|
|
Dynastie is distributed in the hope that it will be useful,
|
|
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
GNU General Public License for more details.
|
|
|
|
|
|
|
|
You should have received a copy of the GNU General Public License
|
|
|
|
along with Dynastie. If not, see <http://www.gnu.org/licenses/>.
|
|
|
|
"""
|
|
|
|
import os
|
2014-09-24 20:27:27 +02:00
|
|
|
from xml.dom.minidom import parse
|
2014-03-27 18:29:06 +01:00
|
|
|
import xml.parsers.expat
|
|
|
|
from dynastie.generators.index import Index
|
|
|
|
from django.db import models
|
|
|
|
|
|
|
|
class LJDC(Index):
|
|
|
|
|
|
|
|
def createPost(self, posts, dom, post_elem, root):
|
|
|
|
new_elem = self.createElement(dom, 'ljdc')
|
|
|
|
|
|
|
|
address = self.cur_post_obj.getElementsByTagName('address')[0]
|
|
|
|
a = dom.createElement('a')
|
|
|
|
a.setAttribute('href', address.childNodes[0].nodeValue)
|
|
|
|
|
|
|
|
title_value = self.cur_post_obj.getElementsByTagName('title')[0]
|
2014-06-01 18:58:13 +02:00
|
|
|
title_value = title_value.childNodes[0].nodeValue
|
|
|
|
title = self.createElement(dom, 'title', title_value)
|
2014-03-27 18:29:06 +01:00
|
|
|
a.appendChild(title)
|
|
|
|
|
|
|
|
img_src = self.cur_post_obj.getElementsByTagName('img')[0]
|
|
|
|
img = dom.createElement('img')
|
|
|
|
img.setAttribute('src', img_src.childNodes[0].nodeValue)
|
|
|
|
|
|
|
|
a.appendChild(img)
|
|
|
|
|
|
|
|
new_elem.appendChild(a)
|
|
|
|
|
|
|
|
self.cur_post_obj = None
|
|
|
|
|
|
|
|
return new_elem
|
|
|
|
|
2014-06-01 18:58:13 +02:00
|
|
|
def _load_references(self, src):
|
2014-03-27 18:29:06 +01:00
|
|
|
name = '_ljdc.xml'
|
|
|
|
if not os.path.exists(src + '/%s' % name):
|
|
|
|
self.addWarning('No %s found, exiting' % name)
|
|
|
|
return None
|
|
|
|
|
|
|
|
try:
|
|
|
|
srcdom = parse(src + '/%s' % name)
|
|
|
|
except xml.dom.DOMException as e:
|
|
|
|
self.addError('Error parsing %s : ' + e)
|
|
|
|
return None
|
|
|
|
|
2014-06-01 18:58:13 +02:00
|
|
|
return srcdom
|
|
|
|
|
|
|
|
def generate(self, blog, src, output):
|
2014-09-24 20:27:27 +02:00
|
|
|
self.posts_per_page = 20
|
|
|
|
self.dirname = '/ljdc'
|
|
|
|
|
2014-06-01 18:58:13 +02:00
|
|
|
srcdom = self._load_references(src)
|
|
|
|
|
|
|
|
if srcdom is None: return None
|
|
|
|
|
2014-03-27 18:29:06 +01:00
|
|
|
posts = srcdom.getElementsByTagName("entry")
|
|
|
|
|
|
|
|
dom = self.parseTemplate(blog, src, output, 'ljdc', 'ljdc')
|
|
|
|
if dom is None: return self.report
|
|
|
|
|
|
|
|
self.generatePages(dom, posts, src, output, 'ljdc')
|
|
|
|
|
|
|
|
if not self.somethingWrote:
|
|
|
|
self.addReport('Nothing changed')
|
|
|
|
|
|
|
|
return self.report
|
|
|
|
|
2014-06-01 18:58:13 +02:00
|
|
|
def getLast(self, dom, src):
|
|
|
|
srcdom = self._load_references(src)
|
|
|
|
if srcdom is None: return None
|
|
|
|
|
|
|
|
images = srcdom.getElementsByTagName("img")
|
|
|
|
if len(images) == 0: return None
|
|
|
|
|
|
|
|
img = dom.createElement('img')
|
|
|
|
img.setAttribute('src', images[0].childNodes[0].nodeValue)
|
|
|
|
|
|
|
|
title = srcdom.getElementsByTagName("title")[0]
|
|
|
|
title = title.childNodes[0].nodeValue
|
|
|
|
img.setAttribute('alt', title.replace("\"", "'"))
|
|
|
|
|
|
|
|
return img
|