Add modification time
This commit is contained in:
parent
f7969e6134
commit
aefee81385
2
forms.py
2
forms.py
|
@ -8,7 +8,7 @@ class BlogForm(ModelForm):
|
||||||
class PostForm(ModelForm):
|
class PostForm(ModelForm):
|
||||||
class Meta:
|
class Meta:
|
||||||
model = Post
|
model = Post
|
||||||
exclude = ('title_slug', 'creation_date', 'author', 'blog', 'tags')
|
exclude = ('title_slug', 'creation_date', 'modification_date', 'author', 'blog', 'tags')
|
||||||
|
|
||||||
def __init__(self, *args, **kwargs):
|
def __init__(self, *args, **kwargs):
|
||||||
super(PostForm, self).__init__(*args, **kwargs)
|
super(PostForm, self).__init__(*args, **kwargs)
|
||||||
|
|
|
@ -31,7 +31,7 @@ class Atom(RSS):
|
||||||
self.appendElement(dom, root, 'generator', 'The Dynastie project', {'uri':'http://indefero.soutade.fr/p/dynastie', 'version':'0.1'})
|
self.appendElement(dom, root, 'generator', 'The Dynastie project', {'uri':'http://indefero.soutade.fr/p/dynastie', 'version':'0.1'})
|
||||||
self.appendElement(dom, root, 'link', '', {'rel':'self', 'type':'application/atom+xml', 'href':address + '/atom.xml'})
|
self.appendElement(dom, root, 'link', '', {'rel':'self', 'type':'application/atom+xml', 'href':address + '/atom.xml'})
|
||||||
|
|
||||||
posts = Post.objects.filter(published=True).order_by('-creation_date')[:10]
|
posts = Post.objects.filter(published=True).order_by('-modification_date')[:10]
|
||||||
|
|
||||||
for post in posts:
|
for post in posts:
|
||||||
item = dom.createElement('entry')
|
item = dom.createElement('entry')
|
||||||
|
@ -41,7 +41,8 @@ class Atom(RSS):
|
||||||
|
|
||||||
creationDate = post.creation_date.strftime('%Y-%m-%dT%H:%M:%SZ')
|
creationDate = post.creation_date.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
self.appendElement(dom, item, 'published', creationDate)
|
self.appendElement(dom, item, 'published', creationDate)
|
||||||
self.appendElement(dom, item, 'updated', creationDate)
|
modificationDate = post.modification_date.strftime('%Y-%m-%dT%H:%M:%SZ')
|
||||||
|
self.appendElement(dom, item, 'updated', modificationDate)
|
||||||
self.appendElement(dom, item, 'id', path)
|
self.appendElement(dom, item, 'id', path)
|
||||||
author = dom.createElement('author')
|
author = dom.createElement('author')
|
||||||
self.appendElement(dom, author, 'name', post.author.first_name + ' ' + post.author.last_name)
|
self.appendElement(dom, author, 'name', post.author.first_name + ' ' + post.author.last_name)
|
||||||
|
|
|
@ -40,7 +40,7 @@ class RSS(DynastieGenerator):
|
||||||
self.appendElement(dom, channel, 'generator', 'Dynastie')
|
self.appendElement(dom, channel, 'generator', 'Dynastie')
|
||||||
self.appendElement(dom, channel, 'language', 'en-gb')
|
self.appendElement(dom, channel, 'language', 'en-gb')
|
||||||
|
|
||||||
posts = Post.objects.filter(published=True).order_by('-creation_date')[:10]
|
posts = Post.objects.filter(published=True).order_by('-modification_date')[:10]
|
||||||
|
|
||||||
for post in posts:
|
for post in posts:
|
||||||
item = dom.createElement('item')
|
item = dom.createElement('item')
|
||||||
|
|
|
@ -188,6 +188,7 @@ class Post(models.Model):
|
||||||
category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL)
|
category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL)
|
||||||
published = models.BooleanField()
|
published = models.BooleanField()
|
||||||
creation_date = models.DateTimeField()
|
creation_date = models.DateTimeField()
|
||||||
|
modification_date = models.DateTimeField()
|
||||||
front_page = models.BooleanField()
|
front_page = models.BooleanField()
|
||||||
author = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
|
author = models.ForeignKey(User, null=True, on_delete=models.SET_NULL)
|
||||||
description = models.TextField(max_length=255, blank=True)
|
description = models.TextField(max_length=255, blank=True)
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<a href="/post/add/{{ blog.id }}">Add an post</a> <a href="/generate/{{ blog.id }}">Generate blog</a><br/>
|
<a href="/post/add/{{ blog.id }}">Add a post</a> <a href="/generate/{{ blog.id }}">Generate blog</a><br/>
|
||||||
{% if report|length == 0 %}
|
{% if report|length == 0 %}
|
||||||
<b style="color:red">Any engine selected</b><br/><br/>
|
<b style="color:red">Any engine selected</b><br/><br/>
|
||||||
{% else %}
|
{% else %}
|
||||||
|
|
|
@ -9,7 +9,7 @@
|
||||||
</form>
|
</form>
|
||||||
{% endif %}
|
{% endif %}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
<a href="/post/add/{{ blog.id }}">Add an post</a> <a href="/generate/{{ blog.id }}">Generate blog</a>
|
<a href="/post/add/{{ blog.id }}">Add a post</a> <a href="/generate/{{ blog.id }}">Generate blog</a>
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
{% if posts|length == 0 %}
|
{% if posts|length == 0 %}
|
||||||
<br/><br/>
|
<br/><br/>
|
||||||
|
@ -17,7 +17,7 @@
|
||||||
{% else %}
|
{% else %}
|
||||||
<table>
|
<table>
|
||||||
{% for post in posts %}
|
{% for post in posts %}
|
||||||
<tr><td><a href="/post/edit/{{ post.id }}">{{ post.id }}</a></td><td>{{ post.title }}</td><td>{{ post.category.name }}</td><td>{{ post.creation_date }}</td><td>{{ post.published }}</td><td>{{ post.front_page }}</td><td><a href="/post/delete/{{ post.id }}">Delete</a></td></tr>
|
<tr><td><a href="/post/edit/{{ post.id }}">{{ post.id }}</a></td><td>{{ post.title }}</td><td>{{ post.category.name }}</td><td>{{ post.creation_date }}</td><td>{{ post.modification_date }}</td><td>{{ post.published }}</td><td>{{ post.front_page }}</td><td><a href="/post/delete/{{ post.id }}">Delete</a></td></tr>
|
||||||
{% endfor %}
|
{% endfor %}
|
||||||
{% endif %}
|
{% endif %}
|
||||||
</table>
|
</table>
|
||||||
|
|
9
views.py
9
views.py
|
@ -142,7 +142,7 @@ def edit_category(request, category_id):
|
||||||
name = category.name
|
name = category.name
|
||||||
form = CategoryForm(request.POST, instance=category) # A form bound to the POST data
|
form = CategoryForm(request.POST, instance=category) # A form bound to the POST data
|
||||||
if form.is_valid(): # All validation rules pass
|
if form.is_valid(): # All validation rules pass
|
||||||
if form['name'] != name:
|
if request.POST['name'] != name:
|
||||||
category.remove()
|
category.remove()
|
||||||
form.save()
|
form.save()
|
||||||
else:
|
else:
|
||||||
|
@ -256,7 +256,7 @@ def add_post(request, blog_id):
|
||||||
|
|
||||||
if request.method == 'POST': # If the form has been submitted...
|
if request.method == 'POST': # If the form has been submitted...
|
||||||
if 'add' in request.POST:
|
if 'add' in request.POST:
|
||||||
post = Post(blog=Blog.objects.get(pk=blog_id), author=User.objects.get(pk=request.user.id), creation_date=datetime.now())
|
post = Post(blog=Blog.objects.get(pk=blog_id), author=User.objects.get(pk=request.user.id), creation_date=datetime.now(), modification_date=datetime.now())
|
||||||
content = request.POST['content']
|
content = request.POST['content']
|
||||||
# del request.POST['content']
|
# del request.POST['content']
|
||||||
form = PostForm(request.POST, instance=post) # A form bound to the POST data
|
form = PostForm(request.POST, instance=post) # A form bound to the POST data
|
||||||
|
@ -296,11 +296,12 @@ def edit_post(request, post_id):
|
||||||
|
|
||||||
if request.method == 'POST': # If the form has been submitted...
|
if request.method == 'POST': # If the form has been submitted...
|
||||||
if 'edit' in request.POST:
|
if 'edit' in request.POST:
|
||||||
|
post.modification_date = datetime.now()
|
||||||
form = PostForm(request.POST, instance=post) # A form bound to the POST data
|
form = PostForm(request.POST, instance=post) # A form bound to the POST data
|
||||||
if form.is_valid(): # All validation rules pass
|
if form.is_valid(): # All validation rules pass
|
||||||
if title != form['title']:
|
if title != request.POST['title']:
|
||||||
post.remove()
|
post.remove()
|
||||||
post.createPost(form['content'])
|
post.createPost(request.POST['content'])
|
||||||
form.save()
|
form.save()
|
||||||
# Process the data in form.cleaned_data
|
# Process the data in form.cleaned_data
|
||||||
# ...
|
# ...
|
||||||
|
|
Loading…
Reference in New Issue
Block a user