#!/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.contrib.auth.admin import UserAdmin
from django.contrib.auth.models import User
from ..accounts.models import AccountSettings
from ..accounts.models import Profile
from ..accounts.models import SupervisionTrack
from ..accounts.models import TemporaryUrl
from .models import Agreement
# ----------------------------------------------------------
[docs]class AgreementInline(admin.StackedInline):
model = Agreement
# ----------------------------------------------------------
[docs]class AccountSettingsInline(admin.StackedInline):
model = AccountSettings
# ----------------------------------------------------------
[docs]class SupervisionTrackInline(admin.StackedInline):
model = SupervisionTrack
fk_name = "supervisor"
# ----------------------------------------------------------
[docs]class ProfileInline(admin.StackedInline):
model = Profile
# ----------------------------------------------------------
[docs]class UserAdmin(UserAdmin):
[docs] def agreement_number(self, obj):
return obj.agreement.version
agreement_number.admin_order_field = "agreement__version"
[docs] def notifications(self, obj):
return (
int(obj.accountsettings.daily_summary)
+ int(obj.accountsettings.experiment_mail_notifications_enabled)
+ int(obj.accountsettings.database_notifications_enabled)
+ int(obj.accountsettings.environment_notifications_enabled)
)
[docs] def supervisor(self, obj):
return obj.profile.is_supervisor
[docs] def status(self, obj):
return obj.profile.status
[docs] def supervision(self, obj):
if obj.is_staff:
return "Staff account"
if obj.profile.is_supervisor:
return "Supervisor account"
else:
supervisiontrack = SupervisionTrack.objects.get(
supervisee=obj, is_valid=True
)
supervisor = supervisiontrack.supervisor
return supervisor
[docs] def supervision_key(self, obj):
return obj.profile.supervision_key
[docs] def rejection_date(self, obj):
return obj.profile.rejection_date
list_display = (
"username",
"is_staff",
"email",
"notifications",
"agreement_number",
"last_login",
"supervisor",
"status",
"supervision",
"supervision_key",
"rejection_date",
)
ordering = (
"-is_staff",
"-last_login",
"username",
)
inlines = (
AgreementInline,
AccountSettingsInline,
SupervisionTrackInline,
ProfileInline,
)
admin.site.unregister(User)
admin.site.register(User, UserAdmin)
# ----------------------------------------------------------
[docs]class SupervisionTrackAdmin(admin.ModelAdmin):
list_display = (
"supervisor",
"supervisee",
"is_valid",
"start_date",
"expiration_date",
"last_validation_date",
"supervision_key",
)
ordering = ("supervisor",)
admin.site.register(SupervisionTrack, SupervisionTrackAdmin)
# ----------------------------------------------------------
[docs]class ProfileAdmin(admin.ModelAdmin):
list_display = (
"user",
"status",
"registration_date",
"is_supervisor",
"supervision_key",
"rejection_date",
)
ordering = ("user",)
admin.site.register(Profile, ProfileAdmin)
# ----------------------------------------------------------
[docs]class TemporaryUrlAdmin(admin.ModelAdmin):
[docs] def supervision_key(self, obj):
return obj.supervision_track.supervision_key
list_display = (
"url_hash",
"expires",
"supervision_track",
"supervision_key",
"status",
)
ordering = ("expires",)
admin.site.register(TemporaryUrl, TemporaryUrlAdmin)