0741709259
Add dyn:ljdc_last
107 lines
3.2 KiB
Python
Executable File
107 lines
3.2 KiB
Python
Executable File
# -*- 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
|
|
from xml.dom.minidom import parse, parseString
|
|
import xml.parsers.expat
|
|
from dynastie.generators.generator import DynastieGenerator
|
|
from dynastie.generators.index import Index
|
|
from django.db import models
|
|
|
|
class LJDC(Index):
|
|
|
|
cur_page = 0
|
|
nb_pages = 0
|
|
cur_post = 0
|
|
posts_per_page = 20
|
|
filename = 'index'
|
|
dirname = '/ljdc'
|
|
cur_category = None
|
|
|
|
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]
|
|
title_value = title_value.childNodes[0].nodeValue
|
|
title = self.createElement(dom, 'title', title_value)
|
|
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
|
|
|
|
def _load_references(self, src):
|
|
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
|
|
|
|
return srcdom
|
|
|
|
def generate(self, blog, src, output):
|
|
srcdom = self._load_references(src)
|
|
|
|
if srcdom is None: return None
|
|
|
|
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
|
|
|
|
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
|