Skip to content

Commit

Permalink
Add necessary migration for geoip app and some minor build tweaks (#171)
Browse files Browse the repository at this point in the history
  • Loading branch information
jkachel authored Nov 5, 2024
1 parent 47b6ccf commit fc1fc6f
Show file tree
Hide file tree
Showing 47 changed files with 493 additions and 55 deletions.
10 changes: 9 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,8 @@ The Compose environment includes a container for general use called `shell` and
- Build the containers: `docker compose build`
- Get a shell in the `shell` container: `docker compose run --rm -ti shell bash`

The database server is exposed on port 55432 locally - you can override this by setting `POSTGRES_PORT` in your environment.

#### Using the `release` container

The `release` container is special and is set up to run `build` commands, including generating releases. It's special because it _does not_ mount your local copy of the codebase (mainly because of file permission issues). So, it requires a bit more care before using.
Expand Down Expand Up @@ -71,7 +73,13 @@ To add a new one, it's easiest to copy one of the existing apps. There's one cal

You can now add your code and tests.

If you need to run Django commands,
### Running Django commands

You can run Django commands by using the `testapp` that's included:

`uv run tests/manage.py`

The management commands for each ol-django app should be available. If you need to run things that require a database, run it in the Docker Compose setup as it contains a PostgreSQL database.

### Running tests

Expand Down
2 changes: 1 addition & 1 deletion docker-compose.yml
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@ services:
POSTGRES_DB: ol_django
POSTGRES_PASSWORD: postgres
ports:
- "5432:5432"
- "${POSTGRES_PORT:-55432}:5432"

shell:
build:
Expand Down
2 changes: 2 additions & 0 deletions pyproject.toml
Original file line number Diff line number Diff line change
Expand Up @@ -203,6 +203,7 @@ lint.ignore = [
"RET506",
"RET507",
"RET508",
"RUF012",
"UP007"
]
lint.typing-modules = ["colour.hints"]
Expand All @@ -216,3 +217,4 @@ inline-quotes = "double"
[tool.ruff.lint.per-file-ignores]
"tests/**" = ["S101"]
"test_*.py" = ["S101"]
"**/migrations/**" = ["ARG001", "D100", "D101", "E501"]
40 changes: 40 additions & 0 deletions src/common/changelog.d/20241105_143822_jkachel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->
### Changed

- Removes unnecessary noqa's.

<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
<!--
### Fixed
- A bullet item for the Fixed category.
-->
<!--
### Security
- A bullet item for the Security category.
-->
2 changes: 1 addition & 1 deletion src/common/mitol/common/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
class BaseApp(AppConfig):
"""Base application class"""

required_settings: List[str] = [] # noqa: FA100, RUF012
required_settings: List[str] = [] # noqa: FA100

def validate_required_settings(self):
"""
Expand Down
2 changes: 1 addition & 1 deletion src/common/mitol/common/utils/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@

def base_register_subclasses_factory(*mixin_classes):
class BaseRegisterSubclasses(abc.ABC, *mixin_classes):
_SUBCLASSES = {} # noqa: RUF012
_SUBCLASSES = {}

def __init_subclass__(cls, *, subclass_type, **kwargs):
super().__init_subclass__()
Expand Down
40 changes: 40 additions & 0 deletions src/digitalcredentials/changelog.d/20241105_143822_jkachel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->
### Changed

- Removes unnecessary noqa's.

<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
<!--
### Fixed
- A bullet item for the Fixed category.
-->
<!--
### Security
- A bullet item for the Security category.
-->
2 changes: 1 addition & 1 deletion src/digitalcredentials/mitol/digitalcredentials/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class DigitalCredentialsApp(BaseApp):
label = "digitalcredentials"
verbose_name = "Digital Credentials"

required_settings = [ # noqa: RUF012
required_settings = [
"MITOL_DIGITAL_CREDENTIALS_VERIFY_SERVICE_BASE_URL",
"MITOL_DIGITAL_CREDENTIALS_BUILD_CREDENTIAL_FUNC",
"MITOL_DIGITAL_CREDENTIALS_HMAC_SECRET",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,12 +10,12 @@
class Migration(migrations.Migration):
initial = True

dependencies = [ # noqa: RUF012
dependencies = [
migrations.swappable_dependency(settings.AUTH_USER_MODEL),
("contenttypes", "0002_remove_content_type_name"),
]

operations = [ # noqa: RUF012
operations = [
migrations.CreateModel(
name="LearnerDID",
fields=[
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,11 @@


class Migration(migrations.Migration):
dependencies = [ # noqa: RUF012
dependencies = [
("digitalcredentials", "0001_add_digital_credentials_models"),
]

operations = [ # noqa: RUF012
operations = [
migrations.RenameField(
model_name="digitalcredential",
old_name="courseware_content_type",
Expand Down
6 changes: 3 additions & 3 deletions src/digitalcredentials/mitol/digitalcredentials/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,9 +15,9 @@
class DigitalCredentialIssueView(GenericAPIView):
"""Digital credential API views"""

authentication_classes = [OAuth2Authentication] # noqa: RUF012
permission_classes = [IsAuthenticated, TokenHasScope] # noqa: RUF012
required_scopes = ["digitalcredentials"] # noqa: RUF012
authentication_classes = [OAuth2Authentication]
permission_classes = [IsAuthenticated, TokenHasScope]
required_scopes = ["digitalcredentials"]
serializer_class = DigitalCredentialIssueSerializer
lookup_field = "uuid"

Expand Down
41 changes: 41 additions & 0 deletions src/geoip/changelog.d/20241104_210241_somebody.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->
<!--
### Changed
- A bullet item for the Changed category.
-->
<!--
### Deprecated
- A bullet item for the Deprecated category.
-->

### Fixed

- Adding migrations to rename the maxmind indexes to geoip.

<!--
### Security
- A bullet item for the Security category.
-->
40 changes: 40 additions & 0 deletions src/geoip/changelog.d/20241105_143822_jkachel.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Removed
- A bullet item for the Removed category.
-->
<!--
### Added
- A bullet item for the Added category.
-->
### Changed

- Removes unnecessary noqa's.

<!--
### Deprecated
- A bullet item for the Deprecated category.
-->
<!--
### Fixed
- A bullet item for the Fixed category.
-->
<!--
### Security
- A bullet item for the Security category.
-->
6 changes: 3 additions & 3 deletions src/geoip/mitol/geoip/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,9 +8,9 @@
class NetBlockAdmin(admin.ModelAdmin):
"""Admin for netblock"""

list_display = ["network", "ip_start", "ip_end", "is_ipv6"] # noqa: RUF012
list_filter = ["is_ipv6"] # noqa: RUF012
search_fields = ["ip_start", "ip_end", "network"] # noqa: RUF012
list_display = ["network", "ip_start", "ip_end", "is_ipv6"]
list_filter = ["is_ipv6"]
search_fields = ["ip_start", "ip_end", "network"]


admin.site.register(models.Geoname)
Expand Down
2 changes: 1 addition & 1 deletion src/geoip/mitol/geoip/apps.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ class GeoIPApp(BaseApp):
label = "geoip"
verbose_name = "GeoIP"

required_settings = [] # noqa: RUF012
required_settings = []

# necessary because this is a namespaced app
path = os.path.dirname(os.path.abspath(__file__)) # noqa: PTH100, PTH120
4 changes: 2 additions & 2 deletions src/geoip/mitol/geoip/migrations/0001_add_geoip_tables.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,9 +6,9 @@
class Migration(migrations.Migration):
initial = True

dependencies = [] # noqa: RUF012
dependencies = []

operations = [ # noqa: RUF012
operations = [
migrations.CreateModel(
name="Geoname",
fields=[
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
# Generated by Django 4.2.16 on 2024-11-04 20:47

from django.db import migrations


class Migration(migrations.Migration):
dependencies = [
("geoip", "0001_add_geoip_tables"),
]

operations = [
migrations.RenameIndex(
model_name="netblock",
new_name="geoip_netbl_decimal_d4f6be_idx",
old_name="maxmind_net_decimal_dfdb1a_idx",
),
migrations.RenameIndex(
model_name="netblock",
new_name="geoip_netbl_decimal_29d863_idx",
old_name="maxmind_net_decimal_6166c4_idx",
),
migrations.RenameIndex(
model_name="netblock",
new_name="geoip_netbl_decimal_724563_idx",
old_name="maxmind_net_decimal_ab7249_idx",
),
]
6 changes: 3 additions & 3 deletions src/geoip/mitol/geoip/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ class Geoname(models.Model):
is_in_european_union = models.BooleanField(blank=True, null=True, default=False)

class Meta:
constraints = [ # noqa: RUF012
constraints = [
models.UniqueConstraint(
fields=["geoname_id", "locale_code"], name="unique_geoname_id_locale"
)
Expand Down Expand Up @@ -89,15 +89,15 @@ class NetBlock(models.Model):
accuracy_radius = models.IntegerField(blank=True, null=True)

class Meta:
constraints = [ # noqa: RUF012
constraints = [
models.CheckConstraint(
check=models.Q(geoname_id__isnull=False)
| models.Q(registered_country_geoname_id__isnull=False)
| models.Q(represented_country_geoname_id__isnull=False),
name="at_least_one_geoname_id",
)
]
indexes = [ # noqa: RUF012
indexes = [
models.Index(fields=["decimal_ip_start"]),
models.Index(fields=["decimal_ip_end"]),
models.Index(fields=["decimal_ip_start", "decimal_ip_end"]),
Expand Down
Loading

0 comments on commit fc1fc6f

Please sign in to comment.