Source code for beat.web.reports.admin

# vim: set fileencoding=utf-8 :
# encoding: 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/.           #
#                                                                             #
###############################################################################

# Flavio Tarsetti <flavio.tarsetti@idiap.ch>
# Wed May 20 15:46:11 CEST 2015

import simplejson as json
from django import forms
from django.contrib import admin

from ..common.texts import Messages
from ..ui.forms import CodeMirrorJSONCharField
from ..ui.forms import CodeMirrorRSTCharField
from .models import Report


[docs]class ReportModelForm(forms.ModelForm): description = CodeMirrorRSTCharField( label="Description", required=False, help_text=Messages["description"], ) content = CodeMirrorJSONCharField(label="Content", help_text=Messages["json"],)
[docs] def clean_content(self): """Cleans-up the content data, make sure it is really new""" try: data = json.loads(self.cleaned_data["content"]) return json.dumps(data, indent=4) except Exception as e: raise forms.ValidationError(str(e))
[docs]class ReportAdmin(admin.ModelAdmin): form = ReportModelForm readonly_fields = ("referenced_plotters", "referenced_plotterparameters") filter_horizontal = [ "experiments", "referenced_plotters", "referenced_plotterparameters", ] fieldsets = ( (None, dict(fields=("status", "name", "number", "author",),),), ( "Dates", dict( classes=("collapse",), fields=("creation_date", "expiration_date", "publication_date",), ), ), ( "Documentation", dict(classes=("collapse",), fields=("short_description", "description",),), ), ( None, dict( fields=( "analyzer", "experiments", "referenced_plotters", "referenced_plotterparameters", "content", ), ), ), ) list_display = ( "id", "name", "number", "author", "creation_date", "expiration_date", "publication_date", ) search_fields = [ "author__username", "name", "short_description", "description", "number", ] list_display_links = ("id", "name") list_filter = ("author", "name")
admin.site.register(Report, ReportAdmin)