Last active
July 11, 2025 10:38
-
-
Save timcowlishaw/044cd4cd2080b048358c997d4a2d5e5c to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generated by Django 5.0.9 on 2025-05-09 15:55 | |
| import django.db.models.deletion | |
| import taggit.managers | |
| from django.db import migrations, models | |
| from django.utils.text import slugify | |
| class Migration(migrations.Migration): | |
| dependencies = [] | |
| operations = [ | |
| migrations.CreateModel( | |
| name="VerificationBasis", | |
| fields=[ | |
| ( | |
| "id", | |
| models.AutoField( | |
| auto_created=True, | |
| primary_key=True, | |
| serialize=False, | |
| verbose_name="ID", | |
| ), | |
| ), | |
| ( | |
| "name", | |
| models.CharField(max_length=255, unique=True, verbose_name="name"), | |
| ), | |
| ( | |
| "slug", | |
| models.SlugField( | |
| allow_unicode=True, | |
| max_length=255, | |
| unique=True, | |
| verbose_name="slug", | |
| ), | |
| ), | |
| ], | |
| options={ | |
| "verbose_name": "Basis for verification", | |
| "verbose_name_plural": "Bases for verification", | |
| }, | |
| ), | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # Generated by Django 5.0.9 on 2025-05-09 15:55 | |
| import django.db.models.deletion | |
| import taggit.managers | |
| from django.db import migrations, models | |
| from django.utils.text import slugify | |
| class Migration(migrations.Migration): | |
| def verification_bases_permissions(apps, schema_editor): | |
| pr_perms_codenames = [ | |
| "add_verificationbasis", | |
| "change_verificationbasis", | |
| "view_verificationbasis", | |
| "delete_verificationbasis" | |
| ] | |
| pr_perms = Permission.objects.filter(codename__in=pr_perms_codenames) | |
| admin, _ = Group.objects.get_or_create(name="admin") | |
| admin.permissions.add(*pr_perms) | |
| dependencies = [ | |
| ("accounts", "0001_create_verification_basis"), | |
| ] | |
| operations = [ | |
| migrations.RunPython(verification_bases_permissions), | |
| ] |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| from django_mysql.models import EnumField | |
| from django.utils.translation import gettext_lazy as _ | |
| from django.utils.translation import pgettext_lazy | |
| from django.utils.safestring import mark_safe | |
| from taggit import models as tag_models | |
| class VerificationBasis(tag_models.TagBase): | |
| """ | |
| A model representing reasons why a provider would be verified. | |
| This includes things like | |
| "We use 100% green energy from our own infrastructure.", | |
| "We operate in a region that has a grid intensity of less than 20g CO2e/kWh or uses over 99% renewable power.", | |
| "We directly pay for green energy to cover the non-green energy we use.", | |
| "We purchase quality carbon offsets to cover the non-green energy we use.", | |
| "We resell or actively use a provider that is already in the Green Web Dataset.", | |
| A subclass of Taggit's 'TagBase' model. | |
| """ | |
| # Annoyingly, the only way to override the max_length in taggit appears to be to copy and adjust | |
| # these two field definitions wholesale: https://github.com/jazzband/django-taggit/issues/510 | |
| name = models.CharField( | |
| verbose_name=pgettext_lazy("A tag name", "name"), unique=True, max_length=255 | |
| ) | |
| slug = models.SlugField( | |
| verbose_name=pgettext_lazy("A tag slug", "slug"), | |
| unique=True, | |
| max_length=255, | |
| allow_unicode=True, | |
| ) | |
| required_evidence_link = models.URLField( | |
| max_length=255, null=True, blank=True, | |
| verbose_name="Required evidence link" | |
| ) | |
| class Meta: | |
| verbose_name = _("Basis for verification") | |
| verbose_name_plural = _("Bases for verification") | |
| @property | |
| def label(self): | |
| label = self.name | |
| if self.required_evidence_link is not None and self.required_evidence_link.strip() != "": | |
| label += f" (<a href='{self.required_evidence_link}' target='_blank'>see required evidence</a>)" | |
| return mark_safe(label) | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment