~widelands-dev/widelands-website/trunk

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
#!/usr/bin/env python -tt
# encoding: utf-8
#

from .models import Map
from django.contrib import admin

def delete_selected(modeladmin, request, queryset):
    """Overwritten Django's default action to delete a map.

    This action uses the delete() method of the map model. This ensures
    also deleting the corresponding files (.wmf and .png) of a map.

    """
    for obj in queryset:
        obj.delete()
delete_selected.short_description = 'Delete selected maps'


class MapAdmin(admin.ModelAdmin):
    actions = [delete_selected,]
    list_display = ['name', 'author', 'pub_date']
    prepopulated_fields = {'slug': ('name',)}
    search_fields = ['name', 'author']
    list_filter = ['pub_date']
    readonly_fields = ('uploader', 'nr_players', 'w', 'h', 'minimap', 'file', 'world_name')
    fieldsets = (
        (None, {
            'fields': (('name', 'author'), 'uploader', 'uploader_comment', 'wl_version_after')
        }),
        ('Map properties', {
            'classes': ('collapse',),
            'fields': ('descr', 'hint', 'world_name',
                       ('nr_players', 'w', 'h')
                       )
        }),
        ('Upload information', {
            'classes': ('collapse',),
            'fields': ('minimap', 'file', 'pub_date', 'nr_downloads', 'slug')
        }),
    )
admin.site.register(Map, MapAdmin)