Gzip content
This commit is contained in:
parent
8d6918e108
commit
a0a4e84c2e
|
@ -1,5 +1,6 @@
|
|||
import os
|
||||
import hashlib
|
||||
import gzip
|
||||
from xml.dom import *
|
||||
|
||||
class DynastieGenerator:
|
||||
|
@ -7,6 +8,9 @@ class DynastieGenerator:
|
|||
URI = "http://indefero.soutade.fr/p/dynastie"
|
||||
report = ''
|
||||
|
||||
def __init__(self):
|
||||
self.report = ''
|
||||
|
||||
def addReport(self, string, color=''):
|
||||
if color != '':
|
||||
self.report = self.report + '<span style="color:' + color + '">'
|
||||
|
@ -37,6 +41,12 @@ class DynastieGenerator:
|
|||
|
||||
if src_md5.digest() == dst_md5.digest():
|
||||
self.addReport(filename + ' regenerated with the same content, skipping...')
|
||||
filename = filename + '.gz'
|
||||
if not os.path.exists(filename):
|
||||
self.addReport(filename + ' was not previously compressed')
|
||||
f = gzip.open(filename, 'wb')
|
||||
f.write(content)
|
||||
f.close()
|
||||
return
|
||||
os.unlink(filename)
|
||||
|
||||
|
@ -45,6 +55,11 @@ class DynastieGenerator:
|
|||
f.write(content)
|
||||
f.close()
|
||||
|
||||
filename = filename + '.gz'
|
||||
self.addReport('Compressing it ' + filename)
|
||||
f = gzip.open(filename, 'wb')
|
||||
f.write(content)
|
||||
f.close()
|
||||
|
||||
def createElement(self, dom, name, content):
|
||||
div = dom.createElement('div')
|
||||
|
|
|
@ -43,8 +43,6 @@ class Index(DynastieGenerator):
|
|||
def generate(self, blog, src, output):
|
||||
from dynastie.models import *
|
||||
|
||||
self.report = ''
|
||||
|
||||
if not os.path.exists(src + '/_index.html'):
|
||||
self.addError('No _index.html found, exiting')
|
||||
return self.report
|
||||
|
@ -80,6 +78,10 @@ class Index(DynastieGenerator):
|
|||
while os.path.exists(filename):
|
||||
self.addReport('Removing unused ' + filename)
|
||||
os.unlink(filename)
|
||||
filename = filename + '.gz'
|
||||
if os.path.exists(filename):
|
||||
self.addReport('Removing unused ' + filename)
|
||||
os.unlink(filename)
|
||||
self.cur_page = self.cur_page + 1
|
||||
filename = 'index' + str(self.cur_page) + '.html'
|
||||
|
||||
|
|
14
models.py
14
models.py
|
@ -145,17 +145,3 @@ def delete_blog_signal(sender, **kwargs):
|
|||
@receiver(post_delete, sender=Blog)
|
||||
def delete_blog_signal(sender, **kwargs):
|
||||
sender.remove()
|
||||
|
||||
@receiver(post_delete, sender=Article)
|
||||
def delete_article_signal(sender, **kwargs):
|
||||
kwargs["instance"].blog.create_paths()
|
||||
kwargs["instance"].blog.generate()
|
||||
# b = Blog.objects.filter(pk=kwargs["instance"].blog.id)
|
||||
# b.generate()
|
||||
|
||||
@receiver(post_save, sender=Article)
|
||||
def save_article_signal(sender, **kwargs):
|
||||
kwargs["instance"].blog.create_paths()
|
||||
kwargs["instance"].blog.generate()
|
||||
# b = Blog.objects.filter(pk=kwargs["instance"].blog.id)
|
||||
# b.generate()
|
||||
|
|
|
@ -1,6 +1,15 @@
|
|||
{% extends "templates/base.html" %}
|
||||
|
||||
{% block content %}
|
||||
{% if user.is_superuser %}
|
||||
<form action="/blog/edit/{{ blog.id }}" method="post">
|
||||
{% csrf_token %}
|
||||
{{ form.as_p }}
|
||||
<input type="submit" name="edit" value="Edit" /><input type="submit" name="delete" value="Delete" />
|
||||
</form>
|
||||
{% endif %}
|
||||
<br/><br/>
|
||||
<a href="/article/add/{{ blog.id }}">Add an article</a> <a href="/generate/{{ blog.id }}">Generate blog</a><br/>
|
||||
{% if report|length == 0 %}
|
||||
<b style="color:red">Any engine selected</b><br/><br/>
|
||||
{% else %}
|
||||
|
@ -8,4 +17,14 @@
|
|||
{{ report }}
|
||||
{% endautoescape %}
|
||||
{% endif %}
|
||||
{% if articles|length == 0 %}
|
||||
<br/><br/>
|
||||
<b>Any article available</b><br/><br/>
|
||||
{% else %}
|
||||
<table>
|
||||
{% for article in articles %}
|
||||
<hr><hl><a href="/article/edit/{{ article.id }}">{{ article.id }}</a></hl><hl>{{ article.title }}</hl><hl>{{ article.category.name }}</hl><hl>{{ article.creation_date }}</hl><hl>{{ article.published }}</hl><hl>{{ article.front_page }}</hl><hl><a href="/article/delete/{{ article.id }}">Delete</a></hl></hr>
|
||||
{% endfor %}
|
||||
{% endif %}
|
||||
</table>
|
||||
{% endblock %}
|
||||
|
|
|
@ -9,7 +9,7 @@
|
|||
</form>
|
||||
{% endif %}
|
||||
<br/><br/>
|
||||
<a href="/article/add/{{ blog.id }}">Add an article</a>
|
||||
<a href="/article/add/{{ blog.id }}">Add an article</a> <a href="/generate/{{ blog.id }}">Generate blog</a>
|
||||
{% if articles|length == 0 %}
|
||||
<br/><br/>
|
||||
<b>Any article available</b><br/><br/>
|
||||
|
|
Loading…
Reference in New Issue
Block a user