class CompatOverrideAdmin(admin.ModelAdmin): raw_id_fields = ('addon', ) inlines = [CompatOverrideRangeInline] form = CompatOverrideAdminForm class ReplacementAddonForm(forms.ModelForm): def clean(self): path = None try: path = self.data.get('path') path = ('/' if not path.startswith('/') else '') + path resolve(path) except: raise forms.ValidationError('Path [%s] is not valid' % path) return super(ReplacementAddonForm, self).clean() class ReplacementAddonAdmin(StaffModelAdmin): list_display = ('guid', 'path') form = ReplacementAddonForm admin.site.register(models.DeniedGuid) admin.site.register(models.Addon, AddonAdmin) admin.site.register(models.FrozenAddon, FrozenAddonAdmin) admin.site.register(models.CompatOverride, CompatOverrideAdmin) admin.site.register(models.ReplacementAddon, ReplacementAddonAdmin) staff_admin_site.register(models.ReplacementAddon, ReplacementAddonAdmin)
raise validation_error except Exception: raise forms.ValidationError('Path [%s] is not valid' % path) return super(ReplacementAddonForm, self).clean() class ReplacementAddonAdmin(StaffModelAdmin): list_display = ('guid', 'path', 'guid_slug', '_url') form = ReplacementAddonForm def _url(self, obj): guid_param = urlencode({'guid': obj.guid}) return format_html( '<a href="{}">Test</a>', reverse('addons.find_replacement') + '?%s' % guid_param) def guid_slug(self, obj): try: slug = models.Addon.objects.get(guid=obj.guid).slug except models.Addon.DoesNotExist: slug = ugettext(u'- Add-on not on AMO -') return slug admin.site.register(models.DeniedGuid) admin.site.register(models.Addon, AddonAdmin) admin.site.register(models.FrozenAddon, FrozenAddonAdmin) admin.site.register(models.CompatOverride, CompatOverrideAdmin) admin.site.register(models.ReplacementAddon, ReplacementAddonAdmin) staff_admin_site.register(models.ReplacementAddon, ReplacementAddonAdmin)