DEV Community

Kelvin Wangonya
Kelvin Wangonya

Posted on

Progress: rethinking the implementation

Initially, I wanted to have python (somehow) directly manipulate the DOM based on the state of document.monetization.state. I didn't know if it was possible but I figured there must be a way because, well, it's python.

After trying out a couple of ways, I realized it's just not as simple as I thought to access document from python and still keep the project free from a whole bunch of dependencies. As a solution, I think I have to include a small js script to provide an interface between what's going on in the browser and the backend.

I've been a bit hesitant to take this approach because I wanted to keep it all python, but this seems like the best thing to do for now.

While this whole thing can be done much easier in Javascript, I still feel like it's worth providing a python implementation for people who would like to include monetization to their flask/django projects without having to write the javascript themselves.

So, the idea remains the same. I still want to be able to do

from monetize import check_state

def monetized_page():
    state = check_state()
    if state == 'started':
        # implement logic to offer monetized content
        # do something else
Enter fullscreen mode Exit fullscreen mode

It's just how to achieve it that's changing.

Top comments (2)

bernardbaker profile image
Bernard Baker

Glad to see you're making progress. We had a team member leave. Well it was more of a no show. No commitment. I'll update everyone with our progress tomorrow 👍.

thisdotmedia_staff profile image
This Dot Media

Really cool that you're stepping in and trying something different/experimenting! Hope the new implementation goes well. Look forward to your findings 🙏