enoren5 / tarot_juicer

Random tarot card generator + rudimentary Django CMS
MIT License
11 stars 12 forks source link
django python

TAROT JUICER

:godmode: ![Magick](https://img.shields.io/badge/Made%20with-Magic-orange?style=for-the-badge&logo=data:image/svg%2bxml;base64,PHN2ZyBpZD0iQ2FwYV8xIiBlbmFibGUtYmFja2dyb3VuZD0ibmV3IDAgMCA1MTIgNTEyIiBoZWlnaHQ9IjUxMiIgdmlld0JveD0iMCAwIDUxMiA1MTIiIHdpZHRoPSI1MTIiIHhtbG5zPSJodHRwOi8vd3d3LnczLm9yZy8yMDAwL3N2ZyI+PGc+PHBhdGggZD0ibTM5NS44MiAxODIuNjE2LTE4OC43MiAxODguNzItMTIuOTEgMS43Mi05LjM1IDIwLjU0LTM0LjMxIDM0LjMxLTExLjAxLS43My0xMS4yNSAyMi45OS01Ni40OCA1Ni40OGMtMi45MyAyLjkzLTYuNzcgNC4zOS0xMC42MSA0LjM5cy03LjY4LTEuNDYtMTAuNjEtNC4zOWwtMjIuNjItMjIuNjJoLS4wMWwtMjIuNjItMjIuNjNjLTUuODYtNS44Ni01Ljg2LTE1LjM2IDAtMjEuMjJsNzcuNjMtNzcuNjMgMTYuNi03LjAzIDUuNjYtMTUuMjMgMzQuMzEtMzQuMzEgMTQuODQtNC45MiA3LjQyLTE3LjM0IDE2Ny41Ny0xNjcuNTcgMzMuMjQgMzMuMjR6IiBmaWxsPSIjZjY2Ii8+PHBhdGggZD0ibTM5NS44MiAxMTYuMTQ2djY2LjQ3bC0xODguNzIgMTg4LjcyLTEyLjkxIDEuNzItOS4zNSAyMC41NC0zNC4zMSAzNC4zMS0xMS4wMS0uNzMtMTEuMjUgMjIuOTktNTYuNDggNTYuNDhjLTIuOTMgMi45My02Ljc3IDQuMzktMTAuNjEgNC4zOXMtNy42OC0xLjQ2LTEwLjYxLTQuMzlsLTIyLjYyLTIyLjYyIDMzNC42NC0zMzQuNjR6IiBmaWxsPSIjZTYyZTZiIi8+PHBhdGggZD0ibTUwNi42MSAyM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aWxsPSIjMzFiZWJlIiByPSIxNSIvPjxjaXJjbGUgY3g9IjQ0MCIgY3k9IjMyNy45NjciIGZpbGw9IiNhZDc3ZTMiIHI9IjE0Ljk5OSIvPjwvZz48L3N2Zz4=)

This is a rudimentary Django-based CMS which dynamically presents tarot-related content placed onto unconventional but familiar contexts such as hollywood film and historical biography. Our purpose is to overturn and reform the audience's perspective beyond all recognition. The author endeavours to reach out (or "appeal") to the broadest audience possible.

DJANGO APPS

Here are Django apps I've created and what their purpose is:

BUILD INSTRUCTIONS

For *nix:

$ virtualenv --python=python venv
$ source venv/bin/activate
$ pip install -r requirements.txt
$ python manage.py runserver

For handling, managing, and upgrading the latest packages, to construct a requirements.txt, we can leverage: $ pip-compile. To upgrade, use: $ pip-compile -U. pip will build the requirements.txt based on the paramaters established in requirements.in which will keep package versions pinned and updated. For more details on how to manage pacakges with best practices, including how to use pip-compile, head over to the Django Project forums in the topic titled: Best practices: Managing requirements.txt.

You will also need to install postgresql v12.3 natively in your operating system outside of the python virtual environment. To install postgresql on Manjaro/Arch, you cam use this:

$ sudo pacman -S postgresql postgresql-libs

USAGE NOTES

1. Swapping lorem ipsum db out with real prod db content

The official Heroku docs cover provisioning Postgres, designating a primary database, sharing Postgres db's between applications, and more. This doc explains how to juggle/change/swap out one db instance for another.

2. Postgres and cultivating an archive of backups

This note to self I moved into it's own (private - hidden) gist titled Guide to backing up Postgres on Friday 9 April 2021. More work needs to be done. My next step will involve either (a) learning AWS S3 or (b) writing a custom Python script using multiple symlinks to automate the download of Postgres instances and mirror them up to my Digital Ocean droplet.

3. Handling db remote instances but locally

It's possible to run a remote AWS Postgres db locally. It's as straightforward as running:

(local venv) $ export DATABASE_URL='postgres://USER:PASSWORD@HOST:PORT/NAME'

whose DATABASE_URL you can source from the Heroku Dashboard. If you are havinng trouble determining the right 'colored' DB you can use:

(local venv) $ heroku addons --app tarot-prod

You can also use:

(local venv) $ heroku pg:info --app tarot-prod

These commands should reveal the name of the add-on to distinguish the db with 'lorem' content from the db with 'real' content.

It's also very important to note that when exporting a db locally, you need to do it inside the same terminal that the local dev server is running in. For this to work, you'll need to exit the currnet local dev server, unset the existing db, export the db, and then finally run the server again.

You can view the current db configuration (probably db.sqlite3 default) with:

(local venv) $ echo $DATABASE_URL

To remove or backout from using a remote Postgres instance and reintroduce db.sqlite3, this is the command you need:

(local venv) $ unset DATABASE_URL

PLEASE NOTE and to emphasize once more: It's important that you handle all of the above commands in the same terminal emulator. If you run export $DATABASE_URL in one terminal, and then have the server running in a different terminal, it won't work. Use all of the above commands in the same terminal that you are running the local server in.

4. Config variables

In the Heroku Dashboard, here are some of the variables you need to change for it to work in the production enviornment:

5. Resolving empty thumbnails (tarot card album) static files

If you accidentally upload duplicate tumbnails (generator app), Django will append a small hash to the .jpg and it won't parse when Django serves the tarot_key template. It's kind of a bug. The problem should only happen remotely on Heroku. If that happens (and it doesn't happen all the time), then the recourse is to use this command on Heroku: (local venv) $ heroku run python manage.py collectstatic -a tarot-testing --noinput --clear --no-post-process. Be sure to specify the right app (whether tarot-testing or tarot-prod). That will purge all static files with hashes. I don't completely understand why, but UmarGit and I went back forth on Upwork on June 14th, 2021.

This was an issue (#92) resolved on 9 April 2021 but which became an issue again on 14 May.

There seems to be three staticfiles directories declared inside settings.py. The one inside tarot_juicer/tarot_juicer/static is for development locally. The directroy tarot_juicer/staticfiles houses the static files on Heroku which will be intialized and created with the pgbounce buildpack in the cloud - - so there is no need for this directory locally. I'm not sure what tarot_juicer/static is for.

6. heroku-cli x2

There are two heroku-cli app interfaces. The first heroku-cli app is installed locally for interacting between the local development environment and the remote server. The second heroku-cli app is installed remotely for interacting with itself. To install, you just navigate in Heroku settings for the app and click: “Add buildpack” and enter: https://buildpack-registry.s3.amazonaws.com/buildpacks/heroku-community/cli.tgz. Next go to Manage Account (settings - - top right corner of avatar icon). Then scroll down and select: “Regenerate API Key”. Next time you push changes and Heroku rebuilds everything, then heroku-cli should be installed. For future reference, you may use the official Heroku doc for managing authentication and API token storage.

7. Local dev server over HTTPS

I'm not sure what changed but one day the dev server began sponataneously complaining: "Error: You're accessing the development server over HTTPS, but it only supports HTTP" I had encountered this in the distant past. I can't recall the solution. But the solution today was to install a local SSL certificate using a guide titled, "How to run a local Django development server over HTTPS with a trusted self-signed SSL certificate." It was initially posted August 10th, 2021, so it is very recent (as of Januarny 2022 as a I write this). The guide targets macOS but there is a link to the GitHub page for the mkcert app that has an instructions for Arch-based distros using pacman whcih worked for me.

TO DO:

PURPOSE

"In a world where men do battle over whose version of God is most accurate, I cannot adequately express the deep respect and admiration I feel toward an organization in which men of differing faiths are able to break bread together in a bond of comradery, brotherhood, and friendship," - - On Freemasonry courtesy of Dan Brown in a 2009 interview as quoted on page 48-49 in Mark E Koltko-Rivera's (2011) Freemasonry: An Introduction (London England: Penguin Group)