blog

Add weekly publication link

Author
Maarten Vangeneugden
Date
Jan. 22, 2018, 11:11 p.m.
Hash
05d87a05e5e61863f4f319889650f7da02b24988
Parent
e2546549968315b5db52e653efe0f7e29c5f0258
Modified files
locale/de/LC_MESSAGES/django.po
locale/es/LC_MESSAGES/django.po
locale/fr/LC_MESSAGES/django.po
locale/nl/LC_MESSAGES/django.po
templates/blog/index.html
templates/blog/locale/de/LC_MESSAGES/django.po
templates/blog/locale/es/LC_MESSAGES/django.po
templates/blog/locale/fr/LC_MESSAGES/django.po
templates/blog/locale/nl/LC_MESSAGES/django.po
views.py

locale/de/LC_MESSAGES/django.po

2 additions and 1 deletion.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
19
#: blog/views.py:95
+
20
#: blog/views.py:95
20
21
msgid "Notepad from a student"
21
22
msgstr ""
22
23

locale/es/LC_MESSAGES/django.po

2 additions and 1 deletion.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
19
#: blog/views.py:95
+
20
#: blog/views.py:95
20
21
msgid "Notepad from a student"
21
22
msgstr ""
22
23

locale/fr/LC_MESSAGES/django.po

2 additions and 1 deletion.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
19
19
#: blog/views.py:95
+
20
#: blog/views.py:95
20
21
msgid "Notepad from a student"
21
22
msgstr "Bloc-notes d'un étudiant"
22
23

locale/nl/LC_MESSAGES/django.po

2 additions and 1 deletion.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
19
#: blog/views.py:95
+
20
#: blog/views.py:95
20
21
msgid "Notepad from a student"
21
22
msgstr "Studentikoos kladblok"
22
23

templates/blog/index.html

6 additions and 2 deletions.

View changes Hide changes
1
1
{% load i18n %}
2
2
3
3
{% block title %}{% trans "Maarten's blog" %}{% endblock title %}
4
4
5
5
{% block description %}{% blocktrans %}The always coherently put together, yet
6
6
fuzzy blog of whatever sprouts in my mind.{% endblocktrans %}
7
7
{% endblock description %}
8
8
9
9
{% block main %}
10
10
{% with color="brown" accent_color="yellow" %}
11
11
<div class="section {{ color }} z-depth-3">
12
12
    <div class="container">
13
13
        <div class="white-text">
14
14
            <h3>{% trans "Blog" %}</h3>
15
15
            <p>
16
16
                {% blocktrans %}Welcome to my blog. Here, I write
17
17
                about things that interest me. Politics, coding,
18
18
                studying, life, or anything else I fancy rambling
19
19
                about. If you're in luck, I may've written it in a
20
20
                language that you understand better than English.
21
21
                {% endblocktrans %}
22
22
            </p>
23
23
        </div>
24
24
    </div>
25
25
</div>
26
26
27
27
<div class="container">
+
28
    <h1 id="Weekboek" class="{{ color }}-text">Weekboek</h1>
+
29
    {% include "blog/weekly.html" %}
+
30
</div>
+
31
<div class="container">
28
32
    {% for title, date, description, link in post_links %}
29
-
        <h2 class="{{ color}}-text">{{ title }}</h2>
