Skip to content

Commit

Permalink
Merge pull request #41 from unicef/warnings
Browse files Browse the repository at this point in the history
address warnings
  • Loading branch information
domdinicola authored May 3, 2024
2 parents e2c47d2 + 7cf0fc7 commit 2085181
Show file tree
Hide file tree
Showing 10 changed files with 140 additions and 21 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/test.yml
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,6 @@ jobs:
- name: Run tests
run: pdm run pytest tests/ --create-db

- uses: codecov/codecov-action@v1
- uses: codecov/codecov-action@v4
with:
verbose: false # optional (default = false)
4 changes: 1 addition & 3 deletions docker/Dockerfile
Original file line number Diff line number Diff line change
Expand Up @@ -50,9 +50,7 @@ ENV PATH="${PATH}:/root/.local/bin:/code/__pypackages__/3.11/bin" \
VERSION=${VERSION} \
POETRY_VERSION=${POETRY_VERSION}

# STATICFILES_STORAGE="django.contrib.staticfiles.storage.StaticFilesStorage" \

RUN pip install pdm==2.9.3
RUN pip install pdm==2.15.1
ADD pyproject.toml pdm.toml pdm.lock ./
RUN sed -i 's/use_venv = true/use_venv = false/' pdm.toml
RUN pdm sync --prod --no-editable --no-self
Expand Down
2 changes: 1 addition & 1 deletion src/aurora/config/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -53,6 +53,7 @@ def parse_emails(value):
"CSRF_COOKIE_NAME": (str, "aurora"),
"DEBUG": (bool, False),
"DEBUG_PROPAGATE_EXCEPTIONS": (bool, False),
"DEFAULT_FILE_STORAGE": (str, "django.core.files.storage.FileSystemStorage"),
"DJANGO_ADMIN_TITLE": (str, "Aurora"),
"EMAIL_BACKEND": (str, "anymail.backends.mailjet.EmailBackend"),
"MAILJET_API_KEY": (str, ""),
Expand Down Expand Up @@ -93,7 +94,6 @@ def parse_emails(value):
# "CSP_DEFAULT_SRC": (list, ),
# "CSP_SCRIPT_SRC": (str, None),
# "FERNET_KEY": (str, "Nl_puP2z0-OKVNKMtPXx4jEI-ox7sKLM7CgnGT-yAug="),
# "STATICFILES_STORAGE": (str, "django.contrib.staticfiles.storage.StaticFilesStorage"),
# "STATIC_ROOT": (str, "/tmp/static/"),
# Sentry - see CONTRIBUTING.md
}
Expand Down
12 changes: 9 additions & 3 deletions src/aurora/config/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -264,9 +264,15 @@
# STATIC_URL = f"/static/{os.environ.get('VERSION', '')}/"
STATIC_URL = env("STATIC_URL")
STATIC_ROOT = env("STATIC_ROOT") + STATIC_URL # simplify nginx config
# STATICFILES_STORAGE = "django.contrib.staticfiles.storage.StaticFilesStorage"
# STATICFILES_STORAGE = "django.contrib.staticfiles.storage.ManifestStaticFilesStorage"
STATICFILES_STORAGE = env("STATICFILES_STORAGE")

STORAGES = {
"default": {
"BACKEND": env("DEFAULT_FILE_STORAGE"),
},
"staticfiles": {
"BACKEND": env("STATICFILES_STORAGE"),
},
}

STATICFILES_DIRS = [
os.path.join(BASE_DIR, "web/static"),
Expand Down
19 changes: 19 additions & 0 deletions src/aurora/core/migrations/0056_case_insensitive_collation.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# Generated by Django 4.2.10 on 2024-05-03 06:31
from django.contrib.postgres.operations import CreateCollation
from django.db import migrations


class Migration(migrations.Migration):

dependencies = [
("core", "0055_alter_project_slug"),
]

operations = [
CreateCollation(
"_",
provider="icu",
locale="und-u-ks-level2",
deterministic=False,
),
]
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
# Generated by Django 4.2.10 on 2024-05-03 06:32

import django.core.validators
from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0056_case_insensitive_collation"),
]

