From 53bd031fea907cb70f3a95be929174be957ecbf9 Mon Sep 17 00:00:00 2001 From: Emilie Date: Fri, 8 Jul 2016 11:57:28 +0200 Subject: [PATCH] Task #74 #84: Article list and detail view --- app/local_settings.py | 3 - app/organization/magazine/models.py | 8 ++ app/organization/magazine/urls.py | 18 +-- app/organization/magazine/views.py | 45 +++++--- .../festival/artist_detail.html | 0 .../{templates => }/festival/artist_list.html | 0 .../festival/inc/artist_card.html | 0 .../festival/inc/audio_playlist.html | 0 .../festival/inc/video_card.html | 0 .../festival/video_detail.html | 0 .../{templates => }/festival/video_list.html | 0 .../magazine/article/article_detail.html | 51 +++++---- .../magazine/article/article_list.html | 106 ++++++++++++++++++ .../magazine/article/includes/post_card.html | 19 ++++ 14 files changed, 192 insertions(+), 58 deletions(-) rename app/templates/{templates => }/festival/artist_detail.html (100%) rename app/templates/{templates => }/festival/artist_list.html (100%) rename app/templates/{templates => }/festival/inc/artist_card.html (100%) rename app/templates/{templates => }/festival/inc/audio_playlist.html (100%) rename app/templates/{templates => }/festival/inc/video_card.html (100%) rename app/templates/{templates => }/festival/video_detail.html (100%) rename app/templates/{templates => }/festival/video_list.html (100%) rename app/templates/{templates => }/magazine/article/article_detail.html (68%) create mode 100644 app/templates/magazine/article/article_list.html create mode 100644 app/templates/magazine/article/includes/post_card.html diff --git a/app/local_settings.py b/app/local_settings.py index 96e92ada..4b3d83c9 100644 --- a/app/local_settings.py +++ b/app/local_settings.py @@ -137,6 +137,3 @@ DEBUG_TOOLBAR_PANELS = [ 'debug_toolbar.panels.logging.LoggingPanel', 'debug_toolbar.panels.redirects.RedirectsPanel', ] - -# slug -BLOG_SLUG = 'article' diff --git a/app/organization/magazine/models.py b/app/organization/magazine/models.py index 412eaf01..1e952fb0 100644 --- a/app/organization/magazine/models.py +++ b/app/organization/magazine/models.py @@ -16,9 +16,17 @@ class Article(BlogPost): sub_title = models.CharField(_('sub title'), blank=True, max_length=1000) + def get_absolute_url(self): + return reverse("magazine-article-detail", kwargs={"slug": self.slug}) + class Meta: verbose_name = _('article') + class Meta: + verbose_name = _("article") + verbose_name_plural = _("article") + ordering = ("-publish_date",) + class Category(Named): """(Category description)""" diff --git a/app/organization/magazine/urls.py b/app/organization/magazine/urls.py index 08d9963b..b61c0bf9 100644 --- a/app/organization/magazine/urls.py +++ b/app/organization/magazine/urls.py @@ -1,28 +1,20 @@ from __future__ import unicode_literals -<<<<<<< HEAD from django.conf.urls import patterns, include, url from django.conf.urls.i18n import i18n_patterns from django.contrib import admin -======= -import django.views.i18n -from django.conf.urls import patterns, include, url -from django.conf.urls.i18n import i18n_patterns ->>>>>>> 0f089a57b9482bec7a88f169e5d5fe2688c538c4 from mezzanine.core.views import direct_to_template from mezzanine.conf import settings -<<<<<<< HEAD from organization.magazine.views import * +_slash = "/" if settings.APPEND_SLASH else "" urlpatterns = [ - url(r'^article/$', ArticleListView.as_view(), name="magazine-article-list"), - url(r'^article/detail/(?P.*)/$', ArticleDetailView.as_view(), name="magazine-article-detail"), -======= - -urlpatterns = [ + # url(r'^article/$', ArticleListView.as_view(), name="magazine-article-list"), + # url(r'^article/detail/(?P.*)/$', ArticleDetailView.as_view(), name="magazine-article-detail"), ->>>>>>> 0f089a57b9482bec7a88f169e5d5fe2688c538c4 + url("^article/$", ArticleListView.as_view(), name="magazine-article-list"), + url("^article/detail/(?P.*)%s$" % _slash, ArticleDetailView.as_view(), name="magazine-article-detail"), ] diff --git a/app/organization/magazine/views.py b/app/organization/magazine/views.py index c3dc0f46..aa7d6ec2 100644 --- a/app/organization/magazine/views.py +++ b/app/organization/magazine/views.py @@ -1,4 +1,7 @@ from django.shortcuts import render +from django.utils import timezone +from django.views.generic import DetailView, ListView, TemplateView + from organization.magazine.models import Article from organization.core.views import SlugMixin @@ -13,20 +16,30 @@ class ArticleDetailView(SlugMixin, DetailView): context = super(ArticleDetailView, self).get_context_data(**kwargs) return context +class ArticleListView(SlugMixin, ListView): + + model = Article + template_name='magazine/article/article_list.html' + # context_object_name = 'article' + + def get_context_data(self, **kwargs): + context = super(ArticleListView, self).get_context_data(**kwargs) + return context + -def blog_post_detail(request, slug, year=None, month=None, day=None, - template="blog/blog_post_detail.html", - extra_context=None): - """. Custom templates are checked for using the name - ``blog/blog_post_detail_XXX.html`` where ``XXX`` is the blog - posts's slug. - """ - blog_posts = BlogPost.objects.published( - for_user=request.user).select_related() - blog_post = get_object_or_404(blog_posts, slug=slug) - related_posts = blog_post.related_posts.published(for_user=request.user) - context = {"blog_post": blog_post, "editable_obj": blog_post, - "related_posts": related_posts} - context.update(extra_context or {}) - templates = [u"blog/blog_post_detail_%s.html" % str(slug), template] - return TemplateResponse(request, templates, context) +# def blog_post_detail(request, slug, year=None, month=None, day=None, +# template="blog/blog_post_detail.html", +# extra_context=None): +# """. Custom templates are checked for using the name +# ``blog/blog_post_detail_XXX.html`` where ``XXX`` is the blog +# posts's slug. +# """ +# blog_posts = BlogPost.objects.published( +# for_user=request.user).select_related() +# blog_post = get_object_or_404(blog_posts, slug=slug) +# related_posts = blog_post.related_posts.published(for_user=request.user) +# context = {"blog_post": blog_post, "editable_obj": blog_post, +# "related_posts": related_posts} +# context.update(extra_context or {}) +# templates = [u"blog/blog_post_detail_%s.html" % str(slug), template] +# return TemplateResponse(request, templates, context) diff --git a/app/templates/templates/festival/artist_detail.html b/app/templates/festival/artist_detail.html similarity index 100% rename from app/templates/templates/festival/artist_detail.html rename to app/templates/festival/artist_detail.html diff --git a/app/templates/templates/festival/artist_list.html b/app/templates/festival/artist_list.html similarity index 100% rename from app/templates/templates/festival/artist_list.html rename to app/templates/festival/artist_list.html diff --git a/app/templates/templates/festival/inc/artist_card.html b/app/templates/festival/inc/artist_card.html similarity index 100% rename from app/templates/templates/festival/inc/artist_card.html rename to app/templates/festival/inc/artist_card.html diff --git a/app/templates/templates/festival/inc/audio_playlist.html b/app/templates/festival/inc/audio_playlist.html similarity index 100% rename from app/templates/templates/festival/inc/audio_playlist.html rename to app/templates/festival/inc/audio_playlist.html diff --git a/app/templates/templates/festival/inc/video_card.html b/app/templates/festival/inc/video_card.html similarity index 100% rename from app/templates/templates/festival/inc/video_card.html rename to app/templates/festival/inc/video_card.html diff --git a/app/templates/templates/festival/video_detail.html b/app/templates/festival/video_detail.html similarity index 100% rename from app/templates/templates/festival/video_detail.html rename to app/templates/festival/video_detail.html diff --git a/app/templates/templates/festival/video_list.html b/app/templates/festival/video_list.html similarity index 100% rename from app/templates/templates/festival/video_list.html rename to app/templates/festival/video_list.html diff --git a/app/templates/templates/magazine/article/article_detail.html b/app/templates/magazine/article/article_detail.html similarity index 68% rename from app/templates/templates/magazine/article/article_detail.html rename to app/templates/magazine/article/article_detail.html index 038899f9..66ad853f 100644 --- a/app/templates/templates/magazine/article/article_detail.html +++ b/app/templates/magazine/article/article_detail.html @@ -1,45 +1,44 @@ -{% extends "blog/blog_post_list.html" %} +{% extends "magazine/article/article_list.html" %} {% load mezzanine_tags comment_tags keyword_tags rating_tags i18n disqus_tags featured_tags %} -{% block meta_title %}{{ blog_post.meta_title }}{% endblock %} +{% block meta_title %}{{ article.meta_title }}{% endblock %} {% block meta_keywords %}{% metablock %} -{% keywords_for blog_post as tags %} +{% keywords_for article as tags %} {% for tag in tags %}{% if not forloop.first %}, {% endif %}{{ tag }}{% endfor %} {% endmetablock %}{% endblock %} {% block meta_description %}{% metablock %} -{{ blog_post.description }} +{{ article.description }} {% endmetablock %}{% endblock %} {% block title %} -{% editable blog_post.title %}{{ blog_post.title }}{% endeditable %} +{% editable article.title %}{{ article.title }}{% endeditable %} {% endblock %} {% block breadcrumb_menu %} {{ block.super }} -
  • {{ blog_post.title }}
  • +
  • {{ article.title }}
  • {% endblock %} {% block main %} -coucou {% block blog_post_detail_postedby %} -{% editable blog_post.publish_date %} +{% editable article.publish_date %} {% endeditable %} {% endblock %} {% block blog_post_detail_commentlink %}

    - {% if blog_post.allow_comments %} + {% if article.allow_comments %} {% if settings.COMMENTS_DISQUS_SHORTNAME %} - ({% spaceless %} + ({% spaceless %} {% trans "Comments" %} {% endspaceless %}) {% else %}({% spaceless %} - {% blocktrans count comments_count=blog_post.comments_count %}{{ comments_count }} comment{% plural %}{{ comments_count }} comments{% endblocktrans %} + {% blocktrans count comments_count=article.comments_count %}{{ comments_count }} comment{% plural %}{{ comments_count }} comments{% endblocktrans %} {% endspaceless %}) {% endif %} {% endif %} @@ -48,8 +47,8 @@ coucou {% comment %} {% block blog_post_detail_featured_image %} -{% if settings.BLOG_USE_FEATURED_IMAGE and blog_post.featured_image %} -

    +{% if settings.BLOG_USE_FEATURED_IMAGE and article.featured_image %} +

    {% endif %} {% endblock %} {% endcomment %} @@ -59,13 +58,13 @@ coucou {% endif %} {% block blog_post_detail_content %} -{% editable blog_post.content %} -{{ blog_post.content|richtext_filters|safe }} +{% editable article.content %} +{{ article.content|richtext_filters|safe }} {% endeditable %} {% endblock %} {% block blog_post_detail_keywords %} -{% keywords_for blog_post as tags %} +{% keywords_for article as tags %} {% if tags %} {% spaceless %}
      @@ -82,28 +81,28 @@ coucou {% block blog_post_detail_rating %}
      - {% rating_for blog_post %} + {% rating_for article %}
      {% endblock %} {% endcomment %} {% block event_detail_sharebuttons %} - {% with blog_post as object %} + {% with article as object %} {% include "includes/share_buttons.html" %} {% endwith %} {% endblock %} {% block blog_post_previous_next %}
        -{% with blog_post.get_previous_by_publish_date as previous %} +{% with article.get_previous_by_publish_date as previous %} {% if previous %} {% endif %} {% endwith %} -{% with blog_post.get_next_by_publish_date as next %} +{% with article.get_next_by_publish_date as next %} {% if next %}
      • {% spaceless %} +{% if tag %} + {% trans "Tag:" %} {{ tag }} +{% else %}{% if category %} + {% trans "Category:" %} {{ category }} +{% else %}{% if year or month %} + {% if month %}{{ month }}, {% endif %}{{ year }} +{% else %}{% if author %} + {% trans "Author:" %} {{ author.get_full_name|default:author.username }} +{% endif %}{% endif %}{% endif %}{% endif %} +{% endspaceless %} +
      • +{% endif %} +{% endblock %} + +{% block main %} + +{% comment %} +{% if tag or category or year or month or author %} + {% block blog_post_list_filterinfo %} +

        + {% if tag %} + {% trans "Viewing posts tagged" %} {{ tag }} + {% else %}{% if category %} + {% trans "Viewing posts for the category" %} {{ category }} + {% else %}{% if year or month %} + {% trans "Viewing posts from" %} {% if month %}{{ month }}, {% endif %} + {{ year }} + {% else %}{% if author %} + {% trans "Viewing posts by" %} + {{ author.get_full_name|default:author.username }} + {% endif %}{% endif %}{% endif %}{% endif %} + {% endblock %} +

        +{% else %} +{% endcomment %} +{% if page %} +{% if page.get_content_model.content %} + {% editable page.get_content_model.content %} + {{ page.get_content_model.content|richtext_filters|safe }} + {% endeditable %} +{% endif %} +{% else %} + {% blog_categories as categories %} + {% if categories %} +
          + {% for cat in categories %} +
        • + {{ cat }} ({{ cat.post_count }}) +
        • + {% endfor %} +
        +
        + {% endif %} +{# {% endif %}#} + +{% endif %} + +
        +
        + + {% for article in article_list %} + {% with article as post %} + {# {% trans "Article" %}#} + {% include 'magazine/article/includes/post_card.html' %} + {% endwith %} + {% endfor %} +
        + +{% if settings.COMMENTS_DISQUS_SHORTNAME %} +{% include "generic/includes/disqus_counts.html" %} +{% endif %} + +{% endblock %} + +{% block right_panel %} +{% include "blog/includes/filter_panel.html" %} +{% endblock %} diff --git a/app/templates/magazine/article/includes/post_card.html b/app/templates/magazine/article/includes/post_card.html new file mode 100644 index 00000000..a9205756 --- /dev/null +++ b/app/templates/magazine/article/includes/post_card.html @@ -0,0 +1,19 @@ +{% load i18n pages_tags mezzanine_tags %} + +
        +
        + + {% if article.featured_image %} +
        + Article: {{ article.title }} +
        + {% endif %} +

        + + {{ article.title }} + +

        + {# {% trans "published on" %} {{ article.publish_date|date:"DATE_FORMAT" }}#} +
        +
        +
        -- 2.39.5