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