Merge pull request #343 from nephila/feature/featured_date
Added featured date to post
This commit is contained in:
commit
e6a40e0d62
6 changed files with 42 additions and 1 deletions
|
@ -20,6 +20,7 @@ History
|
|||
* Improved category admin to avoid circular relationships.
|
||||
* Dropped strict dependency on aldryn-search, haystack. Install separately for search support.
|
||||
* Improved admin filtering.
|
||||
* Added featured date to post.
|
||||
|
||||
*******************
|
||||
0.8.10 (2017-01-02)
|
||||
|
|
|
@ -90,7 +90,7 @@ class PostAdmin(PlaceholderAdminMixin, FrontendEditableAdminMixin,
|
|||
}),
|
||||
(_('Info'), {
|
||||
'fields': [['slug', 'tags'],
|
||||
['date_published', 'date_published_end'],
|
||||
['date_published', 'date_published_end', 'date_featured'],
|
||||
['enable_comments']],
|
||||
'classes': ('collapse',)
|
||||
}),
|
||||
|
|
20
djangocms_blog/migrations/0027_post_date_featured.py
Normal file
20
djangocms_blog/migrations/0027_post_date_featured.py
Normal file
|
@ -0,0 +1,20 @@
|
|||
# -*- coding: utf-8 -*-
|
||||
# Generated by Django 1.10.5 on 2017-01-25 11:15
|
||||
from __future__ import unicode_literals
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('djangocms_blog', '0026_merge'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AddField(
|
||||
model_name='post',
|
||||
name='date_featured',
|
||||
field=models.DateTimeField(blank=True, null=True, verbose_name='featured date'),
|
||||
),
|
||||
]
|
|
@ -142,6 +142,7 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
date_modified = models.DateTimeField(_('last modified'), auto_now=True)
|
||||
date_published = models.DateTimeField(_('published since'), null=True, blank=True)
|
||||
date_published_end = models.DateTimeField(_('published until'), null=True, blank=True)
|
||||
date_featured = models.DateTimeField(_('featured date'), null=True, blank=True)
|
||||
publish = models.BooleanField(_('publish'), default=False)
|
||||
categories = models.ManyToManyField('djangocms_blog.BlogCategory', verbose_name=_('category'),
|
||||
related_name='blog_posts', blank=True)
|
||||
|
@ -237,6 +238,12 @@ class Post(KnockerModel, ModelMeta, TranslatableModel):
|
|||
)
|
||||
return hashlib.sha256(force_bytes(base_string)).hexdigest()
|
||||
|
||||
@property
|
||||
def date(self):
|
||||
if self.date_featured:
|
||||
return self.date_featured
|
||||
return self.date_published
|
||||
|
||||
def save(self, *args, **kwargs):
|
||||
"""
|
||||
Handle some auto configuration during save
|
||||
|
|
|
@ -9,6 +9,11 @@
|
|||
<li>
|
||||
{{ post.date_published|date:"DATE_FORMAT" }}
|
||||
</li>
|
||||
{% if post.date_featured %}
|
||||
<li>
|
||||
{{ post.date_featured|date:"DATE_FORMAT" }}
|
||||
</li>
|
||||
{% endif %}
|
||||
</ul>
|
||||
<ul class="post-detail tags">
|
||||
{% if post.categories.exists %}
|
||||
|
|
|
@ -558,12 +558,20 @@ class ModelsTest(BaseTest):
|
|||
self.app_config_1.app_data.config.gplus_author = 'RandomJoe'
|
||||
self.app_config_1.save()
|
||||
|
||||
featured_date = now() + timedelta(days=40)
|
||||
|
||||
post = self._get_post(self._post_data[0]['en'])
|
||||
post = self._get_post(self._post_data[0]['it'], post, 'it')
|
||||
post.main_image = self.create_filer_image_object()
|
||||
post.publish = True
|
||||
post.save()
|
||||
post.set_current_language('en')
|
||||
self.assertEqual(post.date, post.date_published)
|
||||
|
||||
post.date_featured = featured_date
|
||||
post.save()
|
||||
self.assertEqual(post.date, featured_date)
|
||||
|
||||
meta_en = post.as_meta()
|
||||
self.assertEqual(meta_en.og_type, get_setting('FB_TYPE'))
|
||||
self.assertEqual(meta_en.title, post.title)
|
||||
|
|
Loading…
Reference in a new issue