Ephes Blog

Miscellaneous things. Mostly Weeknotes and links I stumbled upon.


Weeknotes 2023-09-11

, Jochen
It was the best of times. It was the worst of terms and conditions. --Nein

At work, setting up Single Sign-On (SSO) via Azure AD for a Django project was easier than expected, thanks to django-saml2-auth. I also found that ChatGPT was surprisingly effective at generating code to create a simplified Excel file, which I then could use to test the effectiveness of the existing pandas code for Excel parsing.

Doing open source, I fixed a bug in the theme-selector feature of django-cast. The bug occurred because Django handles the HTML rendering for SPA-themes and exposes it via a JSON API. I chose this method to avoid rendering a Wagtail streamfield in JavaScript. However, it used the theme from the database instead of the session template, which broke the Vue.js theme. After addressing this, I updated django-stubs and fixed a minor issue that made mypy pass again. I also improved the documentation for the themes feature. While reviewing the request-handling code, I found a simpler method using APIField and wrote a 'Today I Learned' (TIL) post about it. And finally, I broke most of the images on my site by accidentally deleting all the Wagtail renditions. Well, something to do for next week.

Articles

Weeknotes

Software

Mastodon / Twitter

Videos

Podcasts


How to Pass a Request Object from Wagtail API to a Page

, Jochen

Introduction

When using Wagtail's API to fetch website pages, the APIField class allows you to add custom fields. But what if you also need to incorporate the request object into your custom field?

Why the Request Object is Important

I ran into this issue because I wanted to fetch the fully-rendered HTML of a page via the Wagtail API, eliminating the need to manually render the StreamField in my Vue.js blog theme.

Code Example

To achieve this, use the APIField class as demonstrated in the code snippet below:

from wagtail.models import Page
from wagtail.api import APIField

from rest_framework.fields import Field

class HtmlField(Field):
    def to_representation(self, page):
        return page.serve(self.context["request"])

class Post(Page):
    ...
    api_fields = [
        APIField("html", serializer=HtmlField(source="*")),
    ]

Understanding the source="*" Parameter

The `source="*"` parameter is special: it enables the `to_representation` method to work with the entire page object, rather than just a specific field on that page.


Weeknotes 2023-09-04

, Jochen
UIs are big, messy, mutable, stateful bags of sadness. --Josh Abernathy

Usual work week. Finally upgraded my Debian boxes from bullseye to bookworm and had no problems. Wow 🤯. Found a workaround for a long-standing PyCharm limitation: If you use a German keyboard layout, it's not possible to switch windows or comment out lines of code using keyboard shortcuts. Just install the Keymap Nationalizer Plugin and select your actual keyboard layout.

Didn't have much time for open source last week, but nonetheless managed to add a theme chooser for django-cast. You can now choose your theme and save the result in the session. So now it's possible for all users to try out new themes. Now I have a reason to polish the other themes a bit 😅. If you want to try it, just click on the B in the menu bar.

Articles

Weeknotes

Software

Mastodon / Twitter

Videos

Podcasts


Weeknotes 2023-08-28

, Jochen

"The first principle is that you must not fool yourself — and you are the easiest person to fool." (Feynman)


Started working on a new project, which is always exciting. Refactored django-cast filters.py -> it's almost readable now 😆. Facet counts are now available via the API, so cast-vue got an update showing filters for categories and tags.

Articles

Mastodon / Twitter

Software

Podcasts


Weeknotes 2023-08-21

, Jochen

We begin in admiration and end by organizing our disappointment. --Gaston Bachelard


Attended a local Django meetup in Cologne and had to learn that the one in Cologne is unfortunately the last active Django meetup in Germany 😢. The topic was django CMS which I knew nothing about, and I was surprised how similar it is to Wagtail which I use a lot.

Added a categories/tags feature (beta) to django-cast, which I postponed because I was afraid that messing with the faceted navigation code in filters.py (based on django-filter) would be hard. It turned out to be as hard as I expected, but now it's done 😅.

On Saturday we went hiking in the Neandertal 🥾, because that's where I live. And we managed to leave it the way you want to find it: as a fascinating puzzle for archaeologists. We did this by throwing a baby carriage (without the baby) into the Düssel (the river that formed the valley).

Articles

Websites

Videos

Books