-
Notifications
You must be signed in to change notification settings - Fork 27
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #1013 from thunderstore-io/installers-field
Add 'installers' field support to package manifest
- Loading branch information
Showing
16 changed files
with
491 additions
and
37 deletions.
There are no files selected for viewing
This file contains 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
This file contains 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
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,21 @@ | ||
from django.contrib import admin | ||
from django.http import HttpRequest | ||
|
||
from thunderstore.repository.models import PackageInstaller | ||
|
||
|
||
@admin.register(PackageInstaller) | ||
class PackageInstallerAdmin(admin.ModelAdmin): | ||
readonly_fields = ("identifier",) | ||
list_display_links = ("pk", "identifier") | ||
list_display = ("pk", "identifier") | ||
search_fields = ("pk", "identifier") | ||
|
||
def has_add_permission(self, request: HttpRequest, obj=None) -> bool: | ||
return False | ||
|
||
def has_change_permission(self, request: HttpRequest, obj=None) -> bool: | ||
return False | ||
|
||
def has_delete_permission(self, request: HttpRequest, obj=None) -> bool: | ||
return False |
39 changes: 39 additions & 0 deletions
39
django/thunderstore/repository/admin/tests/test_package_installer.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
import pytest | ||
from django.conf import settings | ||
from django.test import Client | ||
|
||
from thunderstore.repository.models import PackageInstaller | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_admin_package_installer_search(admin_client: Client) -> None: | ||
resp = admin_client.get( | ||
path="/djangoadmin/repository/packageinstaller/?q=asd", | ||
HTTP_HOST=settings.PRIMARY_HOST, | ||
) | ||
assert resp.status_code == 200 | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_admin_package_installer_list( | ||
package_installer: PackageInstaller, admin_client: Client | ||
) -> None: | ||
resp = admin_client.get( | ||
path="/djangoadmin/repository/packageinstaller/", | ||
HTTP_HOST=settings.PRIMARY_HOST, | ||
) | ||
assert resp.status_code == 200 | ||
assert package_installer.identifier in resp.content.decode() | ||
|
||
|
||
@pytest.mark.django_db | ||
def test_admin_package_installer_detail( | ||
package_installer: PackageInstaller, | ||
admin_client: Client, | ||
) -> None: | ||
path = f"/djangoadmin/repository/packageinstaller/{package_installer.pk}/change/" | ||
resp = admin_client.get( | ||
path=path, | ||
HTTP_HOST=settings.PRIMARY_HOST, | ||
) | ||
assert resp.status_code == 200 |
This file contains 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
104 changes: 104 additions & 0 deletions
104
django/thunderstore/repository/migrations/0049_add_package_installer.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,104 @@ | ||
# Generated by Django 3.1.7 on 2024-01-27 04:37 | ||
|
||
import django.db.models.deletion | ||
from django.db import migrations, models | ||
|
||
|
||
class Migration(migrations.Migration): | ||
|
||
dependencies = [ | ||
("repository", "0048_populate_visibility"), | ||
] | ||
|
||
operations = [ | ||
migrations.CreateModel( | ||
name="PackageInstaller", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
("identifier", models.SlugField(editable=False, unique=True)), | ||
], | ||
), | ||
migrations.CreateModel( | ||
name="PackageInstallerDeclaration", | ||
fields=[ | ||
( | ||
"id", | ||
models.AutoField( | ||
auto_created=True, | ||
primary_key=True, | ||
serialize=False, | ||
verbose_name="ID", | ||
), | ||
), | ||
], | ||
), | ||
migrations.RemoveConstraint( | ||
model_name="packageversion", | ||
name="valid_package_format", | ||
), | ||
migrations.AlterField( | ||
model_name="packageversion", | ||
name="format_spec", | ||
field=models.TextField( | ||
blank=True, | ||
choices=[ | ||
("thunderstore.io:v0.0", "V0 0"), | ||
("thunderstore.io:v0.1", "V0 1"), | ||
("thunderstore.io:v0.2", "V0 2"), | ||
("thunderstore.io:v0.3", "V0 3"), | ||
], | ||
help_text="Used to track the latest package format spec this package is compatible with", | ||
null=True, | ||
), | ||
), | ||
migrations.AddConstraint( | ||
model_name="packageversion", | ||
constraint=models.CheckConstraint( | ||
check=models.Q( | ||
("format_spec", None), | ||
("format_spec", "thunderstore.io:v0.0"), | ||
("format_spec", "thunderstore.io:v0.1"), | ||
("format_spec", "thunderstore.io:v0.2"), | ||
("format_spec", "thunderstore.io:v0.3"), | ||
_connector="OR", | ||
), | ||
name="valid_package_format", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="packageinstallerdeclaration", | ||
name="package_installer", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.PROTECT, | ||
related_name="installer_declarations", | ||
to="repository.packageinstaller", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="packageinstallerdeclaration", | ||
name="package_version", | ||
field=models.ForeignKey( | ||
on_delete=django.db.models.deletion.CASCADE, | ||
related_name="installer_declarations", | ||
to="repository.packageversion", | ||
), | ||
), | ||
migrations.AddField( | ||
model_name="packageversion", | ||
name="installers", | ||
field=models.ManyToManyField( | ||
blank=True, | ||
related_name="package_versions", | ||
through="repository.PackageInstallerDeclaration", | ||
to="repository.PackageInstaller", | ||
), | ||
), | ||
] |
This file contains 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
27 changes: 27 additions & 0 deletions
27
django/thunderstore/repository/models/package_installer.py
This file contains 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
from django.db import models | ||
|
||
|
||
class PackageInstaller(models.Model): | ||
identifier = models.SlugField(unique=True, db_index=True, editable=False) | ||
|
||
def __str__(self): | ||
return self.identifier | ||
|
||
|
||
class PackageInstallerDeclaration(models.Model): | ||
""" | ||
Used for the m2m relation between PackageVersion and PackageInstaller. | ||
A custom model is used in order to support potential extra data in the | ||
installer declarations in the future. | ||
""" | ||
|
||
package_installer = models.ForeignKey( | ||
"repository.PackageInstaller", | ||
on_delete=models.PROTECT, | ||
related_name="installer_declarations", | ||
) | ||
package_version = models.ForeignKey( | ||
"repository.PackageVersion", | ||
on_delete=models.CASCADE, | ||
related_name="installer_declarations", | ||
) |
This file contains 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
This file contains 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
Oops, something went wrong.