Daily Dev Notes 2024/06/04
Did some work on the post_content
template tag. I changed it so that if it detects there's a Posts
object in the context, it will show the truncated post by default.
Did some work on the post_content
template tag. I changed it so that if it detects there's a Posts
object in the context, it will show the truncated post by default.
Finally got to 100% test coverage! This has been a great experience and I've learned so much about testing by divining into some gnarly edge-cases. It's also told me that even the bits of code that I thought I was properly testing, needed further tests to fully cover the edge-cases.
Still doing nothing else apart from working on pytest. After finally figuring out the issues I was dealing with, I went through all of the tests and standardised my approach to dealing with application settings.
More testing, testing, testing...
I've been really focusing on the bit of code I've got for getting and setting application-level settings. While the code itself seemed fine, I was running into all sorts of weird bugs when running my tests.
No real coding today, but did tidy up some infrastructure issues at home. I had been trying out GlichTip, which is a self-hosted Sentry alternative. I hadn't been super happy with it, but was giving it some time to collect some stats before making a decision on it.
Testing, testing, testing...
Been spending some time catching up on testing. Decided to try out Coverage for the first time, and this has been an interesting experience. I already had pretty test coverage, but Coverage pointed out some edge cases that I had missed. And while I was trying to test out these edge cases, I discovered some bugs.
Last week I implemented a Markdown Previewer using HTMX, which was fairly rudimentary - it just POST
ed the contents of a textarea
element to a Django view that returned the converted content, which HTMX swapped into the preview div
element.
While this worked pretty well, I wasn't overly keen of the constant stream of POST
requests that were being streamed to the server. I had played with some different delays to reduce the number of requests - but the higher the delay, the less interactive it felt. I also didn't want to implement a client-side markdown renderer with JavaScript, because I wanted to use the same renderer in the previewer that I'm using on this site.
Finally starting to feel like I'm getting on top of this package publishing business. Yesterday I managed to get a project structure more or less sorted out, which also let me run proper linting, formatting, and tests.
Today I focused on implementing GitHub Actions workflows so that the full test suite runs on commit, and new packages are built and uploaded to PyPi!
A lot of restructuring the DJ Press code base tonight, but I think I've got it into shape now. I can finally run my tests, and in doing so found some bugs that had crept in. I've also got my pre-commit hooks all updated and working again, which also meant that I got to clean up some mess that had crept in.
Made some minor tweaks to the categories tags today. But that was a quick and easy change.
The main thing I need to focus on now, is a better workflow to work on this package. I'm still not sure how to test this package since it requires a Django site to test, and that's not included in the package for obvious reasons. Not sure how best to do this, but will do some digging because this must be a solved problem given the sheer number of Django packages available.
I took the plunge today and finally ripped out djpress
into its own, stand-alone package. I mostly followed this guide from Django, which linked through to a tutorial on the Python Packaging site which explained how to build and upload it.
After following the steps, I managed to get the package deployed to PyPi, and created a new public repository to host the code!
I started this blog 31 days ago with the aim of committing code and blogging about it every day for a month. I've achieved that goal, and am now feeling more energised than ever to keep this going.
The main reason I did this was that I was stuck on a gnarly re-write of DJ Checkup and I couldn't get motivated to keep working on it. Then, I picked up James Clear's book Atomic Habits, and he talks a lot about starting small habits. So that was the idea: commit at least once per day, and blog about it.
Just a small change today. I was having so much fun with the Markdown previewer that I add a keyup
event so that it became a live previewer, rather than having to press the Preview button.
I did some searching online today, looking for a Markdown editor that I could easily embed in a page, so that I could provide a better editing experience for posts. But while I was searching, I had an idea - what if I just built a Markdown previewer alongside a regular textarea
element.
So I gave it a quick go, and it worked!
Had some fun this evening. I installed a self-hosted error-tracking application called GlitchTip. It's written in Python and Django and is compatible with Sentry - in fact, to integrate the error reporting into your app, you install the Sentry SDK and configure the DSN to a GlitchTip-specific URL for your own installation.
Installation was fairly straight forward. The Docker compose file they provided was easy to modify for Portainer, but there were a couple of undocumented settings that I had to figure out along the way. But once it was up and running, it was easy to set up the projects and get the client reporting errors.
After yesterday's success updating requirements for Bus Times, I decided to do the same with the Amanzi website. This is an extremely simple Django site that serves a single static template from a view. No admin, or authentication, or databases required.
Should have been a simple update, but I decided to take this opportunity to also modernise the code base a bit by adding the pre-commit hooks I've been using on other projects. Which, of course, meant ensuring that everything was nicely formatted with Ruff. And then I noticed that the Whitenoise configuration was a bit out of date too, along with the Docker configuration too...
Busy night, so not much time to work on DJPress. But to keep my streak going, I updated the requirements for the Bus Times app.
This was my first attempt at creating a template tag that loops through the categories for a post and returns HTML output. I need to avoid this getting too confusing, but for now you specific if you want the outer tag to be a <ul>
, <div>
, or a <span>
. You can also specify additional classes that get added to the link, which was already in place from the post_category_link
tag.
Added a new post category tonight, along with tests.
Next up, I need to think about looping through categories and how I can create template tags to deal with this.
Quick post about this macOS utility called LinearMouse I just discovered. It provides per-mouse configurations and lets me set the scroll direction on the trackpad separately than the scroll direction on the mouse. I'm not sure if I'm a special use-case, but this is the way I like it to be, and for some reason macOS does not let you do this.