diff --git a/forms.py b/forms.py index ba62ab2..7cc8f75 100644 --- a/forms.py +++ b/forms.py @@ -8,7 +8,7 @@ class BlogForm(ModelForm): class PostForm(ModelForm): class Meta: 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): super(PostForm, self).__init__(*args, **kwargs) diff --git a/generators/atom.py b/generators/atom.py index 313f9c2..c569798 100644 --- a/generators/atom.py +++ b/generators/atom.py @@ -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, '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: item = dom.createElement('entry') @@ -41,7 +41,8 @@ class Atom(RSS): creationDate = post.creation_date.strftime('%Y-%m-%dT%H:%M:%SZ') 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) author = dom.createElement('author') self.appendElement(dom, author, 'name', post.author.first_name + ' ' + post.author.last_name) diff --git a/generators/rss.py b/generators/rss.py index 9576283..3f50ea8 100644 --- a/generators/rss.py +++ b/generators/rss.py @@ -40,7 +40,7 @@ class RSS(DynastieGenerator): self.appendElement(dom, channel, 'generator', 'Dynastie') 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: item = dom.createElement('item') diff --git a/models.py b/models.py index 241380c..3575f66 100644 --- a/models.py +++ b/models.py @@ -188,6 +188,7 @@ class Post(models.Model): category = models.ForeignKey(Category, blank=True, null=True, on_delete=models.SET_NULL) published = models.BooleanField() creation_date = models.DateTimeField() + modification_date = models.DateTimeField() front_page = models.BooleanField() author = models.ForeignKey(User, null=True, on_delete=models.SET_NULL) description = models.TextField(max_length=255, blank=True) diff --git a/templates/generate.html b/templates/generate.html index ed6d008..0927dd2 100644 --- a/templates/generate.html +++ b/templates/generate.html @@ -9,7 +9,7 @@ {% endif %}

-Add an post Generate blog
+Add a post Generate blog
{% if report|length == 0 %} Any engine selected

{% else %} diff --git a/templates/view_blog.html b/templates/view_blog.html index 5be985f..b006f24 100644 --- a/templates/view_blog.html +++ b/templates/view_blog.html @@ -9,7 +9,7 @@ {% endif %}

-Add an post Generate blog +Add a post Generate blog

{% if posts|length == 0 %}

@@ -17,7 +17,7 @@ {% else %} {% for post in posts %} - + {% endfor %} {% endif %}
{{ post.id }}{{ post.title }}{{ post.category.name }}{{ post.creation_date }}{{ post.published }}{{ post.front_page }}Delete
{{ post.id }}{{ post.title }}{{ post.category.name }}{{ post.creation_date }}{{ post.modification_date }}{{ post.published }}{{ post.front_page }}Delete
diff --git a/views.py b/views.py index e1909d7..b5d4471 100644 --- a/views.py +++ b/views.py @@ -142,7 +142,7 @@ def edit_category(request, category_id): name = category.name form = CategoryForm(request.POST, instance=category) # A form bound to the POST data if form.is_valid(): # All validation rules pass - if form['name'] != name: + if request.POST['name'] != name: category.remove() form.save() else: @@ -256,7 +256,7 @@ def add_post(request, blog_id): if request.method == 'POST': # If the form has been submitted... 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'] # del request.POST['content'] 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 'edit' in request.POST: + post.modification_date = datetime.now() form = PostForm(request.POST, instance=post) # A form bound to the POST data if form.is_valid(): # All validation rules pass - if title != form['title']: + if title != request.POST['title']: post.remove() - post.createPost(form['content']) + post.createPost(request.POST['content']) form.save() # Process the data in form.cleaned_data # ...