summaryrefslogtreecommitdiff
path: root/ishtar_common/admin.py
blob: b470f82232b43c1b5f608f70c0e80c90d6fb100b (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
#!/usr/bin/env python
# -*- coding: utf-8 -*-
# Copyright (C) 2010-2012 Étienne Loks  <etienne.loks_AT_peacefrogsDOTnet>

# 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 <http://www.gnu.org/licenses/>.

# 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)

class GeneralTypeAdmin(admin.ModelAdmin):
    list_display = ('label', 'txt_idx', 'available')

general_models = [models.OrganizationType, models.SourceType, models.AuthorType]
for model in general_models:
    admin.site.register(model, GeneralTypeAdmin)

basic_models = [models.IshtarUser]
if settings.COUNTRY == 'fr':
    basic_models += [models.Arrondissement, models.Canton]

for model in basic_models:
    admin.site.register(model)