Include slugified sponsor display name in token data
authorMagnus Hagander <magnus@hagander.net>
Wed, 17 Sep 2025 12:47:47 +0000 (14:47 +0200)
committerMagnus Hagander <magnus@hagander.net>
Wed, 17 Sep 2025 12:53:49 +0000 (14:53 +0200)
Commit a7ca59dc added to the dashboard for human consumption but it
makes sense to also have it in the json/yaml data downloads.

This also makes it possible to simplify the fetch_sponsorfiles.py script
since it no longer needs a copy of the django slugify function.

postgresqleu/confsponsor/util.py
tools/deploystatic/fetch_sponsorfiles.py

index 9e87617d86d92cb4c0143c12bc05dcf3646a4ae0..4907816b7efe541b254e9d4901d12182b105a20a 100644 (file)
@@ -2,6 +2,7 @@ from django.db.models import Q
 from django.shortcuts import get_object_or_404
 from django.conf import settings
 from django.utils import timezone
+from django.template.defaultfilters import slugify
 
 from postgresqleu.util.db import exec_to_list
 from postgresqleu.util.currency import format_currency
@@ -82,6 +83,7 @@ def sponsorclaimsdata(conference):
                     'sponsors': [
                         {
                             'name': s.displayname,
+                            'slugname': slugify(s.displayname),
                             'confirmedat': s.confirmedat,
                             'signedupat': s.signupat
                         } for s in lvl.sponsor_set.filter(confirmed=True).order_by('signupat')
@@ -90,6 +92,7 @@ def sponsorclaimsdata(conference):
             'sponsors': {
                 s.displayname: {
                     'name': s.displayname,
+                    'slugname': slugify(s.displayname),
                     'url': s.url,
                     'social': s.social,
                     'level': s.level.levelname,
index 86a7e7fdf52f8062d26028e3cec76b2679899fd5..e43bd4edf149b8cbe47db6a339570bc723e0e08a 100755 (executable)
@@ -16,15 +16,6 @@ import unicodedata
 import urllib.request
 
 
-# Slugify the names - needs to be compatible with django/jinja/deploystatic
-def slugify(value):
-    if not value:
-        return ''
-    value = unicodedata.normalize('NFKD', value).encode('ascii', 'ignore').decode('ascii')
-    value = re.sub(r'[^\w\s-]', '', value).strip().lower()
-    return re.sub(r'[-\s]+', '-', value)
-
-
 if __name__ == "__main__":
     parser = argparse.ArgumentParser(description='Fetch pgeu-system sponsor files from token URLs')
     parser.add_argument('tokenurl', type=str, help='Base URL including the token value, but not including the type of dta')
@@ -46,7 +37,7 @@ if __name__ == "__main__":
         for name, sponsorinfo in data['sponsors']['sponsors'].items():
             for benefit in sponsorinfo['benefits']:
                 if benefit['name'] == args.benefitname:
-                    filename = os.path.join(args.directory, '{}.png'.format(slugify(name)))
+                    filename = os.path.join(args.directory, '{}.png'.format(sponsorinfo['slugname']))
                     if os.path.isfile(filename):
                         # Check if this file is unchanged
                         with open(filename, 'rb') as f: