#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2010-2012 Étienne Loks # This program is free software: you can redistribute it and/or modify # it under the terms of the GNU Affero General Public License as # published by the Free Software Foundation, either version 3 of the # License, or (at your option) any later version. # This program 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. See the # GNU Affero General Public License for more details. # You should have received a copy of the GNU Affero General Public License # along with this program. If not, see . # See the file COPYING for details. """ Admin description """ from django import forms from django.conf import settings from django.contrib import admin from django.core.exceptions import ObjectDoesNotExist from django.utils.translation import ugettext_lazy as _ import models class HistorizedObjectAdmin(admin.ModelAdmin): readonly_fields = ('history_modifier',) def save_model(self, request, obj, form, change): obj.history_modifier = request.user obj.save() class DepartmentAdmin(admin.ModelAdmin): list_display = ('number', 'label',) model = models.Department admin.site.register(models.Department, DepartmentAdmin) class OrganizationAdmin(HistorizedObjectAdmin): list_display = ('name', 'organization_type') list_filter = ("organization_type",) search_fields = ('name',) model = models.Organization admin.site.register(models.Organization, OrganizationAdmin) class PersonAdmin(HistorizedObjectAdmin): list_display = ('name', 'surname', 'email', 'person_type') list_filter = ("person_type",) search_fields = ('name', 'surname', 'email',) model = models.Person admin.site.register(models.Person, PersonAdmin) class TownAdmin(admin.ModelAdmin): list_display = ['name',] search_fields = ['name'] if settings.COUNTRY == 'fr': list_display += ['numero_insee', 'departement', ] search_fields += ['numero_insee', 'departement__label', ] list_filter = ("departement",) model = models.Town admin.site.register(models.Town, TownAdmin) class AuthorAdmin(admin.ModelAdmin): list_display = ['person', 'author_type'] list_filter = ("author_type",) model = models.Author admin.site.register(models.Author, AuthorAdmin) class PersonTypeAdmin(admin.ModelAdmin): model = models.PersonType filter_vertical = ('rights',) admin.site.register(models.PersonType, PersonTypeAdmin) basic_models = [models.IshtarUser, models.SourceType, models.AuthorType, models.OrganizationType] if settings.COUNTRY == 'fr': basic_models += [models.Arrondissement, models.Canton] for model in basic_models: admin.site.register(model)