blog

Add weekly/sizsig archives from the previous years

Author
Maarten Vangeneugden
Date
April 15, 2025, 4:45 p.m.
Hash
0cd7b44b3abcb8d7cf9900060d4251625b0d28c2
Parent
1fb6ce7c2c7f9a5d1980456f84d7ed142f1c2c6d
Modified file
views.py

views.py

6 additions and 0 deletions.

View changes Hide changes
1
1
import requests
2
2
3
3
4
4
from django.utils.translation import gettext as _
5
5
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.
6
6
from django.http import HttpResponseRedirect, HttpResponse
7
7
from django.urls import reverse
8
8
from django.template import loader # This allows to actually load the template.
9
9
10
10
from django.conf import settings  # For the archive 20XX.org files
11
11
12
12
from .models import *
13
13
from .forms import CommentForm
14
14
from django.core.exceptions import ObjectDoesNotExist
15
15
from django.utils import translation
16
16
17
17
GERMAN = "de"
18
18
SPANISH = "es"
19
19
FRENCH = "fr"
20
20
DUTCH = "nl"
21
21
ENGLISH = "en"
22
22
23
23
def index(request):
24
24
    template = "blog/index.djhtml"
25
25
    posts = Post.objects.exclude(visible=False)
26
26
27
27
28
28
    context = {
29
29
            'posts': posts,
30
30
            'navbar_title': _("Notepad from a student"),
31
31
            'navbar_backArrow': True,
32
32
            'stylesheet_name': "blog",
33
33
            }
34
34
    return render(request, template, context)
35
35
36
36
def post(request, language_code, post_slug):
37
37
    context = dict()
38
38
    if request.method == "POST":  # Handling a reply if one is sent
39
39
        form = CommentForm(request.POST)
40
40
41
41
        form.post = Post.objects.get(id=request.POST['post'])
42
42
        if form.is_valid():
43
43
            new_comment = form.save(commit=False)
44
44
            if request.POST['reaction_to'] != "":
45
45
                new_comment.reaction_to = Comment.objects.get(id=request.POST['reaction_to'])
46
46
            new_comment.save()
47
47
            context["comment_response"] = _("Comment succesfully submitted!")
48
48
        else:
49
49
            print("ERROR")
50
50
            print(form.errors)
51
51
            context["contact_response"] = _("An error occured while trying to submit your comment. Please try again later.")
52
52
53
53
    template = "blog/post.djhtml"
54
54
    article = Article.objects.get(slug=post_slug, language_code=language_code)
55
55
    root_comments = Comment.objects.filter(post=article.post, reaction_to=None).order_by('-date')
56
56
    context = context | {
57
57
            'djhtml_file': "/tmp/blog-file-"+article.slug+".djhtml",
58
58
            'article': article,
59
59
            'root_comments': root_comments,
60
60
            'title': article.post.title(),
61
61
            'navbar_title': article.post.title(),
62
62
            'navbar_backArrow': False,
63
63
            'stylesheet_name': "blog"}
64
64
65
65
    return render(request, template, context)
66
66
67
67
def rss(request):
68
68
    template = "blog/feed.rss"
69
69
    context = {
70
70
        'items': FeedItem.objects.all(),
71
71
        }
72
72
    return render(request, template, context, content_type="application/rss+xml")
73
73
74
74
75
75
def archive(request):
76
76
    template = "blog/monthly_archive.djhtml"
77
77
    language = translation.get_language()
78
78
79
79
    file_2017 = org_to_html(settings.MEDIA_ROOT + "blog/weekly/2017.org", slug="arkivo-sizsig-2017")
80
80
    file_2018 = org_to_html(settings.MEDIA_ROOT + "blog/weekly/2018.org", slug="arkivo-sizsig-2018")
81
81
    file_2019 = org_to_html(settings.MEDIA_ROOT + "blog/weekly/2019.org", slug="arkivo-sizsig-2019")
82
82
    file_2020 = org_to_html(settings.MEDIA_ROOT + "blog/weekly/2020.org", slug="arkivo-sizsig-2020")
83
83
    file_2021 = org_to_html(settings.MEDIA_ROOT + "blog/weekly/2021.org", slug="arkivo-sizsig-2021")
84
84
+
85
    file_2023 = org_to_html(settings.MEDIA_ROOT + "blog/weekly/2023.org", slug="arkivo-sizsig-2023")
+
86
    file_2024 = org_to_html(settings.MEDIA_ROOT + "blog/weekly/2024.org", slug="arkivo-sizsig-2024")
+
87
85
88
86
89
87
90
88
91
89
92
    context = {
90
93
        't2017': file_2017,
91
94
        't2018': file_2018,
92
95
        't2019': file_2019,
93
96
        't2020': file_2020,
94
97
        't2021': file_2021,
95
98
            'navbar_title': _("Weekly-archief"),
+
99
        't2023': file_2023,
+
100
        't2024': file_2024,
+
101
            'navbar_title': _("Weekly-archief"),
96
102
            'navbar_backArrow': True,
97
103
            'stylesheet_name': "blog",
98
104
            }
99
105
    return render(request, template, context)
100
106