Source code for beat.web.backend.admin

#!/usr/bin/env python
# vim: set fileencoding=utf-8 :

###############################################################################
#                                                                             #
# Copyright (c) 2016 Idiap Research Institute, http://www.idiap.ch/           #
# Contact: beat.support@idiap.ch                                              #
#                                                                             #
# This file is part of the beat.web module of the BEAT platform.              #
#                                                                             #
# Commercial License Usage                                                    #
# Licensees holding valid commercial BEAT licenses may use this file in       #
# accordance with the terms contained in a written agreement between you      #
# and Idiap. For further information contact tto@idiap.ch                     #
#                                                                             #
# Alternatively, this file may be used under the terms of the GNU Affero      #
# Public License version 3 as published by the Free Software and appearing    #
# in the file LICENSE.AGPL included in the packaging of this file.            #
# The BEAT platform is distributed in the hope that it will be useful, but    #
# WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY  #
# or FITNESS FOR A PARTICULAR PURPOSE.                                        #
#                                                                             #
# You should have received a copy of the GNU Affero Public License along      #
# with the BEAT platform. If not, see http://www.gnu.org/licenses/.           #
#                                                                             #
###############################################################################

from django.contrib import admin
from django import forms

from .models import Environment as EnvironmentModel
from .models import EnvironmentLanguage as EnvironmentLanguageModel
from .models import Worker as WorkerModel
from .models import Queue as QueueModel
from .models import Slot as SlotModel
from .models import Job as JobModel
from .models import JobSplit as JobSplitModel

from ..ui.forms import CodeMirrorRSTCharField
from ..common.texts import Messages
from ..common.admin import Django18ProofGuardedModelAdmin, notify_by_email

#----------------------------------------------------------

[docs]class EnvironmentModelForm(forms.ModelForm): description = CodeMirrorRSTCharField( required=False, help_text=Messages['description'], )
[docs] class Meta: model = EnvironmentModel exclude = [] widgets = { 'name': forms.TextInput( attrs=dict(size=100), ), 'version': forms.TextInput( attrs=dict(size=40), ), 'short_description': forms.TextInput( attrs=dict(size=100), ), }
[docs]class EnvironmentLanguageInline(admin.TabularInline): model = EnvironmentLanguageModel
[docs]class Environment(admin.ModelAdmin): list_display = ( 'id', 'name', 'version', 'sharing', 'active', 'short_description', ) search_fields = [ 'name', 'version', 'short_description', 'description', ] list_display_links = ( 'id', 'name', ) inlines = [ EnvironmentLanguageInline ] form = EnvironmentModelForm filter_horizontal = [ 'shared_with', 'shared_with_team' ] actions = [ notify_by_email('environment_notifications_enabled'), ] fieldsets = ( (None, dict( fields=('name', 'version', 'previous_version', 'active'), ), ), ('Documentation', dict( classes=('collapse',), fields=('short_description', 'description',), ), ), ('Sharing', dict( classes=('collapse',), fields=('sharing', 'shared_with', 'shared_with_team'), ), ), )
admin.site.register(EnvironmentModel, Environment) #----------------------------------------------------------
[docs]def activate_workers(modeladmin, request, queryset): """Activates workers, so they can be normally used""" for q in queryset: q.active = True q.save()
activate_workers.short_description = 'Activate selected workers'
[docs]def deactivate_workers(modeladmin, request, queryset): """Deactivates workers, so they cannot be used""" for q in queryset: q.active = False q.save()
deactivate_workers.short_description = 'Deactivate selected workers'
[docs]class Worker(admin.ModelAdmin): list_display = ('id', 'name', 'cores', 'memory', 'active') search_fields = ['name'] list_display_links = ('id', 'name') actions = [ activate_workers, deactivate_workers, ]
admin.site.register(WorkerModel, Worker) #----------------------------------------------------------
[docs]class SlotInline(admin.TabularInline): model = SlotModel
#----------------------------------------------------------
[docs]class Queue(Django18ProofGuardedModelAdmin): list_display = ('id', 'name', 'memory_limit', 'time_limit', 'cores_per_slot', 'max_slots_per_user') search_fields = ['name'] list_display_links = ('id', 'name') inlines = [SlotInline]
admin.site.register(QueueModel, Queue) #----------------------------------------------------------
[docs]class JobSplitInline(admin.TabularInline): model = JobSplitModel
[docs] def has_delete_permission(self, request, obj=None): return False
[docs] def has_add_permission(self, request): return False
[docs]class Job(admin.ModelAdmin): list_display = ('id', 'key', 'runnable_date', 'start_date', 'block', 'splits') search_fields = ['block__name', 'block__experiment__name'] list_display_links = ('id', 'block', 'key') ordering = ('runnable_date', 'start_date', 'id') inlines = [JobSplitInline] # to avoid very slow loading of cached files raw_id_fields = ('block',)
[docs] def splits(self, obj): return obj.splits.count()
[docs] def has_add_permission(self, request): return False
admin.site.register(JobModel, Job)