Day 20 Dev Notes
More template tags and more template refactoring tonight.
I created a post_date_link
tag that displays a nicely rendered date with links to each of the date archives sections.
More template tags and more template refactoring tonight.
I created a post_date_link
tag that displays a nicely rendered date with links to each of the date archives sections.
Tonight, I created a couple of custom template tags that can be used to display an author link and a category link. These tags first check if the respective options are enabled, and if they are, they return nicely formatted links.
More work on the DJPress URL structure tonight. It's slowly taking shape as I work it all out.
Did some more work on the mortgage tools app, with some form changes and tweaks to the scenario calculator. This was a good reminder of how Django forms work; it's been ages since I got down in the weeds with Django forms.
Recently I've just used crispy-forms to take care of the styling, but I took this opportunity to see how much work is involved in styling forms without the helper package. I think for a simple form like this with just 5 fields, it's not too bad. But crispy-forms is definitely the easier option.
I didn't post any code on the 9th May, but I did launch a whole new project after my last post about updating "My Django X", so I'm going to claim that as keeping my streak alive.
After that post, I wanted to see how quickly I could spin up a functioning project, so I took something I had been playing with in Excel and converted it into a Django app. This formed the start of a new project called "Mortgage Tools".
We will need to be making some decisions about mortgage rates soon, and I had been working on a calculator to compare scenarios. For example, let's say I could lock in a 24-month fixed rate at 6.75% today, or, I could get a higher rate of 7.29% for 12 months with the hope of the rate dropping in the future. The question is, what would the rate have to drop by to make it worthwhile.
This is the first calculator on the project, but now that I have it set up, I will add a bunch of other related calculators to help make these decisions.
But while this is going to be super useful, the main aim was to see how quickly I could spin up a project using the mydjangox
template. And I'm happy to say this was really quick and easy. The challenge now is to keep the template project up to date so that I can keep it useful.
I continued thinking about the URL matching for djpress
but didn't actually write any code for this. Unless, if you count playing with regular expressions, "writing code".
Instead, I took some time out to update my MyDjangoX
project, which is inspired by Will Vincent's DjangoX project.
More work on the URL structure. It's getting there, but is way more complicated than I'd like.
Still moving forward...
Big update to the URL structure this evening. I'll write more soon, but it's late now...
Just some tweaking of the PostHog integration this evening. Yesterday, I added the PostHog configuration and set it up so that the API key is loaded from the environment variables. But silly me - I forgot to add the environment variables to the Docker configuration, so they weren't being loaded into the app.
Today, I added the JavaScript integration to the Bus Times app. Still not sure what value it will add, but it's interesting to play with this stuff. Adding the JavaScript snippet posed a new challenge - I needed to include the API key in the JavaScript code, but I didn't want to hard code this in the template, and I didn't want to modify all the views to pass the key in the context. So with some help from my AI friends, I created a context processor, which isn't something I've used before in Django.
Just one minor change today. After listening to the latest episode of Django Chat, I decided to try out PostHog after a recommendation from Michael Kennedy.
I set up an account and installed the snippet on my Bus Times app. Still not sure if this will bring value, but the basic service is free and so I can try out and see what I think.
More refactoring again, renaming content
to post
in various part of the code. I also made a couple of small functional changes:
author_display_name
property to the Post model. All this does right now is show the first name if it's set, otherwise it shows the username, but this could be more configurable in the future.MARKDOWN_EXTENSIONS
. I may use this to help decide whether to load the Pygments CSS file since that's only needed if the codehilite
extension is used. But that's something to think about another day, since there are some other concerns with making this too configurable.Continuing to tweak the djpress package with the intention of moving into a standalone package. I thought I would start on moving it tonight, but I quickly realised that the packaging landscape is full of differing opinions and I need to do some more research on how best to do this.
The following two links seem to mostly agree with each other, so I will probably start with these:
But I also need to see how tools like Hatch, Flit, and others fit into the mix. Or perhaps that's overcomplicating things. Let's see.
OK, this is starting to take shape. At least in my head it is.
I've decided to separate out the djpress package into a standalone package and will eventually publish it to PyPi. I've also refactored a lot of code, and now I'm starting to work out what I want from this package.