Creates directories for articles

This commit is contained in:
Grégory Soutadé 2012-07-22 17:28:17 +02:00
parent be306c6643
commit 765c3ad19b
2 changed files with 19 additions and 3 deletions

View File

@ -52,7 +52,12 @@ class Article(DynastieGenerator):
#print 'Generate ' + filename #print 'Generate ' + filename
nodes = dom.getElementsByTagName("*") nodes = dom.getElementsByTagName("*")
self.parse(article, dom, nodes[0]) self.parse(article, dom, nodes[0])
self.writeIfNotTheSame(output + '/articles/' + article.title_slug + '.html', nodes[0].toxml('utf8')) filename = output + '/articles/'
filename = filename + article.creation_date.strftime("%Y") + '/' + article.creation_date.strftime("%m") + '/'
if not os.path.exists(filename):
os.makedirs(filename)
filename = filename + article.title_slug + '.html'
self.writeIfNotTheSame(filename, nodes[0].toxml('utf8'))
dom = parse(src + '/_article.html') dom = parse(src + '/_article.html')
if not self.somethingWrote: if not self.somethingWrote:

View File

@ -177,13 +177,24 @@ class Article(models.Model):
os.unlink(filename) os.unlink(filename)
output = b.output_path output = b.output_path
filename = output + '/articles/' + self.title_slug + '.html' filename = output + '/articles/'
filename = filename + self.creation_date.strftime("%Y") + '/' + self.creation_date.strftime("%m") + '/'
filename = filename + self.title_slug + '.html'
if os.path.exists(filename): if os.path.exists(filename):
os.unlink(filename) os.unlink(filename)
filename = filename + '.gz' filename = filename + '.gz'
if os.path.exists(filename): if os.path.exists(filename):
os.unlink(filename) os.unlink(filename)
filename = output + '/articles/'
filename = filename + self.creation_date.strftime("%Y") + '/' + self.creation_date.strftime("%m") + '/'
if len(os.listdir(filename)) == 0:
os.rmdir(filename)
filename = output + '/articles/'
filename = filename + self.creation_date.strftime("%Y") + '/'
if len(os.listdir(filename)) == 0:
os.rmdir(filename)
class Comment(models.Model): class Comment(models.Model):
article = models.ForeignKey(Article) article = models.ForeignKey(Article)