30
-
        {# FIXME: Date is in all languages of the same format. Fix for each language #}
+
33
        <h2 class="{{ color}}-text">{{ human_title }}</h2>
+
34
        {# FIXME: Date is in all languages of the same format. Fix for each language #}
31
35
        <span class="grey-text">{{ date|date:"l j F Y" }}</span>
32
36
        <p class="hide-on-small-only">{{ description|safe|truncatewords_html:100 }}</p>
33
37
        {#<p class="hide-on-small-only">{% lorem %}</p>#}
34
38
        <a class="btn {{accent_color}} accent-4" href="{{link}}">
35
39
            {% trans "Read on"%}
36
40
        </a>
37
41
        <hr />
38
42
    {% endfor %}
39
43
</div>
40
44
{% endwith %}
41
45
{% endblock main %}
42
46

templates/blog/locale/de/LC_MESSAGES/django.po

2 additions and 1 deletion.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
19
#: blog/templates/blog/index.html:4
+
20
#: blog/templates/blog/index.html:4
20
21
msgid "Maarten's blog"
21
22
msgstr ""
22
23
23
24
#: blog/templates/blog/index.html:6
24
25
msgid ""
25
26
"The always coherently put together, yet\n"
26
27
"fuzzy blog of whatever sprouts in my mind."
27
28
msgstr ""
28
29
29
30
#: blog/templates/blog/index.html:15
30
31
msgid "Blog"
31
32
msgstr ""
32
33
33
34
#: blog/templates/blog/index.html:17
34
35
msgid ""
35
36
"Welcome to my blog. Here, I write\n"
36
37
"                about things that interest me. Politics, coding,\n"
37
38
"                studying, life, or anything else I fancy rambling\n"
38
39
"                about. If you're in luck, I may've written it in a\n"
39
40
"                language that you understand better than English.\n"
40
41
"                "
41
42
msgstr ""
42
43
43
44
#: blog/templates/blog/index.html:36
44
45
msgid "Read on"
45
46
msgstr ""
46
47

templates/blog/locale/es/LC_MESSAGES/django.po

2 additions and 1 deletion.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
19
#: blog/templates/blog/index.html:4
+
20
#: blog/templates/blog/index.html:4
20
21
msgid "Maarten's blog"
21
22
msgstr ""
22
23
23
24
#: blog/templates/blog/index.html:6
24
25
msgid ""
25
26
"The always coherently put together, yet\n"
26
27
"fuzzy blog of whatever sprouts in my mind."
27
28
msgstr ""
28
29
29
30
#: blog/templates/blog/index.html:15
30
31
msgid "Blog"
31
32
msgstr ""
32
33
33
34
#: blog/templates/blog/index.html:17
34
35
msgid ""
35
36
"Welcome to my blog. Here, I write\n"
36
37
"                about things that interest me. Politics, coding,\n"
37
38
"                studying, life, or anything else I fancy rambling\n"
38
39
"                about. If you're in luck, I may've written it in a\n"
39
40
"                language that you understand better than English.\n"
40
41
"                "
41
42
msgstr ""
42
43
43
44
#: blog/templates/blog/index.html:36
44
45
msgid "Read on"
45
46
msgstr ""
46
47

templates/blog/locale/fr/LC_MESSAGES/django.po

5 additions and 2 deletions.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n > 1);\n"
19
19
#: blog/templates/blog/index.html:4
+
20
#: blog/templates/blog/index.html:4
20
21
msgid "Maarten's blog"
21
22
msgstr "Blog de Maarten"
22
23
23
24
#: blog/templates/blog/index.html:6
24
25
msgid ""
25
26
"The always coherently put together, yet\n"
26
27
"fuzzy blog of whatever sprouts in my mind."
27
28
msgstr "Le toujours mis de façon cohérente ensemble, mais floue de ce que les germes dans mon esprit."
28
-
+
29
"Le toujours mis de façon cohérente ensemble, mais floue de ce que les germes "
+
30
"dans mon esprit."
+
31
29
32
#: blog/templates/blog/index.html:15
30
33
msgid "Blog"
31
34
msgstr "Blog"
32
35
33
36
#: blog/templates/blog/index.html:17
34
37
msgid ""
35
38
"Welcome to my blog. Here, I write\n"
36
39
"                about things that interest me. Politics, coding,\n"
37
40
"                studying, life, or anything else I fancy rambling\n"
38
41
"                about. If you're in luck, I may've written it in a\n"
39
42
"                language that you understand better than English.\n"
40
43
"                "
41
44
msgstr ""
42
45
43
46
#: blog/templates/blog/index.html:36
44
47
msgid "Read on"
45
48
msgstr "Lire plus"
46
49

templates/blog/locale/nl/LC_MESSAGES/django.po

6 additions and 5 deletions.

View changes Hide changes
1
1
# Copyright (C) YEAR THE PACKAGE'S COPYRIGHT HOLDER
2
2
# This file is distributed under the same license as the PACKAGE package.
3
3
# FIRST AUTHOR <EMAIL@ADDRESS>, YEAR.
4
4
#
5
5
#, fuzzy
6
6
msgid ""
7
7
msgstr ""
8
8
"Project-Id-Version: PACKAGE VERSION\n"
9
9
"Report-Msgid-Bugs-To: \n"
10
10
"POT-Creation-Date: 2017-10-19 18:27+0200\n"
11
-
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
+
11
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
12
12
"Last-Translator: FULL NAME <EMAIL@ADDRESS>\n"
13
13
"Language-Team: LANGUAGE <LL@li.org>\n"
14
14
"Language: \n"
15
15
"MIME-Version: 1.0\n"
16
16
"Content-Type: text/plain; charset=UTF-8\n"
17
17
"Content-Transfer-Encoding: 8bit\n"
18
18
"Plural-Forms: nplurals=2; plural=(n != 1);\n"
19
19
#: blog/templates/blog/index.html:4
+
20
#: blog/templates/blog/index.html:4
20
21
msgid "Maarten's blog"
21
22
msgstr "Maartens blog"
22
23
23
24
#: blog/templates/blog/index.html:6
24
25
msgid ""
25
26
"The always coherently put together, yet\n"
26
27
"fuzzy blog of whatever sprouts in my mind."
27
28
msgstr ""
28
29
"Een zeer weloverwogen geschreven, en toch warrige blog "
29
-
"over vanalles wat in mij opkomt."
30
-
+
30
"mij opkomt."
+
31
31
32
#: blog/templates/blog/index.html:15
32
33
msgid "Blog"
33
34
msgstr "Blog"
34
35
35
36
#: blog/templates/blog/index.html:17
36
37
msgid ""
37
38
"Welcome to my blog. Here, I write\n"
38
39
"                about things that interest me. Politics, coding,\n"
39
40
"                studying, life, or anything else I fancy rambling\n"
40
41
"                about. If you're in luck, I may've written it in a\n"
41
42
"                language that you understand better than English.\n"
42
43
"                "
43
44
msgstr ""
44
45
"Welkom op mijn blog. Hier schrijf ik over onderwerpen die mij interesseren. "
45
46
"Politiek, programmeren, studeren en het leven, plus alles waar ik goesting in "
46
-
"heb om over te schrijven."
47
-
+
47
"in heb om over te schrijven."
+
48
48
49
#: blog/templates/blog/index.html:36
49
50
msgid "Read on"
50
51
msgstr "Verder lezen"
51
52

views.py

5 additions and 3 deletions.

View changes Hide changes
1
1
import subprocess
2
2
3
3
from django.utils.translation import ugettext as _
4
4
from django.shortcuts import get_object_or_404, render # This allows to render the template with the view here. It's pretty cool and important.
5
5
from django.http import HttpResponseRedirect, HttpResponse
6
6
from django.core.urlresolvers import reverse # Why?
7
7
from django.template import loader # This allows to actually load the template.
8
8
from django.contrib.auth.decorators import login_required
9
9
from django.contrib.auth import authenticate, login
10
10
from .models import Post
11
11
from django.core.exceptions import ObjectDoesNotExist
12
12
from django.utils import translation
13
13
14
14
# FIXME: Remove this template trash. THIS IS A VIEW, NOT A FUCKING TEMPLATE FFS
15
15
context = {
16
16
    'materialDesign_color': "green",
17
17
    'materialDesign_accentColor': "purple",
18
18
    'navbar_title': "Blog",
19
19
    'navbar_fixed': True,
20
20
    'navbar_backArrow': True,
21
21
    #'footer_title': "Maarten's blog",
22
22
    #'footer_description': "My personal scribbly notepad.",
23
23
    #'footer_links': footer_links,
24
24
    }
25
25
26
26
def markdown_to_html(file_path):
27
27
    """ Converts the given Markdown formatted file to HTML.
28
28
    This function directly returns the resulting HTML code. This function uses
29
29
    the amazing Haskell library Pandoc to convert the file (and takes care
30
30
    of header id's and all that stuff).
31
31
    """
32
32
    return subprocess.check_output(["pandoc", "--from=markdown", "--to=html", "/srv/django/website/media/"+file_path])
33
33
34
34
def get_available_post_languages(post):
35
35
    """ Returns the language codes for which a blog post exists. This function
36
36
    always returns English (because that field mustn't be empty).
37
37
    So say a blog post has an English, Dutch and French version (which means
38
38
    english_file, french_file and dutch_file aren't empty), the function will return {"en",
39
39
    "fr", "nl"}. """
40
40
    available_languages = {"en"}
41
41
    if post.german_file is not None:
42
42
        available_languages.add("de")
43
43
    if post.spanish_file is not None:
44
44
        available_languages.add("es")
45
45
    if post.french_file is not None:
46
46
        available_languages.add("fr")
47
47
    if post.dutch_file is not None:
48
48
        available_languages.add("nl")
49
49
    return available_languages
50
50
51
51
def get_preferred_post_language(post, language):
52
52
    """ Returns the post language file that best suits the given language. This
53
53
    is handy if you know what language the user prefers, but aren't sure whether
54
54
    you can provide that language. This function will try to provide the file
55
55
    for that language, or return English if that's not possible. """
56
56
    if language == "de" and post.german_file is not None:
57
57
        return post.german_file
58
58
    if language == "es" and post.spanish_file is not None:
59
59
        return post.spanish_file
60
60
    if language == "fr" and post.french_file is not None:
61
61
        return post.french_file
62
62
    if language == "nl" and post.dutch_file is not None:
63
63
        return post.dutch_file
64
64
    return post.english_file  # Returned if all other choices wouldn't be satisfactory, or the requested language is English.
65
65
66
66
def index(request):
67
67
    template = "blog/index.html"
68
68
    posts = Post.objects.all()
69
69
    language = translation.get_language()
70
70
71
71
    post_links = []
72
72
    for post in posts:
73
73
        blog_file = get_preferred_post_language(post, language)
74
74
        # TODO: Find a cleaner way to determine the title. First and foremost:
75
75
        # If the language differs from English, the other language file needs to
76
76
        # be loaded. Plus: look for a built in function to remove the full path
77
77
        # and only return the file name.
78
78
        title = (blog_file.name.rpartition("/")[2]).rpartition(".")[0]
79
79
        date = post.published
+
80
        date = post.published
80
81
        #description = "Lorem ipsum"
81
82
        blog_text = markdown_to_html(blog_file.name)
82
83
        #blog_text = blog_text.replace("\\n\\n", "</p><p>")
83
84
        #blog_text = blog_text.replace("\\n", " ")
84
85
        description = blog_text
85
86
        # TODO: The link can possibly be reversed in the DTL using the title, which is actually
86
87
        # a cleaner way to do it. Investigate.
87
88
        link = reverse("blog-post", args=[str(post)])
88
89
        post_links.append([title, date, description, link])
89
-
+
90
90
91
    context = {
91
92
            'post_links': post_links,
92
93
            'materialDesign_color': "brown",
93
94
            'materialDesign_accentColor': "yellow",
94
95
            'navbar_title': _("Notepad from a student"),
95
96
            'navbar_backArrow': True,
96
97
            }
97
98
    return render(request, template, context)
98
99
99
100
def post(request, title):
100
101
    template = "blog/post.html"
101
102
    posts = Post.objects.all()
102
103
    for post in posts:
103
104
        if str(post)==title:
104
105
            language = translation.get_language()
105
106
            blog_file = get_preferred_post_language(post, language)
106
107
            blog_text = markdown_to_html(blog_file.name)
107
108
            context = {
108
109
                'materialDesign_color': "brown",
+
110
                'materialDesign_color': "brown",
109
111
                'materialDesign_accentColor': "yellow",
110
112
                'article': blog_text,
111
113
                'title': blog_file.name,
112
-
                'navbar_title': (blog_file.name.rpartition("/")[2]).rpartition(".")[0],
113
-
                'navbar_backArrow': True,
+
114
                'navbar_title': ((blog_file.name.rpartition("/")[2]).rpartition(".")[0]).replace("_"," "),
+
115
                'navbar_backArrow': True,
114
116
                }
115
117
            return render(request, template, context)
116
118