Skip to content

Commit

Permalink
Allow to mark a version as not suggested
Browse files Browse the repository at this point in the history
  • Loading branch information
raphaelm committed Feb 25, 2025
1 parent 1ee889d commit 2b3bfc0
Show file tree
Hide file tree
Showing 3 changed files with 32 additions and 2 deletions.
20 changes: 20 additions & 0 deletions src/plum/core/migrations/0029_productversion_allow_suggest.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
# Generated by Django 4.2.19 on 2025-02-25 12:50

from django.db import migrations, models


class Migration(migrations.Migration):

dependencies = [
("core", "0028_alter_user_managers_product_pricing_url"),
]

operations = [
migrations.AddField(
model_name="productversion",
name="allow_suggest",
field=models.BooleanField(
default=True, verbose_name="Allow using as suggested version"
),
),
]
1 change: 1 addition & 0 deletions src/plum/core/models/product.py
Original file line number Diff line number Diff line change
Expand Up @@ -141,6 +141,7 @@ class ProductVersion(models.Model):
name = models.CharField(max_length=190, verbose_name=_('Version name'))
release_date = models.DateField()
release_notes = models.TextField(blank=True)
allow_suggest = models.BooleanField(default=True, verbose_name=_('Allow using as suggested version'))

deliverable_url = models.URLField(blank=True)
deliverable_file = models.FileField(null=True, upload_to=deliverable_filename, blank=True)
Expand Down
13 changes: 11 additions & 2 deletions src/plum/download/views/fdroid.py
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,8 @@ def get(self, request, *args, **kwargs):
for p in self.get_queryset():
if p.active_versions:
app, package = self._app_for_product(p)
if not app:
continue
data['apps'].append(app)
data['packages'][p.android_package_name] = package

Expand All @@ -99,14 +101,21 @@ def get(self, request, *args, **kwargs):
return FileResponse(open(os.path.join(tmpdir, 'index-v1.jar'), 'rb'))

def _app_for_product(self, product):
suggested_versions = [v for v in product.active_versions if v.allow_suggest]
if suggested_versions:
suggested_version = suggested_versions[0]
elif product.active_versions:
suggested_version = product.active_versions[0]
else:
return None, None
app = {
"categories": [
product.category.name
],
"changelog": urljoin(settings.SITE_URL,
reverse("front:product.versions", kwargs={'product': product.slug})),
"suggestedVersionName": product.active_versions[0].android_index_data['versionName'],
"suggestedVersionCode": str(product.active_versions[0].android_index_data['versionCode']),
"suggestedVersionName": suggested_version.android_index_data['versionName'],
"suggestedVersionCode": suggested_version.android_index_data['versionCode'],
"license": "",
"webSite": product.website_url,
"added": int(datetime.datetime.combine(
Expand Down

0 comments on commit 2b3bfc0

Please sign in to comment.