operations = [
migrations.AlterField(
model_name="customfieldtype",
name="name",
field=models.CharField(
db_collation="_",
max_length=100,
unique=True,
validators=[django.core.validators.RegexValidator("[A-Z][a-zA-Z0-9_]*")],
),
),
migrations.AlterField(
model_name="flexform",
name="name",
field=models.CharField(db_collation="_", max_length=255, unique=True),
),
migrations.AlterField(
model_name="flexformfield",
name="name",
field=models.CharField(
blank=True,
db_collation="_",
max_length=100,
validators=[django.core.validators.RegexValidator("^[a-z_0-9]*$")],
),
),
migrations.AlterField(
model_name="formset",
name="name",
field=models.CharField(max_length=255),
),
migrations.AlterField(
model_name="optionset",
name="name",
field=models.CharField(
db_collation="_",
max_length=100,
unique=True,
validators=[django.core.validators.RegexValidator("[a-z0-9-_]")],
),
),
migrations.AlterField(
model_name="organization",
name="name",
field=models.CharField(db_collation="_", max_length=100, unique=True),
),
migrations.AlterField(
model_name="project",
name="name",
field=models.CharField(db_collation="_", max_length=100, unique=True),
),
migrations.AlterField(
model_name="validator",
name="label",
field=models.CharField(db_collation="_", max_length=255),
),
migrations.AlterField(
model_name="validator",
name="name",
field=models.CharField(
blank=True, db_collation="_", max_length=255, null=True, unique=True, verbose_name="Function Name"
),
),
]
23 changes: 13 additions & 10 deletions src/aurora/core/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

from django import forms
from django.contrib.admin.templatetags.admin_urls import admin_urlname
from django.contrib.postgres.fields import CICharField
from django.core.cache import caches
from django.core.exceptions import ValidationError
from django.core.validators import RegexValidator
Expand Down Expand Up @@ -66,7 +65,7 @@ class Organization(AdminReverseMixin, NaturalKeyModel, MPTTModel):
version = AutoIncVersionField()
last_update_date = models.DateTimeField(auto_now=True)

name = CICharField(max_length=100, unique=True)
name = models.CharField(max_length=100, unique=True, db_collation="_")
slug = models.SlugField(max_length=100, unique=True, blank=True, null=True)
parent = TreeForeignKey("self", on_delete=models.CASCADE, null=True, blank=True, related_name="children")

Expand Down Expand Up @@ -95,7 +94,7 @@ class Project(AdminReverseMixin, NaturalKeyModel, MPTTModel):
version = AutoIncVersionField()
last_update_date = models.DateTimeField(auto_now=True)

name = CICharField(max_length=100, unique=True)
name = models.CharField(max_length=100, unique=True, db_collation="_")
slug = models.SlugField(max_length=100, blank=True)
organization = models.ForeignKey(Organization, related_name="projects", on_delete=models.CASCADE)
parent = TreeForeignKey("self", on_delete=models.CASCADE, null=True, blank=True, related_name="children")
Expand Down Expand Up @@ -161,8 +160,10 @@ class Validator(AdminReverseMixin, NaturalKeyModel):
version = AutoIncVersionField()
last_update_date = models.DateTimeField(auto_now=True)

