summaryrefslogtreecommitdiff
path: root/ishtar_common/views.py
diff options
context:
space:
mode:
Diffstat (limited to 'ishtar_common/views.py')
-rw-r--r--ishtar_common/views.py50
1 files changed, 48 insertions, 2 deletions
diff --git a/ishtar_common/views.py b/ishtar_common/views.py
index f5a58afad..ac4e995d1 100644
--- a/ishtar_common/views.py
+++ b/ishtar_common/views.py
@@ -24,6 +24,7 @@ from jinja2 import TemplateSyntaxError
import json
import logging
import os
+import re
import unicodedata
import urllib.parse
@@ -1115,11 +1116,11 @@ organization_merge = merge_action(
)
-class IshtarMixin(object):
+class IshtarMixin:
page_name = ""
def get_context_data(self, **kwargs):
- context = super(IshtarMixin, self).get_context_data(**kwargs)
+ context = super().get_context_data(**kwargs)
context["page_name"] = self.page_name
return context
@@ -1149,6 +1150,51 @@ class AdminLoginRequiredMixin(LoginRequiredMixin):
return super(AdminLoginRequiredMixin, self).dispatch(request, *args, **kwargs)
+class ChangelogView(IshtarMixin, LoginRequiredMixin, TemplateView):
+ template_name = "ishtar/changelog.html"
+ page_name = _("Changelog")
+ current_url = "changelog"
+
+ def update_read_version(self):
+ if not self.request.user or not hasattr(self.request.user, "ishtaruser") \
+ or not self.request.user.ishtaruser:
+ return
+ cache_key = f"{settings.PROJECT_SLUG}-news-version"
+ current_version = cache.get(cache_key)
+ if not current_version:
+ return
+ ishtar_user = models.IshtarUser.objects.get(pk=self.request.user.ishtaruser.pk)
+ if not ishtar_user.latest_news_version \
+ or ishtar_user.latest_news_version != current_version:
+ ishtar_user.latest_news_version = current_version
+ ishtar_user.save()
+
+ def get_context_data(self, **kwargs):
+ context = super().get_context_data(**kwargs)
+ changelog_dir = os.path.join(
+ settings.SHARE_BASE_PATH,
+ "changelog",
+ settings.LANGUAGE_CODE.split('-')[0]
+ )
+ if not os.path.exists(changelog_dir):
+ raise Http404()
+ page_number = int(kwargs.get("page", 0) or 0) or 1
+ if page_number == 1:
+ self.update_read_version()
+ changelog_file = os.path.join(changelog_dir, f"changelog_{page_number}.md")
+ if not os.path.exists(changelog_file):
+ raise Http404()
+ with open(changelog_file, "r") as changelog:
+ context["changelog"] = markdown(changelog.read())
+ if page_number > 1:
+ context["next"] = page_number - 1
+
+ changelog_file_next = os.path.join(changelog_dir, f"changelog_{page_number + 1}.md")
+ if os.path.exists(changelog_file_next):
+ context["previous"] = page_number + 1
+ return context
+
+
class ProfileEdit(LoginRequiredMixin, FormView):
template_name = "ishtar/forms/profile.html"
form_class = forms.ProfilePersonForm