From f3a136626900ffaec96c534fc9b162fff8c5661b Mon Sep 17 00:00:00 2001 From: badbl0cks <4161747+badbl0cks@users.noreply.github.com> Date: Thu, 20 Mar 2025 23:59:22 -0700 Subject: [PATCH] Fix gravatar hovercards, and add trade_offer image generation with playwright, for use with opengraph tags on trade_offer_detal.html --- Dockerfile | 6 +- accounts/migrations/0001_initial.py | 2 +- accounts/templatetags/gravatar.py | 2 +- cards/migrations/0001_initial.py | 2 +- django_project/settings.py | 8 +- docker-compose.yml | 18 +- requirements.txt | 3 + theme/templates/account/profile.html | 10 +- theme/templates/base.html | 11 +- .../templates/trades/trade_offer_detail.html | 10 +- theme/templatetags/card_badge.html | 16 +- theme/templatetags/trade_offer.html | 218 ++++++++++++------ trades/migrations/0001_initial.py | 2 +- trades/templatetags/trade_offer_tags.py | 6 +- trades/urls.py | 2 + trades/views.py | 179 ++++++++++++-- 16 files changed, 372 insertions(+), 123 deletions(-) diff --git a/Dockerfile b/Dockerfile index 6607bb6..03993ae 100644 --- a/Dockerfile +++ b/Dockerfile @@ -23,7 +23,9 @@ COPY .env.production /code/.env ENV HOME=/code # Install NPM & node.js -RUN apt-get update && apt-get install -y nodejs npm +RUN apt-get update && apt-get install -y nodejs npm xvfb libnss3 libnspr4 libasound2t64 libatk-bridge2.0-0 libatk1.0-0 libatspi2.0-0 libcairo2 libcups2 libdbus-1-3 libdrm2 libgbm1 libnspr4 libnss3 libpango-1.0-0 libx11-6 libxcb1 libxcomposite1 libxdamage1 libxext6 libxfixes3 libxkbcommon0 libxrandr2 libcairo-gobject2 libdbus-glib-1-2 libfontconfig1 libfreetype6 libgdk-pixbuf-2.0-0 libgtk-3-0 libharfbuzz0b libpangocairo-1.0-0 libx11-xcb1 libxcb-shm0 libxcursor1 libxi6 libxrender1 libxtst6 libsoup-3.0-0 gstreamer1.0-libav gstreamer1.0-plugins-base gstreamer1.0-plugins-good libegl1 libenchant-2-2 libepoxy0 libevdev2 libgles2 libglx0 libgstreamer-gl1.0-0 libgstreamer-plugins-base1.0-0 libgstreamer1.0-0 libgtk-4-1 libgudev-1.0-0 libharfbuzz-icu0 libhyphen0 libicu72 libjpeg62-turbo liblcms2-2 libmanette-0.2-0 libnotify4 libopengl0 libopenjp2-7 libopus0 libpng16-16 libproxy1v5 libsecret-1-0 libwayland-client0 libwayland-egl1 libwayland-server0 libwebp7 libwebpdemux2 libwoff1 libxml2 libxslt1.1 libatomic1 libevent-2.1-7 libavif16 xvfb fonts-noto-color-emoji fonts-unifont xfonts-scalable fonts-liberation fonts-ipafont-gothic fonts-wqy-zenhei fonts-tlwg-loma-otf fonts-freefont-ttf + +RUN playwright install-deps && playwright install # Expose port 8000 EXPOSE 8000 @@ -32,5 +34,7 @@ EXPOSE 8000 RUN python manage.py collectstatic --noinput +#RUN python manage.py createcachetable django_cache + # Use gunicorn on port 8000 CMD ["gunicorn", "--bind", ":8000", "--workers", "2", "django_project.wsgi"] diff --git a/accounts/migrations/0001_initial.py b/accounts/migrations/0001_initial.py index dfc7763..0cab225 100644 --- a/accounts/migrations/0001_initial.py +++ b/accounts/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2025-03-17 20:39 +# Generated by Django 5.1.2 on 2025-03-20 00:08 import django.contrib.auth.models import django.contrib.auth.validators diff --git a/accounts/templatetags/gravatar.py b/accounts/templatetags/gravatar.py index ea47edc..3aab3ba 100644 --- a/accounts/templatetags/gravatar.py +++ b/accounts/templatetags/gravatar.py @@ -21,7 +21,7 @@ def gravatar_url(email, size=20): Returns the Gravatar URL for a given email. The URL includes parameters for the default image and the size. """ - default = "wavatar" + default = "retro" email_hash = gravatar_hash(email) params = urlencode({'d': default, 's': str(size)}) return f"https://www.gravatar.com/avatar/{email_hash}?{params}" diff --git a/cards/migrations/0001_initial.py b/cards/migrations/0001_initial.py index 552e7ea..6cb7d2a 100644 --- a/cards/migrations/0001_initial.py +++ b/cards/migrations/0001_initial.py @@ -1,4 +1,4 @@ -# Generated by Django 5.1.2 on 2025-03-17 20:39 +# Generated by Django 5.1.2 on 2025-03-20 00:08 import django.db.models.deletion from django.db import migrations, models diff --git a/django_project/settings.py b/django_project/settings.py index 4a36451..f0f1182 100644 --- a/django_project/settings.py +++ b/django_project/settings.py @@ -56,6 +56,7 @@ INSTALLED_APPS = [ "cards", "home", "trades.apps.TradesConfig", + "meta", #"silk", ] @@ -67,6 +68,11 @@ SILKY_META = True TAILWIND_APP_NAME = 'theme' +META_SITE_NAME = 'PKMN Trade Club' +META_SITE_PROTOCOL = 'https' +META_USE_SITES = True +META_IMAGE_URL = 'https://pkmntrade.club/' + # https://docs.djangoproject.com/en/dev/ref/settings/#middleware MIDDLEWARE = [ "django.middleware.security.SecurityMiddleware", @@ -299,6 +305,6 @@ else: CACHES = { "default": { "BACKEND": "django.core.cache.backends.db.DatabaseCache", - "LOCATION": "site-cache", + "LOCATION": "django_cache", } } \ No newline at end of file diff --git a/docker-compose.yml b/docker-compose.yml index 401a9af..90a69f3 100644 --- a/docker-compose.yml +++ b/docker-compose.yml @@ -1,13 +1,13 @@ services: -# web: -# build: . -# command: python /code/manage.py runserver 0.0.0.0:8000 -# volumes: -# - .:/code:z -# ports: -# - 8000:8000 -# depends_on: -# - db + # web: + # build: . + # command: python /code/manage.py runserver 0.0.0.0:8000 + # volumes: + # - .:/code:z + # ports: + # - 8000:8000 + # depends_on: + # - db db: image: postgres:16 ports: diff --git a/requirements.txt b/requirements.txt index 759a4bf..55d4b3b 100644 --- a/requirements.txt +++ b/requirements.txt @@ -14,11 +14,13 @@ django-daisy==1.0.13 django-debug-toolbar==4.4.6 django-el-pagination==4.1.2 django-environ==0.12.0 +django-meta==2.4.2 django-silk==5.3.1 django-tailwind-4[reload]==0.1.4 django-widget-tweaks==1.5.0 gunicorn==23.0.0 idna==3.4 +imgkit==1.2.3 oauthlib==3.2.2 packaging==23.1 psycopg==3.2.3 @@ -26,6 +28,7 @@ psycopg-binary==3.2.3 pycparser==2.21 PyJWT==2.6.0 python3-openid==3.2.0 +playwright==1.51.0 requests==2.28.2 requests-oauthlib==1.3.1 sqlparse==0.4.3 diff --git a/theme/templates/account/profile.html b/theme/templates/account/profile.html index 50ad857..087badc 100644 --- a/theme/templates/account/profile.html +++ b/theme/templates/account/profile.html @@ -10,13 +10,19 @@
All profile information is managed through Gravatar.
- ++ + Edit Profile on Gravatar + +
Gravatar (Globally Recognized Avatar) is a free service that links your email address to a profile picture and, optionally, a profile. Many websites, including this one, use Gravatar to display your avatar and profile automatically.
If you’ve set up a Gravatar, your profile picture will appear here whenever you use your email on supported sites. When someone hovers over or clicks on your avatar, your Gravatar profile will appear if you have one. If you don’t have a Gravatar yet, you’ll see a default image instead.
+If you've set up a Gravatar, your profile picture will appear here whenever you use your email on supported sites. When someone hovers over or clicks on your avatar, your Gravatar profile will also appear if you have one. If you don't have a Gravatar yet, you'll see a default image instead.
Go to Gravatar.com to set up or change your avatar or profile. Your updates will appear here once saved!
diff --git a/theme/templates/base.html b/theme/templates/base.html index 42ca995..e03166e 100644 --- a/theme/templates/base.html +++ b/theme/templates/base.html @@ -9,7 +9,8 @@ - + {% include 'meta/meta.html' %} +