diff --git a/newsbox/admin.py b/newsbox/admin.py index 76d42f7f15ee708531fb7a23edf8037f1e59712d..26e547ba7e6047a77d04db38aa879e74d5956f4f 100644 --- a/newsbox/admin.py +++ b/newsbox/admin.py @@ -143,8 +143,6 @@ class NewsboxBaseAdmin(admin.ModelAdmin): changestatus_link.short_description = _('published') def newsbox_date_short(self, obj): - if not obj.newsbox_publication_start_date: - return None return '<span title="%s">%s</span>' % ( formats.date_format(obj.newsbox_publication_start_date, 'DATETIME_FORMAT'), formats.date_format(obj.newsbox_publication_start_date, 'SHORT_DATE_FORMAT') @@ -318,20 +316,15 @@ class NewsboxAdmin(NewsboxBaseAdmin): class NewsboxExpiredAdmin(NewsboxBaseAdmin): def newsbox_publication_dates_short(self, obj): - if not obj.newsbox_publication_end_date and not obj.newsbox_publication_start_date: - return None output = [] title = [] css_class = [] - if not obj.newsbox_publication_start_date: - title.append(_('always')) - else: - title.append(formats.date_format(obj.newsbox_publication_start_date, - 'DATETIME_FORMAT')) - output.append('<span class="from">%s</span>' % - formats.date_format(obj.newsbox_publication_start_date, - 'SHORT_DATE_FORMAT')) - css_class.append('from') + title.append(formats.date_format(obj.newsbox_publication_start_date, + 'DATETIME_FORMAT')) + output.append('<span class="from">%s</span>' % + formats.date_format(obj.newsbox_publication_start_date, + 'SHORT_DATE_FORMAT')) + css_class.append('from') if not obj.newsbox_publication_end_date: title.append(_('never')) else: diff --git a/newsbox/models.py b/newsbox/models.py index d6bda6fdf47bdae1e388b648f4d78b37a65452dd..08f6f06acb8c72d2597479267a21e95363adafbf 100644 --- a/newsbox/models.py +++ b/newsbox/models.py @@ -168,6 +168,7 @@ class NewsboxBase(six.with_metaclass(NewsboxModelBase, models.Model)): # event datetime newsbox_date = models.DateTimeField( verbose_name=_('date'), + help_text=_('Date of the event related to this news'), default=None, db_index=False, null=True, blank=True, ) @@ -178,7 +179,8 @@ class NewsboxBase(six.with_metaclass(NewsboxModelBase, models.Model)): default=datetime.now, db_index=True, help_text=_( 'When the news should go live. ' - 'Status must be "Published" for news to go live.')) + 'Status must be "Published" for news to go live.'), + null=False, blank=False) newsbox_published = models.BooleanField( verbose_name=_('published'), @@ -188,6 +190,22 @@ class NewsboxBase(six.with_metaclass(NewsboxModelBase, models.Model)): default_manager = NewsboxManager() objects = default_manager + class Meta: + abstract = True + verbose_name = _('news') + verbose_name_plural = _('news') + ordering = ('-newsbox_publication_start_date', ) + newsbox_metaclass_base_processor = 'newsbox_mcls_processor' + + @classmethod + def q_published(cls): + now = datetime.utcnow().replace(tzinfo=utc) + # Only published News + q = models.Q(newsbox_published=True) + # exclude news with publication start date in the future + q &= models.Q(newsbox_publication_start_date__lte=now) + return q + def __str__(self): return six.text_type(self.newsbox_title) @@ -207,7 +225,7 @@ class NewsboxBase(six.with_metaclass(NewsboxModelBase, models.Model)): if isinstance(self, NewsboxExpiredBase): now = datetime.utcnow().replace(tzinfo=utc) - if self.newsbox_publication_start_date and now < self.newsbox_publication_start_date: + if now < self.newsbox_publication_start_date: return False if self.newsbox_publication_end_date and now > self.newsbox_publication_end_date: return False @@ -224,21 +242,11 @@ class NewsboxBase(six.with_metaclass(NewsboxModelBase, models.Model)): self.newsbox_publication_start_date.strftime("%d"), self.get_slug(),)) - @classmethod - def q_published(cls): - now = datetime.utcnow().replace(tzinfo=utc) - # Only published News - q = models.Q(newsbox_published=True) - # exclude news with publication start date in the future - q &= models.Q(newsbox_publication_start_date__lte=now) - return q - - class Meta: - abstract = True - verbose_name = _('news') - verbose_name_plural = _('news') - ordering = ('-newsbox_publication_start_date', ) - newsbox_metaclass_base_processor = 'newsbox_mcls_processor' + def save(self, *args, **kwargs): + # be sure to have a publication start date + if not self.newsbox_publication_start_date: + self.newsbox_publication_start_date = self.newsbox_creation_date + super(NewsboxBase, self).save(*args, **kwargs) class NewsboxExpiredBase(six.with_metaclass(NewsboxModelBase, models.Model)): diff --git a/newsbox/views.py b/newsbox/views.py index 27c0bc87ce4127bf4ab4f82b8f6f08603fc5e592..c76770f28e064bb7b4e69fc86091f000f6e4a206 100644 --- a/newsbox/views.py +++ b/newsbox/views.py @@ -92,9 +92,6 @@ class NewsboxDetailView(DateDetailView): def get_object(self, queryset=None): # We check user permission obj = super(NewsboxDetailView, self).get_object(queryset) - if( - not obj.is_published() and - not obj.has_change_permission(self.request) - ): + if not obj.is_published() and not obj.has_change_permission(self.request): raise Http404 return obj diff --git a/newsbox_i18n/views.py b/newsbox_i18n/views.py index 52e14e0b7a6ce6639d6412b5fa80fcbf4526b18e..7a94df5d7a07b310d11a4c9b9facd4b183516840 100644 --- a/newsbox_i18n/views.py +++ b/newsbox_i18n/views.py @@ -26,7 +26,5 @@ class NewsboxI18NDetailView(NewsboxDetailView): if not queryset: queryset = self.get_queryset() language = get_language() - obj = queryset.translated(language, newsbox_slug=self.kwargs[self.slug_url_kwarg]).get() - if not obj.is_published() and not obj.has_change_permission(self.request): - raise Http404 - return obj + queryset = queryset.translated(language, newsbox_slug=self.kwargs[self.slug_url_kwarg]) + return super(NewsboxI18NDetailView, self).get_object(queryset=queryset) diff --git a/tests/myapp/fixtures/tests_data.json b/tests/myapp/fixtures/tests_data.json index fe8b54af098a93df032407c6616e0dcfff7daebb..bf53a2cacfd5f4f7d4a9e91012d092036a7cc7f0 100644 --- a/tests/myapp/fixtures/tests_data.json +++ b/tests/myapp/fixtures/tests_data.json @@ -5,12 +5,12 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-1", - "newsbox_creation_date": "2014-03-11T13:54:03.213Z", - "newsbox_publication_start_date": "1985-07-02T08:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_creation_date": "2014-03-01T13:54:03.213Z", + "newsbox_publication_start_date": "2014-03-01T13:54:03.213Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 1", "newsbox_body": "Body of the news 1", - "newsbox_changed_date": "2014-03-11T13:54:03.213Z", + "newsbox_changed_date": "2014-03-01T13:54:03.213Z", "newsbox_title": "News 1" } }, @@ -20,12 +20,12 @@ "fields": { "newsbox_published": false, "newsbox_slug": "news-2", - "newsbox_creation_date": "2014-03-11T13:54:03.398Z", - "newsbox_publication_start_date": "1985-07-02T09:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_creation_date": "2014-03-02T13:54:03.398Z", + "newsbox_publication_start_date": "2014-03-02T13:54:03.398Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 2", "newsbox_body": "Body of the news 2", - "newsbox_changed_date": "2014-03-11T13:54:03.398Z", + "newsbox_changed_date": "2014-03-02T13:54:03.398Z", "newsbox_title": "News 2" } }, @@ -35,12 +35,12 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-3", - "newsbox_creation_date": "2014-03-11T13:54:03.598Z", + "newsbox_creation_date": "2014-03-03T13:54:03.598Z", "newsbox_publication_start_date": "2020-01-01T08:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 3", "newsbox_body": "Body of the news 3", - "newsbox_changed_date": "2014-03-11T13:54:03.598Z", + "newsbox_changed_date": "2014-03-03T13:54:03.598Z", "newsbox_title": "News 3" } }, @@ -50,12 +50,12 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-4", - "newsbox_creation_date": "2014-03-11T13:54:03.882Z", - "newsbox_publication_start_date": "1985-07-02T10:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_creation_date": "2014-03-04T13:54:03.882Z", + "newsbox_publication_start_date": "2014-03-04T13:54:03.882Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 4", "newsbox_body": "", - "newsbox_changed_date": "2014-03-11T13:54:03.882Z", + "newsbox_changed_date": "2014-03-04T13:54:03.882Z", "newsbox_title": "News 4" } }, @@ -65,12 +65,12 @@ "fields": { "newsbox_published": false, "newsbox_slug": "news-5", - "newsbox_creation_date": "2014-03-11T13:54:04.083Z", - "newsbox_publication_start_date": "1985-07-02T11:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_creation_date": "2014-03-05T13:54:04.083Z", + "newsbox_publication_start_date": "2014-03-05T13:54:04.083Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 5", "newsbox_body": "Body of the news 5", - "newsbox_changed_date": "2014-03-11T13:54:04.083Z", + "newsbox_changed_date": "2014-03-05T13:54:04.083Z", "newsbox_title": "News 5" } }, @@ -80,12 +80,12 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-6", - "newsbox_creation_date": "2014-03-11T13:54:04.293Z", - "newsbox_publication_start_date": "1985-07-02T12:00:00Z", - "newsbox_date": "2005-07-15T08:00:00Z", + "newsbox_creation_date": "2014-03-06T13:54:04.293Z", + "newsbox_publication_start_date": "2005-07-15T08:00:00Z", + "newsbox_date": "2028-01-01T08:00:00Z", "newsbox_summary": "Summary of the news 6", "newsbox_body": "Body of the news 6", - "newsbox_changed_date": "2014-03-11T13:54:04.293Z", + "newsbox_changed_date": "2014-03-06T13:54:04.293Z", "newsbox_title": "News 6" } }, @@ -95,12 +95,12 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-7", - "newsbox_creation_date": "2014-03-11T13:54:04.502Z", - "newsbox_publication_start_date": "1985-07-02T13:00:00Z", - "newsbox_date": "2020-01-01T08:00:00Z", + "newsbox_creation_date": "2014-03-07T13:54:04.502Z", + "newsbox_publication_start_date": "2014-03-07T13:54:04.502Z", + "newsbox_date": "1985-07-02T23:50:00Z", "newsbox_summary": "Summary of the news 7", "newsbox_body": "Body of the news 7", - "newsbox_changed_date": "2014-03-11T13:54:04.503Z", + "newsbox_changed_date": "2014-03-07T13:54:04.503Z", "newsbox_title": "News 7" } }, @@ -111,14 +111,14 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 1", "newsbox_slug": "news-1", - "newsbox_creation_date": "2014-03-11T13:54:01.813Z", - "newsbox_publication_start_date": "1985-07-02T08:00:00Z", + "newsbox_creation_date": "2014-03-01T13:54:01.813Z", + "newsbox_publication_start_date": "2014-03-01T13:54:01.813Z", "newsbox_meta_keywords": "keyword1, keyword2, news-1", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 1", "newsbox_body": "Body of the news 1", - "newsbox_changed_date": "2014-03-11T13:54:01.813Z", + "newsbox_changed_date": "2014-03-01T13:54:01.813Z", "newsbox_title": "News 1" } }, @@ -129,14 +129,14 @@ "newsbox_published": false, "newsbox_meta_description": "Meta description of the news 2", "newsbox_slug": "news-2", - "newsbox_creation_date": "2014-03-11T13:54:02.005Z", - "newsbox_publication_start_date": "1985-07-02T09:00:00Z", + "newsbox_creation_date": "2014-03-02T13:54:02.005Z", + "newsbox_publication_start_date": "2014-03-02T13:54:02.005Z", "newsbox_meta_keywords": "keyword1, keyword2, news-2", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 2", "newsbox_body": "Body of the news 2", - "newsbox_changed_date": "2014-03-11T13:54:02.005Z", + "newsbox_changed_date": "2014-03-02T13:54:02.005Z", "newsbox_title": "News 2" } }, @@ -147,14 +147,14 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 3", "newsbox_slug": "news-3", - "newsbox_creation_date": "2014-03-11T13:54:02.201Z", + "newsbox_creation_date": "2014-03-03T13:54:02.201Z", "newsbox_publication_start_date": "2020-01-01T08:00:00Z", "newsbox_meta_keywords": "keyword1, keyword2, news-3", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 3", "newsbox_body": "Body of the news 3", - "newsbox_changed_date": "2014-03-11T13:54:02.201Z", + "newsbox_changed_date": "2014-03-03T13:54:02.201Z", "newsbox_title": "News 3" } }, @@ -165,14 +165,14 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 4", "newsbox_slug": "news-4", - "newsbox_creation_date": "2014-03-11T13:54:02.408Z", - "newsbox_publication_start_date": "1985-07-02T10:00:00Z", + "newsbox_creation_date": "2014-03-04T13:54:02.408Z", + "newsbox_publication_start_date": "2014-03-04T13:54:02.408Z", "newsbox_meta_keywords": "keyword1, keyword2, news-4", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 4", "newsbox_body": "", - "newsbox_changed_date": "2014-03-11T13:54:02.408Z", + "newsbox_changed_date": "2014-03-04T13:54:02.408Z", "newsbox_title": "News 4" } }, @@ -183,14 +183,14 @@ "newsbox_published": false, "newsbox_meta_description": "Meta description of the news 5", "newsbox_slug": "news-5", - "newsbox_creation_date": "2014-03-11T13:54:02.602Z", - "newsbox_publication_start_date": "1985-07-02T11:00:00Z", + "newsbox_creation_date": "2014-03-05T13:54:02.602Z", + "newsbox_publication_start_date": "2014-03-05T13:54:02.408Z", "newsbox_meta_keywords": "keyword1, keyword2, news-5", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 5", "newsbox_body": "Body of the news 5", - "newsbox_changed_date": "2014-03-11T13:54:02.602Z", + "newsbox_changed_date": "2014-03-05T13:54:02.602Z", "newsbox_title": "News 5" } }, @@ -201,14 +201,14 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 6", "newsbox_slug": "news-6", - "newsbox_creation_date": "2014-03-11T13:54:02.810Z", - "newsbox_publication_start_date": "1985-07-02T12:00:00Z", + "newsbox_creation_date": "2014-03-06T13:54:02.810Z", + "newsbox_publication_start_date": "2005-07-15T08:00:00Z", "newsbox_meta_keywords": "keyword1, keyword2, news-6", - "newsbox_date": "2005-07-15T08:00:00Z", + "newsbox_date": "2028-01-01T08:00:00Z", "newsbox_indexed": false, "newsbox_summary": "Summary of the news 6", "newsbox_body": "Body of the news 6", - "newsbox_changed_date": "2014-03-11T13:54:02.810Z", + "newsbox_changed_date": "2014-03-06T13:54:02.810Z", "newsbox_title": "News 6" } }, @@ -219,14 +219,14 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 7", "newsbox_slug": "news-7", - "newsbox_creation_date": "2014-03-11T13:54:03.019Z", - "newsbox_publication_start_date": "1985-07-02T13:00:00Z", + "newsbox_creation_date": "2014-03-07T13:54:03.019Z", + "newsbox_publication_start_date": "2014-03-07T13:54:03.019Z", "newsbox_meta_keywords": "keyword1, keyword2, news-7", - "newsbox_date": "2020-01-01T08:00:00Z", + "newsbox_date": "1985-07-02T23:50:00Z", "newsbox_indexed": true, "newsbox_summary": "Summary of the news 7", "newsbox_body": "Body of the news 7", - "newsbox_changed_date": "2014-03-11T13:54:03.019Z", + "newsbox_changed_date": "2014-03-07T13:54:03.019Z", "newsbox_title": "News 7" } }, @@ -236,10 +236,10 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-1", - "newsbox_changed_date": "2014-03-11T13:53:50.409Z", - "newsbox_creation_date": "2014-03-11T13:53:50.409Z", - "newsbox_publication_start_date": "1985-07-02T08:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_changed_date": "2014-03-01T13:53:50.409Z", + "newsbox_creation_date": "2014-03-01T13:53:50.409Z", + "newsbox_publication_start_date": "2014-03-01T13:53:50.409Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 1", "newsbox_body": "Body of the news 1", "newsbox_publication_end_date": null, @@ -252,10 +252,10 @@ "fields": { "newsbox_published": false, "newsbox_slug": "news-2", - "newsbox_changed_date": "2014-03-11T13:53:50.593Z", - "newsbox_creation_date": "2014-03-11T13:53:50.593Z", - "newsbox_publication_start_date": "1985-07-02T09:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_changed_date": "2014-03-02T13:53:50.593Z", + "newsbox_creation_date": "2014-03-02T13:53:50.593Z", + "newsbox_publication_start_date": "2014-03-02T13:53:50.593Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 2", "newsbox_body": "Body of the news 2", "newsbox_publication_end_date": null, @@ -268,10 +268,10 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-3", - "newsbox_changed_date": "2014-03-11T13:53:50.795Z", - "newsbox_creation_date": "2014-03-11T13:53:50.795Z", + "newsbox_changed_date": "2014-03-03T13:53:50.795Z", + "newsbox_creation_date": "2014-03-03T13:53:50.795Z", "newsbox_publication_start_date": "2020-01-01T08:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 3", "newsbox_body": "Body of the news 3", "newsbox_publication_end_date": null, @@ -284,10 +284,10 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-4", - "newsbox_changed_date": "2014-03-11T13:53:50.988Z", - "newsbox_creation_date": "2014-03-11T13:53:50.988Z", - "newsbox_publication_start_date": "1985-07-02T10:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_changed_date": "2014-03-04T13:53:50.988Z", + "newsbox_creation_date": "2014-03-04T13:53:50.988Z", + "newsbox_publication_start_date": "2014-03-04T13:53:50.988Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 4", "newsbox_body": "", "newsbox_publication_end_date": null, @@ -300,13 +300,13 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-5", - "newsbox_changed_date": "2014-03-11T13:53:51.196Z", - "newsbox_creation_date": "2014-03-11T13:53:51.196Z", - "newsbox_publication_start_date": "1985-07-02T11:00:00Z", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_changed_date": "2014-03-05T13:53:51.196Z", + "newsbox_creation_date": "2014-03-05T13:53:51.196Z", + "newsbox_publication_start_date": "2014-03-05T13:53:51.196Z", + "newsbox_date": null, "newsbox_summary": "Summary of the news 5", "newsbox_body": "Body of the news 5", - "newsbox_publication_end_date": "2000-01-01T08:00:00Z", + "newsbox_publication_end_date": "2014-06-01T08:00:00Z", "newsbox_title": "News 5" } }, @@ -316,10 +316,10 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-6", - "newsbox_changed_date": "2014-03-11T13:53:51.406Z", - "newsbox_creation_date": "2014-03-11T13:53:51.406Z", - "newsbox_publication_start_date": "1985-07-02T12:00:00Z", - "newsbox_date": "2005-07-15T08:00:00Z", + "newsbox_changed_date": "2014-03-06T13:53:51.406Z", + "newsbox_creation_date": "2014-03-06T13:53:51.406Z", + "newsbox_publication_start_date": "2005-07-15T08:00:00Z", + "newsbox_date": "2028-01-01T08:00:00Z", "newsbox_summary": "Summary of the news 6", "newsbox_body": "Body of the news 6", "newsbox_publication_end_date": null, @@ -332,13 +332,13 @@ "fields": { "newsbox_published": true, "newsbox_slug": "news-7", - "newsbox_changed_date": "2014-03-11T13:53:51.589Z", - "newsbox_creation_date": "2014-03-11T13:53:51.589Z", - "newsbox_publication_start_date": "1985-07-02T13:00:00Z", - "newsbox_date": "2020-01-01T08:00:00Z", + "newsbox_changed_date": "2014-03-07T13:53:51.589Z", + "newsbox_creation_date": "2014-03-07T13:53:51.589Z", + "newsbox_publication_start_date": "2014-03-07T13:53:51.589Z", + "newsbox_date": "1985-07-02T23:50:00Z", "newsbox_summary": "Summary of the news 7", "newsbox_body": "Body of the news 7", - "newsbox_publication_end_date": null, + "newsbox_publication_end_date": "2020-03-07T13:53:51.589Z", "newsbox_title": "News 7" } }, @@ -349,11 +349,11 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 1", "newsbox_slug": "news-1", - "newsbox_changed_date": "2014-03-11T13:53:28.605Z", - "newsbox_creation_date": "2014-03-11T13:53:28.605Z", - "newsbox_publication_start_date": "1985-07-02T08:00:00Z", + "newsbox_changed_date": "2014-03-01T13:53:28.605Z", + "newsbox_creation_date": "2014-03-01T13:53:28.605Z", + "newsbox_publication_start_date": "2014-03-01T13:53:28.605Z", "newsbox_meta_keywords": "keyword1, keyword2, news-1", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 1", "newsbox_body": "Body of the news 1", @@ -368,11 +368,11 @@ "newsbox_published": false, "newsbox_meta_description": "Meta description of the news 2", "newsbox_slug": "news-2", - "newsbox_changed_date": "2014-03-11T13:53:28.763Z", - "newsbox_creation_date": "2014-03-11T13:53:28.763Z", - "newsbox_publication_start_date": "1985-07-02T09:00:00Z", + "newsbox_changed_date": "2014-03-02T13:53:28.763Z", + "newsbox_creation_date": "2014-03-02T13:53:28.763Z", + "newsbox_publication_start_date": "2014-03-02T13:53:28.605Z", "newsbox_meta_keywords": "keyword1, keyword2, news-2", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 2", "newsbox_body": "Body of the news 2", @@ -387,11 +387,11 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 3", "newsbox_slug": "news-3", - "newsbox_changed_date": "2014-03-11T13:53:28.947Z", - "newsbox_creation_date": "2014-03-11T13:53:28.947Z", + "newsbox_changed_date": "2014-03-03T13:53:28.947Z", + "newsbox_creation_date": "2014-03-03T13:53:28.947Z", "newsbox_publication_start_date": "2020-01-01T08:00:00Z", "newsbox_meta_keywords": "keyword1, keyword2, news-3", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 3", "newsbox_body": "Body of the news 3", @@ -406,11 +406,11 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 4", "newsbox_slug": "news-4", - "newsbox_changed_date": "2014-03-11T13:53:29.125Z", - "newsbox_creation_date": "2014-03-11T13:53:29.125Z", - "newsbox_publication_start_date": "1985-07-02T10:00:00Z", + "newsbox_changed_date": "2014-03-04T13:53:29.125Z", + "newsbox_creation_date": "2014-03-04T13:53:29.125Z", + "newsbox_publication_start_date": "2014-03-04T13:53:28.605Z", "newsbox_meta_keywords": "keyword1, keyword2, news-4", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 4", "newsbox_body": "", @@ -425,11 +425,11 @@ "newsbox_published": false, "newsbox_meta_description": "Meta description of the news 5", "newsbox_slug": "news-5", - "newsbox_changed_date": "2014-03-11T13:53:29.368Z", - "newsbox_creation_date": "2014-03-11T13:53:29.368Z", - "newsbox_publication_start_date": "1985-07-02T11:00:00Z", + "newsbox_changed_date": "2014-03-05T13:53:29.368Z", + "newsbox_creation_date": "2014-03-05T13:53:29.368Z", + "newsbox_publication_start_date": "2014-03-05T13:53:28.605Z", "newsbox_meta_keywords": "keyword1, keyword2, news-5", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "newsbox_indexed": true, "newsbox_summary": "Summary of the news 5", "newsbox_body": "Body of the news 5", @@ -444,11 +444,11 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 6", "newsbox_slug": "news-6", - "newsbox_changed_date": "2014-03-11T13:53:29.594Z", - "newsbox_creation_date": "2014-03-11T13:53:29.594Z", - "newsbox_publication_start_date": "1985-07-02T12:00:00Z", + "newsbox_changed_date": "2014-03-06T13:53:29.594Z", + "newsbox_creation_date": "2014-03-06T13:53:29.594Z", + "newsbox_publication_start_date": "2005-07-15T08:00:00Z", "newsbox_meta_keywords": "keyword1, keyword2, news-6", - "newsbox_date": "2005-07-15T08:00:00Z", + "newsbox_date": "2028-01-01T08:00:00Z", "newsbox_indexed": false, "newsbox_summary": "Summary of the news 6", "newsbox_body": "Body of the news 6", @@ -463,15 +463,15 @@ "newsbox_published": true, "newsbox_meta_description": "Meta description of the news 7", "newsbox_slug": "news-7", - "newsbox_changed_date": "2014-03-11T13:53:29.787Z", - "newsbox_creation_date": "2014-03-11T13:53:29.787Z", - "newsbox_publication_start_date": "1985-07-02T13:00:00Z", + "newsbox_changed_date": "2014-03-07T13:53:29.787Z", + "newsbox_creation_date": "2014-03-07T13:53:29.787Z", + "newsbox_publication_start_date": "2014-03-07T13:53:28.605Z", "newsbox_meta_keywords": "keyword1, keyword2, news-7", - "newsbox_date": "2020-01-01T08:00:00Z", + "newsbox_date": "1985-07-02T23:50:00Z", "newsbox_indexed": true, "newsbox_summary": "Summary of the news 7", "newsbox_body": "Body of the news 7", - "newsbox_publication_end_date": null, + "newsbox_publication_end_date": "2020-03-07T13:53:51.589Z", "newsbox_title": "News 7" } }, @@ -482,11 +482,11 @@ "newsbox_published": true, "content_field": "Extra content of the news 1", "newsbox_slug": "news-1", - "newsbox_changed_date": "2014-03-11T13:53:49.052Z", - "newsbox_creation_date": "2014-03-11T13:53:49.052Z", - "newsbox_publication_start_date": "1985-07-02T08:00:00Z", + "newsbox_changed_date": "2014-03-01T13:53:49.052Z", + "newsbox_creation_date": "2014-03-01T13:53:49.052Z", + "newsbox_publication_start_date": "2014-03-01T13:53:49.052Z", "newsbox_meta_keywords": "keyword1, keyword2, news-1", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "general_field": "Test", "newsbox_indexed": true, "seo_field": "Extra SEO of the news 1", @@ -504,11 +504,11 @@ "newsbox_published": false, "content_field": "Extra content of the news 2", "newsbox_slug": "news-2", - "newsbox_changed_date": "2014-03-11T13:53:49.243Z", - "newsbox_creation_date": "2014-03-11T13:53:49.243Z", - "newsbox_publication_start_date": "1985-07-02T09:00:00Z", + "newsbox_changed_date": "2014-03-02T13:53:49.243Z", + "newsbox_creation_date": "2014-03-02T13:53:49.243Z", + "newsbox_publication_start_date": "2014-03-02T13:53:49.052Z", "newsbox_meta_keywords": "keyword1, keyword2, news-2", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "general_field": "Test", "newsbox_indexed": true, "seo_field": "Extra SEO of the news 2", @@ -526,11 +526,11 @@ "newsbox_published": true, "content_field": "Extra content of the news 3", "newsbox_slug": "news-3", - "newsbox_changed_date": "2014-03-11T13:53:49.445Z", - "newsbox_creation_date": "2014-03-11T13:53:49.445Z", + "newsbox_changed_date": "2014-03-03T13:53:49.445Z", + "newsbox_creation_date": "2014-03-03T13:53:49.445Z", "newsbox_publication_start_date": "2020-01-01T08:00:00Z", "newsbox_meta_keywords": "keyword1, keyword2, news-3", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "general_field": "Test", "newsbox_indexed": true, "seo_field": "Extra SEO of the news 3", @@ -548,11 +548,11 @@ "newsbox_published": true, "content_field": "Extra content of the news 4", "newsbox_slug": "news-4", - "newsbox_changed_date": "2014-03-11T13:53:49.629Z", - "newsbox_creation_date": "2014-03-11T13:53:49.629Z", - "newsbox_publication_start_date": "1985-07-02T10:00:00Z", + "newsbox_changed_date": "2014-03-04T13:53:49.629Z", + "newsbox_creation_date": "2014-03-04T13:53:49.629Z", + "newsbox_publication_start_date": "2014-03-04T13:53:49.052Z", "newsbox_meta_keywords": "keyword1, keyword2, news-4", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "general_field": "Test", "newsbox_indexed": true, "seo_field": "Extra SEO of the news 4", @@ -570,11 +570,11 @@ "newsbox_published": false, "content_field": "Extra content of the news 5", "newsbox_slug": "news-5", - "newsbox_changed_date": "2014-03-11T13:53:49.830Z", - "newsbox_creation_date": "2014-03-11T13:53:49.830Z", - "newsbox_publication_start_date": "1985-07-02T11:00:00Z", + "newsbox_changed_date": "2014-03-05T13:53:49.830Z", + "newsbox_creation_date": "2014-03-05T13:53:49.830Z", + "newsbox_publication_start_date": "2014-03-05T13:53:49.052Z", "newsbox_meta_keywords": "keyword1, keyword2, news-5", - "newsbox_date": "2014-02-22T08:00:00Z", + "newsbox_date": null, "general_field": "Test", "newsbox_indexed": true, "seo_field": "Extra SEO of the news 5", @@ -592,11 +592,11 @@ "newsbox_published": true, "content_field": "Extra content of the news 6", "newsbox_slug": "news-6", - "newsbox_changed_date": "2014-03-11T13:53:50.016Z", - "newsbox_creation_date": "2014-03-11T13:53:50.016Z", - "newsbox_publication_start_date": "1985-07-02T12:00:00Z", + "newsbox_changed_date": "2014-03-06T13:53:50.016Z", + "newsbox_creation_date": "2014-03-06T13:53:50.016Z", + "newsbox_publication_start_date": "2005-07-15T08:00:00Z", "newsbox_meta_keywords": "keyword1, keyword2, news-6", - "newsbox_date": "2005-07-15T08:00:00Z", + "newsbox_date": "2028-01-01T08:00:00Z", "general_field": "Test", "newsbox_indexed": false, "seo_field": "Extra SEO of the news 6", @@ -614,18 +614,18 @@ "newsbox_published": true, "content_field": "Extra content of the news 7", "newsbox_slug": "news-7", - "newsbox_changed_date": "2014-03-11T13:53:50.208Z", - "newsbox_creation_date": "2014-03-11T13:53:50.208Z", - "newsbox_publication_start_date": "1985-07-02T13:00:00Z", + "newsbox_changed_date": "2014-03-07T13:53:50.208Z", + "newsbox_creation_date": "2014-03-07T13:53:50.208Z", + "newsbox_publication_start_date": "2014-03-07T13:53:49.052Z", "newsbox_meta_keywords": "keyword1, keyword2, news-7", - "newsbox_date": "2020-01-01T08:00:00Z", + "newsbox_date": "1985-07-02T23:50:00Z", "general_field": "Test", "newsbox_indexed": true, "seo_field": "Extra SEO of the news 7", "newsbox_summary": "Summary of the news 7", "newsbox_meta_description": "Meta description of the news 7", "newsbox_body": "Body of the news 7", - "newsbox_publication_end_date": null, + "newsbox_publication_end_date": "2020-03-07T13:53:50.208Z", "newsbox_title": "News 7" } } diff --git a/tests/myapp/tests.py b/tests/myapp/tests.py index 738c7a8e41a97b7ec4e43b426c3c7428fa7e7534..b726cd7e3ac28d696e7787848e935bb573015e12 100644 --- a/tests/myapp/tests.py +++ b/tests/myapp/tests.py @@ -49,10 +49,9 @@ class NewsboxAbstractModelsTests(TestCase): self.assertFalse(r.context['with_pager']) r = c.get('/news/2014/') self.assertEqual(r.status_code, 200) - self.assertEqual(r.context['newsset'].paginator.num_pages, 2) + self.assertEqual(r.context['newsset'].paginator.num_pages, 3) r = c.get('/news/2020/') - self.assertEqual(r.status_code, 200) - self.assertEqual(r.context['newsset'].paginator.num_pages, 1) + self.assertEqual(r.status_code, 404) def test_04_view_year_archive_404(self): """ @@ -128,6 +127,14 @@ class NewsboxAbstractModelsTests(TestCase): r = c.get('/newsbox/myapp/news/2014/02/22/news-2/') self.assertEqual(r.status_code, 404) + def test_12_view_detail_404_wrong_date(self): + """ + Test if generic day views return a 404 with an URL with an invalide date + """ + c = Client() + r = c.get('/newsbox/myapp/news/1984/07/15/news-6/') + self.assertEqual(r.status_code, 404) + def has_readmore_link(self, news): readmore_p = news.find('p', class_='readmore') if readmore_p: @@ -138,19 +145,37 @@ class NewsboxAbstractModelsTests(TestCase): return False def get_news_in_list_by_summary(self, response, summary): - soup = BeautifulSoup(response.content) + soup = BeautifulSoup(response.content, "html.parser") for news in soup.find_all('div', class_='news'): readmore_summary = news.find('p', text=summary) if readmore_summary: return news return None + def test_news_are_ordered(self): + """ + Test if news are correctly ordered + """ + c = Client() + r = c.get('/news/?page=1') + news = self.get_news_in_list_by_summary(r, 'Summary of the news 7') + self.assertIsNotNone(news) + r = c.get('/news/?page=2') + news = self.get_news_in_list_by_summary(r, 'Summary of the news 4') + self.assertIsNotNone(news) + r = c.get('/news/?page=3') + news = self.get_news_in_list_by_summary(r, 'Summary of the news 1') + self.assertIsNotNone(news) + r = c.get('/news/?page=4') + news = self.get_news_in_list_by_summary(r, 'Summary of the news 6') + self.assertIsNotNone(news) + def test_news_4_has_no_readmore_link(self): """ Test if readmore link is not present in news 4 """ c = Client() - r = c.get('/news/?page=3') + r = c.get('/news/?page=2') news = self.get_news_in_list_by_summary(r, 'Summary of the news 4') self.assertIsNotNone(news) diff --git a/tests/myapp_i18n/tests.py b/tests/myapp_i18n/tests.py index ac1d90c91750ef85dbc11d196870c1de17be2252..af2206844aa031fe8d407e911f32b0cc3dcc7894 100644 --- a/tests/myapp_i18n/tests.py +++ b/tests/myapp_i18n/tests.py @@ -62,7 +62,7 @@ class NewsboxAbstractModelsTests(TestCase): Test if generic day views return right informations. """ c = Client() - r = c.get('/en/newsbox/myapp_i18n/news/2005/07/15/news-6/') + r = c.get('/en/newsbox/myapp_i18n/news/1985/07/02/news-6/') self.assertEqual(r.status_code, 200) self.assertEqual(r.context['news'].pk, 6) @@ -81,21 +81,29 @@ class NewsboxAbstractModelsTests(TestCase): news """ c = Client() - r = c.get('/en/newsbox/myapp_i18n/news/2014/02/22/news-2/') + r = c.get('/en/newsbox/myapp_i18n/news/1985/07/02/news-2/') self.assertEqual(r.status_code, 404) def test_07_view_detail_translated(self): c = Client() - r_en = c.get('/en/newsbox/myapp_i18n/news/2005/07/15/news-6/') - r_fr = c.get('/fr/newsbox/myapp_i18n/news/2005/07/15/actualite-6/') + r_en = c.get('/en/newsbox/myapp_i18n/news/1985/07/02/news-6/') + r_fr = c.get('/fr/newsbox/myapp_i18n/news/1985/07/02/actualite-6/') self.assertEqual(r_fr.context['news'].pk, r_en.context['news'].pk) self.assertEqual(r_fr.context['news'].newsbox_title, 'Actualité 6') self.assertEqual(r_en.context['news'].newsbox_title, 'News 6') def test_08_get_absolute_url(self): news6 = News.objects.get(pk=6) - expected_results = {'en': '/en/newsbox/myapp_i18n/news/2005/07/15/news-6/', - 'fr': '/fr/newsbox/myapp_i18n/news/2005/07/15/actualite-6/', } + expected_results = {'en': '/en/newsbox/myapp_i18n/news/1985/07/02/news-6/', + 'fr': '/fr/newsbox/myapp_i18n/news/1985/07/02/actualite-6/', } for lang in expected_results: activate(lang) self.assertEqual(news6.get_absolute_url(), expected_results[lang]) + + def test_09_view_detail_404_wrong_date(self): + """ + Test if generic day views return a 404 with an URL with an invalide date + """ + c = Client() + r = c.get('/en/newsbox/myapp_i18n/news/2009/02/22/news-6/') + self.assertEqual(r.status_code, 404) diff --git a/tox.ini b/tox.ini index e0d6efd97ccc752fe2c0c1a5e3174a7d86122d10..e3a61dc1cd82c1b90556cf2ecfb169cde6a2c2c7 100644 --- a/tox.ini +++ b/tox.ini @@ -1,20 +1,23 @@ [tox] envlist= +; test all python version with django 16 py26-16, py27-16, py32-16, py33-16, py34-16, + +; test all other django with python 2.7 py27-17, py27-18, - - py26-cms30, - py27-cms30, - py27-cms31, -; cms seems to be not yet compatible with python 3.0 -; py32-cms30, -; py33-cms30, -; py34-cms30, +; py27-19, + +; test all django CMS with python 2.7 (and recommanded django) +; py27-cms30, +; py27-cms31, +; py27-cms32, +; py27-cms33, +; py27-cms34 [testenv] changedir = {toxinidir}/tests