diff --git a/digitalglarus/templates/glarus_blog/base.html b/digitalglarus/templates/glarus_blog/base.html new file mode 100644 index 00000000..69f50d5b --- /dev/null +++ b/digitalglarus/templates/glarus_blog/base.html @@ -0,0 +1,13 @@ +{% extends "digitalglarus/base.html" %} + +{% block meta %} + {% if meta %} + {% include "meta_mixin/meta.html" %} + {% endif %} +{% endblock meta %} + +{% block content %} +<div class="app app-blog span8"> + {% block content_blog %}{% endblock %} +</div> +{% endblock content %} diff --git a/digitalglarus/templates/glarus_blog/includes/blog_item.html b/digitalglarus/templates/glarus_blog/includes/blog_item.html new file mode 100644 index 00000000..7340962f --- /dev/null +++ b/digitalglarus/templates/glarus_blog/includes/blog_item.html @@ -0,0 +1,22 @@ +{% load i18n thumbnail %} + +<article id="post-{{ post.slug }}" class="post-item"> + <header> + <h3><a href="{% url 'digitalglarus:blog-detail' post.slug %}">{{ post.title }}</a></h3> + {% block blog_meta %} + {% include "glarus_blog/includes/blog_meta.html" %} + {% endblock %} + </header> + {% if image and post.main_image %} + <div class="blog-visual"> + {% thumbnail post.main_image post.thumbnail_options.size crop=post.thumbnail_options.crop upscale=post.thumbnail_options.upscale subject_location=post.main_image.subject_location as thumb %} + <img src="{{ thumb.url }}" alt="{{ post.main_image.default_alt_text }}" width="{{ thumb.width }}" height="{{ thumb.height }}" /> + </div> + {% endif %} + <div class="blog-lead"> + {{ post.abstract| safe }} + </div> + <footer class="read-more"> + <a href="{% url 'digitalglarus:blog-detail' post.slug %}">{% trans "read more" %} »</a> + </footer> +</article> \ No newline at end of file diff --git a/digitalglarus/templates/glarus_blog/includes/blog_meta.html b/digitalglarus/templates/glarus_blog/includes/blog_meta.html new file mode 100644 index 00000000..24ca606a --- /dev/null +++ b/digitalglarus/templates/glarus_blog/includes/blog_meta.html @@ -0,0 +1,26 @@ +{% load i18n thumbnail %} + +<ul class="post-detail"> + {% if post.author %} + <li> + {% trans "by" %} <a href="{% url 'djangocms_blog:posts-author' post.author.get_username %}">{% if post.author.get_full_name %}{{ post.author.get_full_name }}{% else %}{{ post.author }}{% endif %}</a> + </li> + {% endif %} + <li> + {{ post.date_published|date:"DATE_FORMAT" }} + </li> +</ul> +<ul class="post-detail tags"> + {% if post.categories.exists %} + {% for category in post.categories.all %} + {% if category.slug %} + <li class="category_{{ forloop.counter }}"><a href="{% url 'djangocms_blog:posts-category' category=category.slug %}" class="blog-categories-{{ category.count }}">{{ category.name }}</a>{% if not forloop.last %}, {% endif %}</li> + {% endif %} + {% endfor %} + {% endif %} + {% if post.tags.exists %} + {% for tag in post.tags.all %} + <li class="tag_{{ forloop.counter }}"><a href="{% url 'djangocms_blog:posts-tagged' tag=tag.slug %}" class="blog-tag blog-tag-{{ tag.count }}">{{ tag.name }}</a>{% if not forloop.last %}, {% endif %}</li> + {% endfor %} + {% endif %} +</ul> \ No newline at end of file diff --git a/digitalglarus/templates/glarus_blog/post_detail.html b/digitalglarus/templates/glarus_blog/post_detail.html new file mode 100644 index 00000000..ed71df5e --- /dev/null +++ b/digitalglarus/templates/glarus_blog/post_detail.html @@ -0,0 +1,26 @@ +{% extends "glarus_blog/base.html" %} +{% load i18n thumbnail cms_tags %} + +{% block meta_description %}{{ post.meta_description }}{% endblock meta_description %} +{% block meta_keywords %}{{ post.meta_keywords }}{% endblock meta_keywords %} +{% block canonical_url %}<link rel="canonical" href="{{ SITE.domain }}{{ view.get_view_url }}"/>{% endblock canonical_url %} +{% block title %}{{ post.get_title }}{% endblock %} + +{% block content_blog %}{% spaceless %} +<article id="post-{{ post.slug }}" class="post-item post-detail"> + <header> + <h2>{{ post.title }}</h2> + {% block blog_meta %} + {% include "glarus_blog/includes/blog_meta.html" %} + {% endblock %} + </header> + {% if post.main_image_id %} + <div class="blog-visual"> + {% thumbnail post.main_image post.full_image_options.size crop=post.full_image_options.crop upscale=post.full_image_options.upscale subject_location=post.main_image.subject_location as thumb %} + <img src="{{ thumb.url }}" alt="{{ post.main_image.default_alt_text }}" width="{{ thumb.width }}" height="{{ thumb.height }}" /> + </div> + {% endif %} + {% endspaceless %} + <div class="blog-content">{% render_placeholder post.content %}</div> +</article> +{% endblock content_blog %} diff --git a/digitalglarus/templates/glarus_blog/post_list.html b/digitalglarus/templates/glarus_blog/post_list.html new file mode 100644 index 00000000..d640f30e --- /dev/null +++ b/digitalglarus/templates/glarus_blog/post_list.html @@ -0,0 +1,41 @@ +{% extends "glarus_blog/base.html" %} +{% load i18n thumbnail %}{% spaceless %} + +{% block canonical_url %}<link rel="canonical" href="{{ SITE.domain }}{{ view.get_view_url }}"/>{% endblock canonical_url %} + +{% block content_blog %} +<section class="blog-list"> + {% block blog_title %} + <header> + <h2> + {% if author %}{% trans "Articles by" %} {{ author.get_full_name }} + {% elif archive_date %}{% trans "Archive" %} – {% if month %}{{ archive_date|date:'F' }} {% endif %}{{ year }} + {% elif tagged_entries %}{% trans "Tag" %} – {{ tagged_entries|capfirst }} + {% elif category %}{% trans "Category" %} – {{ category }}{% endif %} + </h2> + </header> + {% endblock %} + {% for post in post_list %} + {% include "glarus_blog/includes/blog_item.html" with post=post image="true" TRUNCWORDS_COUNT=TRUNCWORDS_COUNT %} + {% empty %} + <p class="blog-empty">{% trans "No article found." %}</p> + {% endfor %} + {% if author or archive_date or tagged_entries %} + <p class="blog-back"><a href="{% url 'djangocms_blog:posts-latest' %}">{% trans "Back" %}</a></p> + {% endif %} + {% if is_paginated %} + <nav class="{% firstof css_grid instance.css_grid %} pagination"> + {% if page_obj.has_previous %} + <a href="?{{ view.page_kwarg }}={{ page_obj.previous_page_number }}">« {% trans "previous" %}</a> + {% endif %} + <span class="current"> + {% trans "Page" %} {{ page_obj.number }} {% trans "of" %} {{ paginator.num_pages }} + </span> + {% if page_obj.has_next %} + <a href="?{{ view.page_kwarg }}={{ page_obj.next_page_number }}">{% trans "next" %} »</a> + {% endif %} + </nav> + {% endif %} +</section> +{% endblock %} +{% endspaceless %} \ No newline at end of file diff --git a/digitalglarus/urls.py b/digitalglarus/urls.py index c1ef0c5e..d08b5085 100644 --- a/digitalglarus/urls.py +++ b/digitalglarus/urls.py @@ -6,4 +6,6 @@ urlpatterns = [ url(r'^$', views.index, name='index'), url(r'about$', views.about, name='about'), url(r'contact$', views.contact, name='contact'), + url(r'blog/$', views.blog, name='blog'), + url(r'^blog/(?P<slug>\w[-\w]*)/$', views.blog_detail, name='blog-detail'), ] diff --git a/digitalglarus/views.py b/digitalglarus/views.py index c9d3feec..debfb528 100644 --- a/digitalglarus/views.py +++ b/digitalglarus/views.py @@ -4,6 +4,8 @@ from django.shortcuts import get_object_or_404, render from django.forms import ModelForm from django.http import HttpResponseRedirect from django.core.urlresolvers import reverse +from django.utils.translation import get_language +from djangocms_blog.models import Post from .models import Message @@ -43,3 +45,21 @@ def contact(request): } return render(request, 'digitalglarus/contact.html', context) + + +def blog(request): + tags = ["glarus"] + posts = Post.objects.filter(tags__name__in=tags) + context = { + 'post_list': posts, + } + return render(request, 'glarus_blog/post_list.html', context) + + +def blog_detail(request, slug): + language = get_language() + post = Post.objects.translated(language, slug=slug).language(language).get() + context = { + 'post': post, + } + return render(request, 'glarus_blog/post_detail.html', context)