fix button words

This commit is contained in:
mohamad
2026-05-31 12:45:05 +03:30
parent 7726b0b6ec
commit de2789bd99
14 changed files with 271 additions and 36 deletions
+27 -2
View File
@@ -83,7 +83,19 @@ class MainProductAdmin(admin.ModelAdmin):
list_editable = ("order", "is_active", "show_on_homepage", "homepage_order")
inlines = [MainProductArticleInline, MainProductVersionInline, SubProductInline]
fieldsets = (
(None, {"fields": ("name", "slug", "short_description", "distribution")}),
(
None,
{
"fields": (
"name",
"slug",
"short_description",
"distribution",
"package_resource_button_text",
"package_source_button_text",
)
},
),
("Description", {"fields": ("description_format", "description")}),
("Media", {"fields": ("image",)}),
("Homepage", {"fields": ("show_on_homepage", "homepage_order")}),
@@ -110,7 +122,20 @@ class SubProductAdmin(admin.ModelAdmin):
raw_id_fields = ("main_product",)
inlines = [SubProductArticleInline, SubProductVersionInline]
fieldsets = (
(None, {"fields": ("main_product", "name", "slug", "distribution", "short_description")}),
(
None,
{
"fields": (
"main_product",
"name",
"slug",
"distribution",
"short_description",
"package_resource_button_text",
"package_source_button_text",
)
},
),
("Description", {"fields": ("description_format", "description")}),
("Media", {"fields": ("image", "logo")}),
("Homepage", {"fields": ("show_on_homepage", "homepage_order")}),
@@ -0,0 +1,33 @@
# Generated by Django 5.0.2 on 2026-05-31 09:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('products', '0012_migrate_homepage_visibility_to_mainproduct'),
]
operations = [
migrations.AddField(
model_name='mainproduct',
name='package_resource_button_text',
field=models.CharField(default='PyPI', help_text='Label for the package resource button on package releases.', max_length=100),
),
migrations.AddField(
model_name='mainproduct',
name='package_source_button_text',
field=models.CharField(default='Source', help_text='Label for the source code button on package releases.', max_length=100),
),
migrations.AddField(
model_name='subproduct',
name='package_resource_button_text',
field=models.CharField(default='PyPI', help_text='Label for the package resource button on package releases.', max_length=100),
),
migrations.AddField(
model_name='subproduct',
name='package_source_button_text',
field=models.CharField(default='Source', help_text='Label for the source code button on package releases.', max_length=100),
),
]
+20
View File
@@ -36,6 +36,16 @@ class MainProduct(models.Model):
default=DISTRIBUTION_INSTALLABLE,
help_text="Only affects how releases appear on the public site.",
)
package_resource_button_text = models.CharField(
max_length=100,
default="PyPI",
help_text="Label for the package resource button on package releases.",
)
package_source_button_text = models.CharField(
max_length=100,
default="Source",
help_text="Label for the source code button on package releases.",
)
order = models.PositiveIntegerField(default=0)
is_active = models.BooleanField(default=True)
show_on_homepage = models.BooleanField(default=False, help_text="Display this product in the homepage Products section.")
@@ -99,6 +109,16 @@ class SubProduct(models.Model):
default=DISTRIBUTION_INSTALLABLE,
help_text="Only affects how releases appear on the public site.",
)
package_resource_button_text = models.CharField(
max_length=100,
default="PyPI",
help_text="Label for the package resource button on package releases.",
)
package_source_button_text = models.CharField(
max_length=100,
default="Source",
help_text="Label for the source code button on package releases.",
)
created_at = models.DateTimeField(auto_now_add=True)
updated_at = models.DateTimeField(auto_now=True)
+16 -2
View File
@@ -1,5 +1,17 @@
from .models import DISTRIBUTION_INSTALLABLE, DISTRIBUTION_PACKAGE, INSTALLABLE_PLATFORM_SPECS
DEFAULT_PACKAGE_RESOURCE_BUTTON_TEXT = "PyPI"
DEFAULT_PACKAGE_SOURCE_BUTTON_TEXT = "Source"
def package_button_labels(product):
resource = (getattr(product, "package_resource_button_text", "") or "").strip()
source = (getattr(product, "package_source_button_text", "") or "").strip()
return {
"package_resource_button_text": resource or DEFAULT_PACKAGE_RESOURCE_BUTTON_TEXT,
"package_source_button_text": source or DEFAULT_PACKAGE_SOURCE_BUTTON_TEXT,
}
def featured_version(qs):
ordered = qs.order_by("order", "pk")
@@ -16,7 +28,7 @@ def install_specs_from_versions(version_list):
return tuple(s for s in INSTALLABLE_PLATFORM_SPECS if s[0] in present)
def build_release_context(distribution, active_versions):
def build_release_context(distribution, active_versions, product):
context = {
"distribution_installable": distribution == DISTRIBUTION_INSTALLABLE,
"distribution_package": distribution == DISTRIBUTION_PACKAGE,
@@ -25,6 +37,7 @@ def build_release_context(distribution, active_versions):
"featured_install_cells": [],
"show_older_versions_link": False,
"package_versions": [],
**package_button_labels(product),
}
if distribution == DISTRIBUTION_INSTALLABLE:
@@ -62,7 +75,7 @@ def build_release_context(distribution, active_versions):
return context
def build_archive_context(distribution, active_versions):
def build_archive_context(distribution, active_versions, product):
featured = featured_version(active_versions)
archive = list(
active_versions.exclude(pk=featured.pk).order_by("order", "pk")
@@ -72,6 +85,7 @@ def build_archive_context(distribution, active_versions):
context = {
"featured_version": featured,
"archive_versions": archive,
**package_button_labels(product),
}
if distribution == DISTRIBUTION_INSTALLABLE:
+8 -3
View File
@@ -31,6 +31,7 @@ class MainProductDetailView(DetailView):
release_context = build_release_context(
self.object.distribution,
self.object.versions.filter(is_active=True),
self.object,
)
release_context["versions_archive_url"] = self.object.get_versions_archive_url()
context.update(release_context)
@@ -52,7 +53,9 @@ class MainProductOlderVersionsView(TemplateView):
context["sub_product"] = None
context["product_detail_url"] = main_product.get_absolute_url()
context.update(
build_archive_context(main_product.distribution, active_versions)
build_archive_context(
main_product.distribution, active_versions, main_product
)
)
return context
@@ -85,7 +88,7 @@ class SubProductDetailView(TemplateView):
)
active_versions = sub_product.versions.filter(is_active=True)
release_context = build_release_context(
sub_product.distribution, active_versions
sub_product.distribution, active_versions, sub_product
)
release_context["versions_archive_url"] = sub_product.get_versions_archive_url()
context.update(release_context)
@@ -113,6 +116,8 @@ class SubProductOlderVersionsView(TemplateView):
context["sub_product"] = sub_product
context["product_detail_url"] = sub_product.get_absolute_url()
context.update(
build_archive_context(sub_product.distribution, active_versions)
build_archive_context(
sub_product.distribution, active_versions, sub_product
)
)
return context