2
0
mirror of https://expo.survex.com/repositories/troggle/.git synced 2024-11-22 07:11:52 +00:00
troggle/core/admin.py

164 lines
5.0 KiB
Python
Raw Normal View History

import django.forms as forms
2011-07-11 02:10:22 +01:00
from django.contrib import admin
from django.forms import ModelForm
from django.http import HttpResponse
from django.core import serializers
from troggle.core.views_other import downloadLogbook
from troggle.core.models import *
2020-06-04 23:16:26 +01:00
from troggle.core.models_caves import Cave, Area, Entrance, CaveAndEntrance, NewSubCave, OtherCaveName, CaveDescription, LogbookEntry, PersonTrip, QM
2020-05-30 12:35:15 +01:00
from troggle.core.models_survex import SurvexBlock, SurvexPersonRole, SurvexStation, SurvexScansFolder, SurvexScanSingle
2011-07-11 02:10:22 +01:00
#from troggle.reversion.admin import VersionAdmin #django-reversion version control
class TroggleModelAdmin(admin.ModelAdmin):
def save_model(self, request, obj, form, change):
"""overriding admin save to fill the new_since parsing_field"""
obj.new_since_parsing=True
obj.save()
2011-07-11 02:10:22 +01:00
class Media:
js = ('jquery/jquery.min.js','js/QM_helper.js')
2011-07-11 02:10:22 +01:00
2011-07-11 02:10:22 +01:00
class RoleInline(admin.TabularInline):
model = SurvexPersonRole
extra = 4
2011-07-11 02:10:22 +01:00
class SurvexBlockAdmin(TroggleModelAdmin):
inlines = (RoleInline,)
2020-06-04 19:32:26 +01:00
# class ScannedImageInline(admin.TabularInline):
# model = ScannedImage
# extra = 4
2011-07-11 02:10:22 +01:00
2011-07-11 02:10:22 +01:00
class OtherCaveInline(admin.TabularInline):
model = OtherCaveName
extra = 1
2011-07-11 02:10:22 +01:00
class SurveyAdmin(TroggleModelAdmin):
2020-06-04 19:32:26 +01:00
#inlines = (ScannedImageInline,)
2011-07-11 02:10:22 +01:00
search_fields = ('expedition__year','wallet_number')
2011-07-11 02:10:22 +01:00
class QMsFoundInline(admin.TabularInline):
model=QM
fk_name='found_by'
fields=('number','grade','location_description','comment')#need to add foreignkey to cave part
extra=1
2020-05-15 21:32:55 +01:00
# class PhotoInline(admin.TabularInline):
# model = DPhoto
# exclude = ['is_mugshot' ]
# extra = 1
2011-07-11 02:10:22 +01:00
2011-07-11 02:10:22 +01:00
class PersonTripInline(admin.TabularInline):
model = PersonTrip
raw_id_fields = ('personexpedition',)
extra = 1
2011-07-11 02:10:22 +01:00
#class LogbookEntryAdmin(VersionAdmin):
class LogbookEntryAdmin(TroggleModelAdmin):
prepopulated_fields = {'slug':("title",)}
2011-07-11 02:10:22 +01:00
search_fields = ('title','expedition__year')
date_heirarchy = ('date')
2020-05-15 21:32:55 +01:00
# inlines = (PersonTripInline, PhotoInline, QMsFoundInline)
inlines = (PersonTripInline, QMsFoundInline)
2011-07-11 02:10:22 +01:00
class Media:
css = {
"all": ("css/troggleadmin.css",)
}
actions=('export_logbook_entries_as_html','export_logbook_entries_as_txt')
def export_logbook_entries_as_html(self, modeladmin, request, queryset):
2011-07-11 02:10:22 +01:00
response=downloadLogbook(request=request, queryset=queryset, extension='html')
return response
def export_logbook_entries_as_txt(self, modeladmin, request, queryset):
2011-07-11 02:10:22 +01:00
response=downloadLogbook(request=request, queryset=queryset, extension='txt')
return response
2011-07-11 02:10:22 +01:00
class PersonExpeditionInline(admin.TabularInline):
model = PersonExpedition
extra = 1
2011-07-11 02:10:22 +01:00
class PersonAdmin(TroggleModelAdmin):
search_fields = ('first_name','last_name')
inlines = (PersonExpeditionInline,)
2011-07-11 02:10:22 +01:00
class QMAdmin(TroggleModelAdmin):
search_fields = ('found_by__cave__kataster_number','number','found_by__date')
2020-05-26 02:21:36 +01:00
list_display = ('__str__','grade','found_by','ticked_off_by')
list_display_links = ('__str__',)
2011-07-11 02:10:22 +01:00
list_editable = ('found_by','ticked_off_by','grade')
list_per_page = 20
raw_id_fields=('found_by','ticked_off_by')
2011-07-11 02:10:22 +01:00
class PersonExpeditionAdmin(TroggleModelAdmin):
search_fields = ('person__first_name','expedition__year')
2011-07-11 02:10:22 +01:00
class CaveAdmin(TroggleModelAdmin):
search_fields = ('official_name','kataster_number','unofficial_number')
inlines = (OtherCaveInline,)
extra = 4
2011-07-11 02:10:22 +01:00
class EntranceAdmin(TroggleModelAdmin):
search_fields = ('caveandentrance__cave__kataster_number',)
2020-05-15 21:32:55 +01:00
#admin.site.register(DPhoto)
2011-07-11 02:10:22 +01:00
admin.site.register(Cave, CaveAdmin)
admin.site.register(Area)
#admin.site.register(OtherCaveName)
admin.site.register(CaveAndEntrance)
admin.site.register(NewSubCave)
admin.site.register(CaveDescription)
admin.site.register(Entrance, EntranceAdmin)
2019-06-26 20:57:24 +01:00
admin.site.register(SurvexBlock, SurvexBlockAdmin)
2011-07-11 02:10:22 +01:00
admin.site.register(Expedition)
admin.site.register(Person,PersonAdmin)
2019-06-26 20:57:24 +01:00
admin.site.register(SurvexPersonRole)
2011-07-11 02:10:22 +01:00
admin.site.register(PersonExpedition,PersonExpeditionAdmin)
admin.site.register(LogbookEntry, LogbookEntryAdmin)
#admin.site.register(PersonTrip)
admin.site.register(QM, QMAdmin)
2020-06-04 23:16:26 +01:00
#admin.site.register(Survey, SurveyAdmin)
2020-06-04 19:32:26 +01:00
#admin.site.register(ScannedImage)
admin.site.register(SurvexStation)
2019-06-26 20:57:24 +01:00
2011-07-11 02:10:22 +01:00
admin.site.register(SurvexScansFolder)
admin.site.register(SurvexScanSingle)
admin.site.register(DataIssue)
2011-07-11 02:10:22 +01:00
def export_as_json(modeladmin, request, queryset):
response = HttpResponse(content_type="text/json")
2011-07-11 02:10:22 +01:00
response['Content-Disposition'] = 'attachment; filename=troggle_output.json'
serializers.serialize("json", queryset, stream=response)
return response
2011-07-11 02:10:22 +01:00
def export_as_xml(modeladmin, request, queryset):
response = HttpResponse(content_type="text/xml")
2011-07-11 02:10:22 +01:00
response['Content-Disposition'] = 'attachment; filename=troggle_output.xml'
serializers.serialize("xml", queryset, stream=response)
return response
2011-07-11 02:10:22 +01:00
#admin.site.add_action(export_as_xml)
#admin.site.add_action(export_as_json)