Anvil Advent Calendar

Build a web app every day until Christmas, with nothing but Python!

There are only a few shopping days left until Christmas!

If your friends and family haven’t already bought you everything you’ve always wanted, they might need some digital assistance.

Enter Christmalist! The sofware-as-a-service solution for your yuletide purchasing needs.

https://christmalist.anvil.app

It’s a wishlist, stored online, that you can share with your friends. Your friends can check off what they’ve bought to avoid double-buying.

Building a list

Here’s my wishlist:

This is a simple CRUD app - the “wish” button adds my items to a Data Table, with the ‘Owner’ column set to the Users row for whoever is logged in.

The owner column stores who wants each item.

The owner column stores who wants each item.

You’ve got to be logged in to make a list, so the first time the “wish” button is pressed, I display a login form using:

    anvil.users.login_with_form()

Sharing with friends

To share your list with a friend, you simply enter their email address:

The email is sent using anvil.email.send:

    anvil.email.send(
      to=email,
      subject=f"{user['email']} wants to share their wishlist with you on Christmalist!",
      text=f"""
        {user['email']} wants to share their wishlist with you on Christmalist!
       
        Follow this link to see it: https://christmalist.anvil.app/#?u={user['email']&k={key}}
      """,
      html=f"""
        <h1 style="color: #D32F2F">View your friend's wish list!</h1>
      
        {user['email']} wants to share their wishlist with you on Christmalist!<br><br>
       
        <a href="https://christmalist.anvil.app/#?u={user['email']}&k={key}">Click here</a> to see it!
      """,
    )

This email contains a link to Christmalist, with some query parameters that dictate whose list is being shared, and a random key to make sure people don’t randomly invent these links for themselves. Here’s an example:

https://christmalist.anvil.app/#?u=shaun@anvil.works&k=9de2e62f-ba19-4d21-8041-956cbf1da61f

The ‘Users’ table stores a list of valid keys. I check the k query param against the sharing_keys column to check that the link is valid.

Viewing your friends’ lists

Finally, you can view your friends’ lists by selecting them from a dropdown. If you’ve purchased that item for them, you can check the box so nobody else buys the same thing!

Go ahead and use it

The app is published at christmalist.anvil.app - go ahead and use it to streamline your present-receiving this year!

You can get the source code for yourself – you could even make a business out of it, using Anvil’s Stripe integration to take payments!

To get started, get your own copy of the source code, and tweak it however you like:


Give the Gift of Python

Share this post: