mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-12 23:05:12 +00:00

The "true dependencies" usign db relationships were too strict for reality - multiple entries can have the same textid, and that's what we need to depend on. Resolving it for platform is handled in the StackBuilder client. This update requires the following SQL to be run in the database: DROP TABLE downloads_stackbuilderapp_dependencies; ALTER TABLE downloads_stackbuilderapp ADD COLUMN txtdependencies varchar(1000) NOT NULL DEFAULT ''; ALTER TABLE downloads_stackbuilderapp ALTER COLUMN txtdependencies DROP DEFAULT; Closes #167
65 lines
2.1 KiB
Python
65 lines
2.1 KiB
Python
from django.contrib import admin
|
|
from django import forms
|
|
from django.forms import ValidationError
|
|
|
|
import re
|
|
|
|
from util.admin import PgwebAdmin
|
|
from models import *
|
|
|
|
class MirrorAdmin(admin.ModelAdmin):
|
|
list_display = ('__unicode__', 'country_name', 'country_code', 'mirror_index', 'mirror_last_rsync', 'host_sponsor', )
|
|
list_filter = ('country_name', 'mirror_active', )
|
|
search_fields = ('country_name', 'host_sponsor', 'host_notes', )
|
|
ordering = ('country_code', )
|
|
|
|
class ProductAdmin(PgwebAdmin):
|
|
list_display = ('name', 'org', 'approved', 'lastconfirmed',)
|
|
list_filter = ('approved',)
|
|
search_fields = ('name', 'description', )
|
|
ordering = ('name', )
|
|
|
|
def duplicate_stackbuilderapp(modeladmin, request, queryset):
|
|
# Duplicate each individual selected object, but turn off
|
|
# the active flag if it's on.
|
|
for o in queryset:
|
|
o.id = None # Triggers creation of a new object
|
|
o.active = False
|
|
o.textid = o.textid + "_new"
|
|
o.save()
|
|
|
|
duplicate_stackbuilderapp.short_description = "Duplicate application"
|
|
|
|
class StackBuilderAppAdminForm(forms.ModelForm):
|
|
class Meta:
|
|
model = StackBuilderApp
|
|
|
|
def clean_textid(self):
|
|
if not re.match('^[a-z0-9_]*$', self.cleaned_data['textid']):
|
|
raise ValidationError('Only lowerchase characters, numbers and underscore allowed!')
|
|
return self.cleaned_data['textid']
|
|
|
|
def clean_txtdependencies(self):
|
|
if len(self.cleaned_data['txtdependencies']) == 0:
|
|
return ''
|
|
|
|
deplist = self.cleaned_data['txtdependencies'].split(',')
|
|
if len(deplist) != len(set(deplist)):
|
|
raise ValidationError('Duplicate dependencies not allowed!')
|
|
|
|
for d in deplist:
|
|
if not StackBuilderApp.objects.filter(textid=d).exists():
|
|
raise ValidationError("Dependency '%s' does not exist!" % d)
|
|
return self.cleaned_data['txtdependencies']
|
|
|
|
class StackBuilderAppAdmin(admin.ModelAdmin):
|
|
list_display = ('textid', 'active', 'name', 'platform', 'version', )
|
|
actions = [duplicate_stackbuilderapp, ]
|
|
form = StackBuilderAppAdminForm
|
|
|
|
admin.site.register(Mirror, MirrorAdmin)
|
|
admin.site.register(Category)
|
|
admin.site.register(LicenceType)
|
|
admin.site.register(Product, ProductAdmin)
|
|
admin.site.register(StackBuilderApp, StackBuilderAppAdmin)
|