mirror of
https://github.com/postgres/pgweb.git
synced 2025-08-03 15:38:59 +00:00
Make stackbuilder dependencies into a comma separated textfield
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
This commit is contained in:
@ -1,4 +1,9 @@
|
||||
from django.contrib import admin
|
||||
from django import forms
|
||||
from django.forms import ValidationError
|
||||
|
||||
import re
|
||||
|
||||
from util.admin import PgwebAdmin
|
||||
from models import *
|
||||
|
||||
@ -25,11 +30,32 @@ def duplicate_stackbuilderapp(modeladmin, request, queryset):
|
||||
|
||||
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', )
|
||||
filter_horizontal = ('dependencies', )
|
||||
actions = [duplicate_stackbuilderapp, ]
|
||||
|
||||
form = StackBuilderAppAdminForm
|
||||
|
||||
admin.site.register(Mirror, MirrorAdmin)
|
||||
admin.site.register(Category)
|
||||
|
@ -125,7 +125,9 @@ class StackBuilderApp(models.Model):
|
||||
checksum = models.CharField(max_length=32, null=False, blank=False)
|
||||
mirrorpath = models.CharField(max_length=500, null=False, blank=True)
|
||||
alturl = models.URLField(max_length=500, null=False, blank=True)
|
||||
dependencies = models.ManyToManyField("self", blank=True)
|
||||
txtdependencies = models.CharField(max_length=1000, null=False, blank=True,
|
||||
verbose_name='Dependencies',
|
||||
help_text='Comma separated list of text dependencies, no spaces!')
|
||||
versionkey = models.CharField(max_length=500, null=False, blank=False)
|
||||
|
||||
def __unicode__(self):
|
||||
|
@ -272,8 +272,8 @@ def applications_v2_xml(request):
|
||||
x.add_xml_element('mirrorpath', a.mirrorpath)
|
||||
x.add_xml_element('alturl', a.alturl)
|
||||
x.add_xml_element('versionkey', a.versionkey)
|
||||
for dep in a.dependencies.all():
|
||||
x.add_xml_element('dependency', dep.textid)
|
||||
for dep in a.txtdependencies.split(','):
|
||||
x.add_xml_element('dependency', dep)
|
||||
x.endElement('application')
|
||||
x.endElement('applications')
|
||||
x.endDocument()
|
||||
|
Reference in New Issue
Block a user