#!/usr/bin/env python # -*- coding: utf-8 -*- # Copyright (C) 2012-2016 É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. from ajax_select import make_ajax_form from ajax_select.fields import AutoCompleteSelectField from django import forms from django.contrib import admin from django.contrib.gis.forms import PointField, PolygonField, \ LineStringField, OSMWidget from django.utils.translation import ugettext_lazy as _ from ishtar_common.apps import admin_site from ishtar_common.admin import HistorizedObjectAdmin, GeneralTypeAdmin import models class AdminBaseFindForm(forms.ModelForm): class Meta: model = models.BaseFind exclude = [] point_2d = PointField(label=_(u"Point (2D)"), required=False, widget=OSMWidget) line = LineStringField(label=_(u"Line"), required=False, widget=OSMWidget) polygon = PolygonField(label=_(u"Polygon"), required=False, widget=OSMWidget) context_record = AutoCompleteSelectField('context_record') class BaseFindAdmin(HistorizedObjectAdmin): list_display = ('label', 'context_record', 'index') search_fields = ('label', 'cache_complete_id',) model = models.BaseFind form = AdminBaseFindForm readonly_fields = HistorizedObjectAdmin.readonly_fields + [ 'cache_short_id', 'cache_complete_id', ] admin_site.register(models.BaseFind, BaseFindAdmin) class FindAdmin(HistorizedObjectAdmin): list_display = ('label', 'operations_lbl', 'context_records_lbl', 'index', 'dating', 'materials') list_filter = ('datings__period', 'material_types') search_fields = ('label', "base_finds__cache_complete_id", "base_finds__context_record__operation__cached_label") model = models.Find form = make_ajax_form(model, { 'base_finds': 'base_find', 'container': 'container' }) readonly_fields = HistorizedObjectAdmin.readonly_fields + [ 'datings', 'cached_label' ] admin_site.register(models.Find, FindAdmin) class FindSourceAdmin(admin.ModelAdmin): list_display = ('find', 'title', 'source_type',) list_filter = ('source_type',) search_fields = ('title', ) model = models.FindSource form = make_ajax_form(model, { 'authors': 'author', 'find': 'find' }) admin_site.register(models.FindSource, FindSourceAdmin) class PropertyAdmin(HistorizedObjectAdmin): list_display = ['find', 'person', 'start_date', 'end_date'] search_fields = ('find__label', 'person__name') model = models.Property form = make_ajax_form(model, { 'find': 'find', 'person': 'person', }) readonly_fields = HistorizedObjectAdmin.readonly_fields + [ 'administrative_act'] def has_add_permission(self, request): return False admin_site.register(models.Property, PropertyAdmin) class TreatmentAdmin(HistorizedObjectAdmin): list_display = ('year', 'index', 'label','treatment_types_lbl', 'location', 'downstream_lbl', 'upstream_lbl', 'container', 'person') list_filter = ('treatment_types', 'treatment_state', 'year') model = models.Treatment form = make_ajax_form(model, { 'person': 'person', 'organization': 'organization', 'file': 'treatment_file', 'location': 'warehouse', 'container': 'container', }) readonly_fields = HistorizedObjectAdmin.readonly_fields + [ 'cached_label', 'downstream_lbl', 'upstream_lbl' ] def has_add_permission(self, request): return False admin_site.register(models.Treatment, TreatmentAdmin) class TreatmentFileAdmin(HistorizedObjectAdmin): list_display = ('type', 'year', 'index', 'name', 'applicant', 'in_charge', 'internal_reference') list_filter = ('type', 'year') search_fields = ('name', 'applicant__name', 'applicant__surname', 'applicant__raw_name', 'applicant_organisation__name', 'cached_label') model = models.TreatmentFile form = make_ajax_form(model,{ 'in_charge': 'person', 'applicant': 'person', 'applicant_organisation': 'organization', }) readonly_fields = HistorizedObjectAdmin.readonly_fields + [ 'cached_label', ] admin_site.register(models.TreatmentFile, TreatmentFileAdmin) class TreatmentSourceAdmin(admin.ModelAdmin): list_display = ('title', 'treatment', 'source_type',) list_filter = ('source_type',) search_fields = ('title', 'treatment__cached_label') model = models.TreatmentSource form = make_ajax_form(model, { 'treatment': 'treatment', 'authors': 'author' }) admin_site.register(models.TreatmentSource, TreatmentSourceAdmin) class HierarchicalTypeAdmin(GeneralTypeAdmin): list_display = ['label', 'txt_idx', 'parent', 'available', 'comment'] admin_site.register(models.ObjectType, HierarchicalTypeAdmin) class MaterialTypeAdmin(HierarchicalTypeAdmin): list_display = HierarchicalTypeAdmin.list_display + ['recommendation'] search_fields = ('label', 'parent__label', 'comment',) admin_site.register(models.MaterialType, MaterialTypeAdmin) admin_site.register(models.CommunicabilityType, HierarchicalTypeAdmin) class TreatmentTypeAdmin(GeneralTypeAdmin): list_display = HierarchicalTypeAdmin.list_display + [ 'order', 'virtual', 'upstream_is_many', 'downstream_is_many'] model = models.TreatmentType admin_site.register(models.TreatmentType, TreatmentTypeAdmin) general_models = [ models.ConservatoryState, models.RemarkabilityType, models.IntegrityType, models.TreatmentFileType, models.TreatmentState, models.BatchType, models.AlterationCauseType, models.AlterationType, models.TreatmentEmergencyType ] for model in general_models: admin_site.register(model, GeneralTypeAdmin)