versioning and wp plugin updates
This commit is contained in:
@@ -178,17 +178,12 @@ class PluginVersionAdmin(ModelAdmin):
|
||||
def release_versions(self, request, queryset):
|
||||
from django.utils import timezone
|
||||
count = 0
|
||||
for version in queryset.filter(status__in=['draft', 'testing', 'staged']):
|
||||
for version in queryset.filter(status='draft'):
|
||||
version.status = 'released'
|
||||
version.save() # Triggers signal to build ZIP
|
||||
count += 1
|
||||
self.message_user(request, f"Released {count} version(s). ZIP files are being built automatically.")
|
||||
|
||||
@admin.action(description="📢 Mark as update ready (notify WordPress sites)")
|
||||
def mark_as_update_ready(self, request, queryset):
|
||||
count = queryset.filter(status='released').update(status='update_ready')
|
||||
self.message_user(request, f"Marked {count} version(s) as update ready. WordPress sites will be notified.")
|
||||
|
||||
@admin.action(description="🗑️ Mark as deprecated")
|
||||
def mark_as_deprecated(self, request, queryset):
|
||||
count = queryset.update(status='deprecated')
|
||||
|
||||
@@ -0,0 +1,18 @@
|
||||
# Generated by Django 5.2.10 on 2026-01-09 23:50
|
||||
|
||||
from django.db import migrations, models
|
||||
|
||||
|
||||
class Migration(migrations.Migration):
|
||||
|
||||
dependencies = [
|
||||
('plugins', '0002_allow_blank_autogenerated_fields'),
|
||||
]
|
||||
|
||||
operations = [
|
||||
migrations.AlterField(
|
||||
model_name='pluginversion',
|
||||
name='status',
|
||||
field=models.CharField(choices=[('draft', 'Draft'), ('released', 'Released'), ('deprecated', 'Deprecated')], db_index=True, default='draft', help_text='Release status of this version', max_length=20),
|
||||
),
|
||||
]
|
||||
@@ -64,7 +64,7 @@ class Plugin(models.Model):
|
||||
def get_latest_version(self):
|
||||
"""Get the latest released version of this plugin."""
|
||||
return self.versions.filter(
|
||||
status__in=['released', 'update_ready']
|
||||
status='released'
|
||||
).first()
|
||||
|
||||
def get_download_count(self):
|
||||
@@ -80,11 +80,8 @@ class PluginVersion(models.Model):
|
||||
"""
|
||||
|
||||
STATUS_CHOICES = [
|
||||
('draft', 'Draft'), # In development
|
||||
('testing', 'Testing'), # Internal testing
|
||||
('staged', 'Staged'), # Ready, not yet pushed
|
||||
('released', 'Released'), # Available for download
|
||||
('update_ready', 'Update Ready'), # Push to installed sites
|
||||
('draft', 'Draft'), # In development - NOT available for download
|
||||
('released', 'Released'), # Available for download and updates
|
||||
('deprecated', 'Deprecated'), # Old version, not recommended
|
||||
]
|
||||
|
||||
|
||||
@@ -17,7 +17,7 @@ logger = logging.getLogger(__name__)
|
||||
@receiver(pre_save, sender=PluginVersion)
|
||||
def auto_build_plugin_on_release(sender, instance, **kwargs):
|
||||
"""
|
||||
Automatically build ZIP package when a version is marked as released or update_ready.
|
||||
Automatically build ZIP package when a version is marked as released.
|
||||
|
||||
This ensures:
|
||||
1. ZIP file is always up-to-date with source code
|
||||
@@ -25,36 +25,32 @@ def auto_build_plugin_on_release(sender, instance, **kwargs):
|
||||
3. No manual intervention needed for releases
|
||||
|
||||
Triggers on:
|
||||
- New version created with status 'released' or 'update_ready'
|
||||
- Existing version status changed to 'released' or 'update_ready'
|
||||
"""
|
||||
release_statuses = ['released', 'update_ready']
|
||||
- New version created with status 'released'
|
||||
- Existing version status changed to 'released'
|
||||
|
||||
# Check if this version should have a ZIP built
|
||||
Note: Only 'released' status makes the version available for download.
|
||||
"""
|
||||
# Only build ZIP when status is 'released'
|
||||
should_build = False
|
||||
|
||||
if not instance.pk:
|
||||
# New instance - build if status is a release status
|
||||
if instance.status in release_statuses:
|
||||
# New instance - build if status is released
|
||||
if instance.status == 'released':
|
||||
should_build = True
|
||||
logger.info(f"New plugin version {instance.plugin.slug} v{instance.version} created with status '{instance.status}' - building ZIP")
|
||||
logger.info(f"New plugin version {instance.plugin.slug} v{instance.version} created with status 'released' - building ZIP")
|
||||
else:
|
||||
# Existing instance - check if status changed to a release status
|
||||
# Existing instance - check if status changed to released
|
||||
try:
|
||||
old_instance = PluginVersion.objects.get(pk=instance.pk)
|
||||
old_status = old_instance.status
|
||||
new_status = instance.status
|
||||
|
||||
# Build if moving to a release status from a non-release status
|
||||
if new_status in release_statuses and old_status not in release_statuses:
|
||||
# Build if moving to released from any other status
|
||||
if new_status == 'released' and old_status != 'released':
|
||||
should_build = True
|
||||
logger.info(f"Building plugin ZIP for {instance.plugin.slug} v{instance.version} (status: {old_status} -> {new_status})")
|
||||
elif old_status == new_status and new_status in release_statuses:
|
||||
# No status change, but already released - no rebuild
|
||||
return
|
||||
elif old_status in release_statuses and new_status in release_statuses:
|
||||
# Moving between release statuses - no rebuild
|
||||
logger.info(f"Plugin {instance.plugin.slug} v{instance.version}: Status changing from {old_status} to {new_status}, no rebuild needed")
|
||||
logger.info(f"Building plugin ZIP for {instance.plugin.slug} v{instance.version} (status: {old_status} -> released)")
|
||||
elif old_status == 'released' and new_status == 'released':
|
||||
# No status change, already released - no rebuild
|
||||
return
|
||||
except PluginVersion.DoesNotExist:
|
||||
return
|
||||
|
||||
@@ -190,6 +190,9 @@ def create_plugin_zip(
|
||||
'**/tests',
|
||||
'**/tester',
|
||||
'**/.DS_Store',
|
||||
'**/*.bak',
|
||||
'**/*.tmp',
|
||||
'**/*.log',
|
||||
]
|
||||
|
||||
for pattern in patterns_to_remove:
|
||||
|
||||
Reference in New Issue
Block a user