# Path: ref/admin.py
# class MageParamAdmin(ModelAdmin):
# class EnvironmentAdmin(ModelAdmin):
# class EnvironmentTypeAdmin(ModelAdmin):
# class LogicalComponentAdmin(ModelAdmin):
# class ApplicationAdmin(ModelAdmin):
# class ProjectAdmin(ModelAdmin):
# class LinkAdmin(ModelAdmin):
# class CICAdmin(ModelAdmin):
# class ImplementationRelationTypeAdmin(ModelAdmin):
# class ImplementationFieldDescriptionInline(TabularInline):
# class ImplementationRelationDescriptionInline(TabularInline):
# class ImplementationComputedFieldDescriptionInline(TabularInline):
# class ImplementationDescriptionAdmin(ModelAdmin):
# class ConventionCounterAdmin(ModelAdmin):
# class ExtendedParameterInline(TabularInline):
# class ComponentInstanceFieldAdmin(TabularInline):
# class ComponentInstanceRelationAdmin(TabularInline):
# class ComponentInstanceAdmin(ModelAdmin):
#     def has_delete_permission(self, request, obj=None):
#     def get_actions(self, request):
# 
# Path: scm/models.py
# class BackupRestoreMethod(models.Model):
#     """
#         BMRs are needed because there may be multiple InstallationMethods available for the same CIC. Therefore, 
#         we need a mean to know which InstallationMethod to use to restore a backup.
#         There cannot be more than one BMR per CIC (we are talking default restoration method - only one default!)
#     """
#     method = models.ForeignKey(InstallationMethod, on_delete=models.CASCADE)
#     target = models.ForeignKey(ComponentImplementationClass, related_name='restore_methods', verbose_name='cible', on_delete=models.CASCADE)
# 
#     class Meta:
#         verbose_name = u'méthode de restauration par défaut'
#         verbose_name_plural = 'méthodes de restauration par défaut'
# 
# class InstallationMethod(models.Model):
#     name = models.CharField(max_length=254, verbose_name=u'nom')
#     halts_service = models.BooleanField(default=True, verbose_name=u'arrêt de service')
#     method_compatible_with = models.ManyToManyField(ComponentImplementationClass, related_name='installation_methods', verbose_name=u'permet d\'installer')
#     available = models.BooleanField(default=True, verbose_name=u'disponible')
#     restoration_only = models.BooleanField(default=False, verbose_name=u'opération purement de restauration')
#     checkers = models.ManyToManyField('PackageChecker', related_name='used_in', blank=True)
# 
#     def __str__(self):
#         a = ""
#         if not self.available:
#             a = "OBSOLETE - "
#         return u'%s%s' % (a, self.name)  #, ",".join([ i.name for i in self.method_compatible_with.all()]))
# 
#     def check_package(self, package_file, logical_component):
#         for checker in self.checkers.all():
#             checker.check_package(package_file, logical_component, self)
# 
#     class Meta:
#         verbose_name = u'méthode d\'installation'
#         verbose_name_plural = u'méthodes d\'installation'
# 
# class BackupSet(InstallableSet):
#     from_envt = models.ForeignKey(Environment, blank=True, null=True, on_delete=models.CASCADE)
# 
# class PackageChecker(models.Model):
#     module = models.CharField(max_length=200, verbose_name='Python module containing the checker class')
#     name = models.CharField(max_length=200, verbose_name='Python checker class name')
#     description = models.CharField(max_length=200, verbose_name='description')
# 
#     def check_package(self, package_file, logical_component, installation_method):
#         checker_impl = getattr(__import__(self.module, fromlist=[self.name]), self.name)
#         checker_impl.check(checker_impl(), package_file, logical_component, installation_method)
# 
#     def __str__(self):
#         return self.description


from ref import admin
from scm.models import BackupRestoreMethod, InstallationMethod, BackupSet, \
    PackageChecker

    def has_delete_permission(self, request, obj=None):
        return False
    def get_actions(self, request):
        actions = super(InstallationMethodAdmin, self).get_actions(request)
        if 'delete_selected' in actions:
            del actions['delete_selected']
        return actions

admin.site.register(InstallationMethod, InstallationMethodAdmin)


class BackupSetAdmin(admin.ModelAdmin):
    list_display = ('name', 'is_available', 'from_envt')
    list_filter = ('from_envt', 'set_date', 'removed')

    def has_delete_permission(self, request, obj=None):
        return False
    def get_actions(self, request):
        actions = super(BackupSetAdmin, self).get_actions(request)
        if 'delete_selected' in actions:
            del actions['delete_selected']
        return actions

#admin.site.register(BackupSet, BackupSetAdmin)

class PackageCheckerAdmin(admin.ModelAdmin):
    list_display = ('description', 'module', 'name',)
    readonly_fields = ('module', 'name')


