| 1 | #!/usr/bin/env python |
|---|
| 2 | # -*- coding: utf-8 -*- |
|---|
| 3 | # |
|---|
| 4 | # Copyright 2010 Código Sur - Nuestra América Asoc. Civil / Fundación Pacificar. |
|---|
| 5 | # All rights reserved. |
|---|
| 6 | # |
|---|
| 7 | # This file is part of Cyclope. |
|---|
| 8 | # |
|---|
| 9 | # Cyclope is free software: you can redistribute it and/or modify |
|---|
| 10 | # it under the terms of the GNU General Public License as published by |
|---|
| 11 | # the Free Software Foundation, either version 3 of the License, or |
|---|
| 12 | # (at your option) any later version. |
|---|
| 13 | # |
|---|
| 14 | # Cyclope is distributed in the hope that it will be useful, |
|---|
| 15 | # but WITHOUT ANY WARRANTY; without even the implied warranty of |
|---|
| 16 | # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
|---|
| 17 | # GNU General Public License for more details. |
|---|
| 18 | # |
|---|
| 19 | # You should have received a copy of the GNU General Public License |
|---|
| 20 | # along with this program. If not, see <http://www.gnu.org/licenses/>. |
|---|
| 21 | |
|---|
| 22 | |
|---|
| 23 | from django.conf import settings |
|---|
| 24 | from django.contrib import admin |
|---|
| 25 | from django.utils.translation import ugettext_lazy as _ |
|---|
| 26 | from django.utils.importlib import import_module |
|---|
| 27 | |
|---|
| 28 | import cyclope.settings as cyc_settings |
|---|
| 29 | from cyclope.admin import BaseContentAdmin |
|---|
| 30 | from cyclope.core.collections.admin import CollectibleAdmin |
|---|
| 31 | |
|---|
| 32 | from models import Contact, ContactAddress |
|---|
| 33 | from forms import ContactForm |
|---|
| 34 | |
|---|
| 35 | class ContactAddressInline(admin.TabularInline): |
|---|
| 36 | model = ContactAddress |
|---|
| 37 | extra = 1 |
|---|
| 38 | fields = ('type', 'country', 'region', 'city', 'street_address', 'phone_number', |
|---|
| 39 | 'post_office_box') |
|---|
| 40 | |
|---|
| 41 | class ContactAdmin(CollectibleAdmin, BaseContentAdmin): |
|---|
| 42 | form = ContactForm |
|---|
| 43 | inlines = CollectibleAdmin.inlines + BaseContentAdmin.inlines + [ContactAddressInline] |
|---|
| 44 | |
|---|
| 45 | list_filter = CollectibleAdmin.list_filter + ('gender', ) |
|---|
| 46 | list_display = ('given_name', 'surname', 'gender', 'email', 'web', 'mobile_phone_number') |
|---|
| 47 | search_fields = ('given_name', 'surname', 'email', 'web', 'mobile_phone_number') |
|---|
| 48 | |
|---|
| 49 | fieldsets = ( |
|---|
| 50 | (None, { |
|---|
| 51 | 'fields': ('given_name', 'surname', 'birth_date', 'photo', 'gender', |
|---|
| 52 | 'email', 'web', 'mobile_phone_number') |
|---|
| 53 | }), |
|---|
| 54 | ) |
|---|
| 55 | |
|---|
| 56 | # Add ContactProfile admin as inline if defined in settings |
|---|
| 57 | if getattr(settings, 'CYCLOPE_CONTACTS_PROFILE_ADMIN_INLINE_MODULE', False): |
|---|
| 58 | _parts = settings.CYCLOPE_CONTACTS_PROFILE_ADMIN_INLINE_MODULE.split('.') |
|---|
| 59 | _inl = _parts[-1] |
|---|
| 60 | _mod = ".".join(_parts[:-1]) |
|---|
| 61 | _module = import_module(_mod) |
|---|
| 62 | profile_inline = getattr(_module, _inl) |
|---|
| 63 | inlines.append(profile_inline) |
|---|
| 64 | |
|---|
| 65 | |
|---|
| 66 | |
|---|
| 67 | admin.site.register(Contact, ContactAdmin) |
|---|