label = CICharField(max_length=255)
name = CICharField(verbose_name=_("Function Name"), max_length=255, unique=True, blank=True, null=True)
label = models.CharField(max_length=255, db_collation="_")
name = models.CharField(
verbose_name=_("Function Name"), max_length=255, unique=True, blank=True, null=True, db_collation="_"
)
code = models.TextField(blank=True, null=True)
target = models.CharField(
max_length=10,
Expand Down Expand Up @@ -303,7 +304,7 @@ class FlexForm(AdminReverseMixin, I18NModel, NaturalKeyModel):
version = AutoIncVersionField()
last_update_date = models.DateTimeField(auto_now=True)
project = models.ForeignKey(Project, on_delete=models.CASCADE)
name = CICharField(max_length=255, unique=True)
name = models.CharField(max_length=255, unique=True, db_collation="_")
base_type = StrategyClassField(registry=form_registry, default=FlexFormBaseForm)
validator = models.ForeignKey(
Validator, limit_choices_to={"target": Validator.FORM}, blank=True, null=True, on_delete=models.PROTECT
Expand Down Expand Up @@ -458,7 +459,7 @@ class FormSet(AdminReverseMixin, NaturalKeyModel, OrderableModel):
version = AutoIncVersionField()
last_update_date = models.DateTimeField(auto_now=True)

name = CICharField(max_length=255)
name = models.CharField(max_length=255)
title = models.CharField(max_length=300, blank=True, null=True)
description = models.TextField(max_length=2000, blank=True, null=True)
enabled = models.BooleanField(default=True)
Expand Down Expand Up @@ -567,7 +568,7 @@ class FlexFormField(AdminReverseMixin, NaturalKeyModel, I18NModel, OrderableMode

flex_form = models.ForeignKey(FlexForm, on_delete=models.CASCADE, related_name="fields")
label = models.CharField(max_length=2000)
name = CICharField(max_length=100, blank=True, validators=[RegexValidator("^[a-z_0-9]*$")])
name = models.CharField(max_length=100, blank=True, validators=[RegexValidator("^[a-z_0-9]*$")], db_collation="_")
field_type = StrategyClassField(registry=field_registry, import_error=import_custom_field)
choices = models.CharField(max_length=2000, blank=True, null=True)
required = models.BooleanField(default=False)
Expand Down Expand Up @@ -750,7 +751,7 @@ def get_from_cache(self, name):
class OptionSet(AdminReverseMixin, NaturalKeyModel, models.Model):
version = AutoIncVersionField()
last_update_date = models.DateTimeField(auto_now=True)
name = CICharField(max_length=100, unique=True, validators=[RegexValidator("[a-z0-9-_]")])
name = models.CharField(max_length=100, unique=True, validators=[RegexValidator("[a-z0-9-_]")], db_collation="_")
description = models.CharField(max_length=1000, blank=True, null=True)
data = models.TextField(blank=True, null=True)
separator = models.CharField(max_length=1, default="", blank=True)
Expand Down Expand Up @@ -848,7 +849,9 @@ def clean_choices(value):


class CustomFieldType(AdminReverseMixin, NaturalKeyModel, models.Model):
name = CICharField(max_length=100, unique=True, validators=[RegexValidator("[A-Z][a-zA-Z0-9_]*")])
name = models.CharField(
max_length=100, unique=True, validators=[RegexValidator("[A-Z][a-zA-Z0-9_]*")], db_collation="_"
)
base_type = StrategyClassField(registry=field_registry, default=forms.CharField)
attrs = models.JSONField(default=dict)
regex = RegexField(blank=True, null=True)
Expand Down
18 changes: 18 additions & 0 deletions src/aurora/registration/migrations/0053_alter_registration_name.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
# Generated by Django 4.2.10 on 2024-05-02 23:32

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("registration", "0052_alter_registration_slug"),
]

operations = [
migrations.AlterField(
model_name="registration",
name="name",
field=models.CharField(db_collation="_", max_length=255),
),
]
3 changes: 1 addition & 2 deletions src/aurora/registration/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@

from django.conf import settings
from django.contrib.flatpages.models import FlatPage
from django.contrib.postgres.fields import CICharField
from django.db import models
from django.utils import timezone, translation
from django.utils.functional import cached_property
Expand Down Expand Up @@ -55,7 +54,7 @@ class Registration(NaturalKeyModel, I18NModel, models.Model):
version = AutoIncVersionField()
last_update_date = models.DateTimeField(auto_now=True)

name = CICharField(max_length=255)
name = models.CharField(max_length=255, db_collation="_")
title = models.CharField(max_length=500, blank=True, null=True)
slug = models.SlugField(max_length=500, blank=True, null=True, unique=True)
project = models.ForeignKey(Project, on_delete=models.CASCADE, related_name="registrations")
Expand Down
2 changes: 1 addition & 1 deletion tests/conftest.py
Original file line number Diff line number Diff line change
Expand Up @@ -45,7 +45,7 @@ def pytest_configure(config):

from django.conf import global_settings, settings

settings.STATICFILES_STORAGE = global_settings.STATICFILES_STORAGE
settings.STORAGES = global_settings.STORAGES


@pytest.fixture()
Expand Down

0 comments on commit 2085181

Please sign in to comment.