# Path: ref/admin.py
# class MageParamAdmin(ModelAdmin):
# class EnvironmentAdmin(ModelAdmin):
# class EnvironmentTypeAdmin(ModelAdmin):
# class LogicalComponentAdmin(ModelAdmin):
# class ApplicationAdmin(ModelAdmin):
# class ProjectAdmin(ModelAdmin):
# class LinkAdmin(ModelAdmin):
# class CICAdmin(ModelAdmin):
# class ImplementationRelationTypeAdmin(ModelAdmin):
# class ImplementationFieldDescriptionInline(TabularInline):
# class ImplementationRelationDescriptionInline(TabularInline):
# class ImplementationComputedFieldDescriptionInline(TabularInline):
# class ImplementationDescriptionAdmin(ModelAdmin):
# class ConventionCounterAdmin(ModelAdmin):
# class ExtendedParameterInline(TabularInline):
# class ComponentInstanceFieldAdmin(TabularInline):
# class ComponentInstanceRelationAdmin(TabularInline):
# class ComponentInstanceAdmin(ModelAdmin):
#     def has_delete_permission(self, request, obj=None):
#     def get_actions(self, request):
# 
# Path: scm/models.py
# class BackupRestoreMethod(models.Model):
#     """
#         BMRs are needed because there may be multiple InstallationMethods available for the same CIC. Therefore, 
#         we need a mean to know which InstallationMethod to use to restore a backup.
#         There cannot be more than one BMR per CIC (we are talking default restoration method - only one default!)
#     """
#     method = models.ForeignKey(InstallationMethod, on_delete=models.CASCADE)
#     target = models.ForeignKey(ComponentImplementationClass, related_name='restore_methods', verbose_name='cible', on_delete=models.CASCADE)
# 
#     class Meta:
#         verbose_name = u'méthode de restauration par défaut'
#         verbose_name_plural = 'méthodes de restauration par défaut'
# 
# class InstallationMethod(models.Model):
#     name = models.CharField(max_length=254, verbose_name=u'nom')
#     halts_service = models.BooleanField(default=True, verbose_name=u'arrêt de service')
#     method_compatible_with = models.ManyToManyField(ComponentImplementationClass, related_name='installation_methods', verbose_name=u'permet d\'installer')
#     available = models.BooleanField(default=True, verbose_name=u'disponible')
#     restoration_only = models.BooleanField(default=False, verbose_name=u'opération purement de restauration')
#     checkers = models.ManyToManyField('PackageChecker', related_name='used_in', blank=True)
# 
#     def __str__(self):
#         a = ""
#         if not self.available:
#             a = "OBSOLETE - "
#         return u'%s%s' % (a, self.name)  #, ",".join([ i.name for i in self.method_compatible_with.all()]))
# 
#     def check_package(self, package_file, logical_component):
#         for checker in self.checkers.all():
#             checker.check_package(package_file, logical_component, self)
# 
#     class Meta:
#         verbose_name = u'méthode d\'installation'
#         verbose_name_plural = u'méthodes d\'installation'
# 
# class BackupSet(InstallableSet):
#     from_envt = models.ForeignKey(Environment, blank=True, null=True, on_delete=models.CASCADE)
# 
# class PackageChecker(models.Model):
#     module = models.CharField(max_length=200, verbose_name='Python module containing the checker class')
#     name = models.CharField(max_length=200, verbose_name='Python checker class name')
#     description = models.CharField(max_length=200, verbose_name='description')
# 
#     def check_package(self, package_file, logical_component, installation_method):
#         checker_impl = getattr(__import__(self.module, fromlist=[self.name]), self.name)
#         checker_impl.check(checker_impl(), package_file, logical_component, installation_method)
# 
#     def __str__(self):
#         return self.description


# Path: scm/admin.py
from ref import admin
from scm.models import BackupRestoreMethod, InstallationMethod, BackupSet, \
    PackageChecker


    def has_delete_permission(self, request, obj=None):
        return False
    def get_actions(self, request):
        actions = super(InstallationMethodAdmin, self).get_actions(request)
        if 'delete_selected' in actions:
            del actions['delete_selected']
        return actions

admin.site.register(InstallationMethod, InstallationMethodAdmin)


class BackupSetAdmin(admin.ModelAdmin):
    list_display = ('name', 'is_available', 'from_envt')
    list_filter = ('from_envt', 'set_date', 'removed')

    def has_delete_permission(self, request, obj=None):
        return False
    def get_actions(self, request):
        actions = super(BackupSetAdmin, self).get_actions(request)
        if 'delete_selected' in actions:
            del actions['delete_selected']
        return actions

#admin.site.register(BackupSet, BackupSetAdmin)

class PackageCheckerAdmin(admin.ModelAdmin):
    list_display = ('description', 'module', 'name',)
    readonly_fields = ('module', 'name')


admin.site.register(PackageChecker, PackageCheckerAdmin)