milton /

from django import forms
from django.contrib import admin
from django.utils.translation import ugettext_lazy as _

from milton.models import *


def action_mark_draft(model_admin, request, query_set):
action_mark_draft.short_description = "Change status of selected items to Draft"

def action_mark_published(model_admin, request, query_set):
action_mark_published.short_description = "Change status of selected items to Published"

def action_open_comments(model_admin, request, query_set):
action_open_comments.short_description = "Allow comments on the selected items"

def action_close_comments(model_admin, request, query_set):
action_close_comments.short_description = "Close comments on the selected items"

def action_disable_comments(model_admin, request, query_set):
action_disable_comments.short_description = "Disable and hide comments on the selected items"

### PAGES ###

class PageForm(forms.ModelForm):
    url = forms.RegexField(label=_("URL"), max_length=255, regex=r'^[-\w/]+$',
        help_text      = _("Example: '/about/contact/'. Make sure to have leading"
                      " and trailing slashes."),
        error_message = _("This value must contain only letters, numbers,"
                          " underscores, dashes or slashes."))
    class Meta:
        model = Page

class PageAdmin(admin.ModelAdmin):
    form           = PageForm
    list_display   = ('title', 'absolute_url', 'visible', 'status', 'date_created', 'date_modified', 'date_published', 'date_hidden')
    list_editable  = ('status',)
    list_filter       = ('date_published', 'date_modified', 'status')
    date_hierarchy = 'date_published'
    search_fields  = ('title', 'url')
    actions           = [action_mark_draft, action_mark_published]
    readonly_fields = ['date_created', 'date_modified']
    fieldsets       = [
        ('',                {'fields': ['title', 'url', 'site']}),
        (_('Content'),        {'fields': ['content_format', 'content', 'template_name']}),
        (_('Availability'), {'fields': ['status', 'date_published', 'date_hidden', 'date_created', 'date_modified'], 'classes':('collapse',)}),
    def absolute_url(self, obj):
        return obj.get_absolute_url(), PageAdmin)

### STORIES ###

class StoryAdmin(admin.ModelAdmin):
    list_display = ('title', 'site_name', 'section', 'status', 'allow_comments', 'date_published', 'date_hidden', 'date_modified')
    list_editable = ('status','section')
    list_filter = ('section', 'date_published', 'date_hidden', 'date_modified', 'status', 'site__name')
    date_hierarchy = 'date_published'
    search_fields = ('title', '^user__username', 'slug')
    prepopulated_fields = {"slug": ("title",)}
    actions = [action_mark_draft, action_mark_published, action_open_comments, action_close_comments, action_disable_comments]
    readonly_fields = ['date_created', 'date_modified']
    fieldsets = [
        ('',                {'fields': ['user', 'title', 'slug', 'tags', 'section', 'allow_comments', 'site']}),
        ('Content',            {'fields': ['teaser_format', 'teaser', 'content_format', 'content']}),
        ('Availability',    {'fields': ['status', 'date_published', 'date_hidden', 'date_created', 'date_modified'], 'classes':('collapse',)}),
    def site_name(self, obj):
        return, StoryAdmin)

class ContentHistoryAdmin(admin.ModelAdmin):
    list_display = ('title', 'content_type', 'object_id', 'field_name', 'date_created')
    list_filter = ('field_name', 'date_created')
    date_hierarchy = 'date_created'
    search_fields = ('field_name', 'content')
    readonly_fields = ['date_created', 'date_modified']
    def title(self, obj):
        return obj.__unicode__()
    title.short_description = "Item Name", ContentHistoryAdmin)

### SECTIONS ###

class SectionAdmin(admin.ModelAdmin):
    list_display = ("name", "slug")
    prepopulated_fields = {"slug": ("name",)}, SectionAdmin)

class RedirectAdmin(admin.ModelAdmin):
    list_display = ("original", "current", "site", "content_type", "object_id", "permanent", "date_modified", "date_created")
    fieldsets = (
        ("Source", {"fields": ["site", "original"]}),
        ("Destination", {"fields": ["current", "content_type", "object_id"]}),
        ("Options", {"fields": ["permanent"]})
    list_filter = ('site__name', 'date_created', 'date_modified', 'permanent', 'content_type')
    readonly_fields = ['date_created', 'date_modified'], RedirectAdmin)

### SITE ###

class MiltonSiteAdmin(admin.ModelAdmin):
    list_display = ("name", "base_url", "alias_for"), MiltonSiteAdmin)
Tip: Filter by directory path e.g. /media app.js to search for public/media/app.js.
Tip: Use camelCasing e.g. ProjME to search for
Tip: Filter by extension type e.g. /repo .js to search for all .js files in the /repo directory.
Tip: Separate your search with spaces e.g. /ssh pom.xml to search for src/ssh/pom.xml.
Tip: Use ↑ and ↓ arrow keys to navigate and return to view the file.
Tip: You can also navigate files with Ctrl+j (next) and Ctrl+k (previous) and view the file with Ctrl+o.
Tip: You can also navigate files with Alt+j (next) and Alt+k (previous) and view the file with Alt+o.