Adam Knight avatar Adam Knight committed fd0cf23

Various admin fixes.

Comments (0)

Files changed (3)

     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', 'sites']}),
         (_('Content'),        {'fields': ['content_format', 'content', 'template_name']}),
-        (_('Availability'), {'fields': ['status', 'date_published', 'date_hidden'], 'classes':('collapse',)}),
+        (_('Availability'), {'fields': ['status', 'date_published', 'date_hidden', 'date_created', 'date_modified'], 'classes':('collapse',)}),
     ]
     
     def absolute_url(self, obj):
 ### STORIES ###
 
 class StoryAdmin(admin.ModelAdmin):
-    list_display = ('title', 'tags', 'status', 'allow_comments', 'date_published', 'date_hidden', 'date_modified')
-    list_editable = ('status',)
-    list_filter = ('date_published', 'date_hidden', 'date_modified', 'status')
+    list_display = ('title', 'tags', 'section', 'status', 'allow_comments', 'date_published', 'date_hidden', 'date_modified')
+    list_editable = ('status','section')
+    list_filter = ('section', 'date_published', 'date_hidden', 'date_modified', 'status')
     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']}),
+        ('',                {'fields': ['user', 'title', 'slug', 'tags', 'section', 'allow_comments', 'sites']}),
         ('Content',            {'fields': ['teaser_format', 'teaser', 'content_format', 'content']}),
-        ('Availability',    {'fields': ['status', 'date_published', 'date_hidden', 'allow_comments', 'sites'], 'classes':('collapse',)}),
+        ('Availability',    {'fields': ['status', 'date_published', 'date_hidden', 'date_created', 'date_modified'], 'classes':('collapse',)}),
         ]
 
 admin.site.register(Story, StoryAdmin)
     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__()
         ("Destination", {"fields": ["current", "content_type", "object_id"]}),
         ("Options", {"fields": ["permanent"]})
     )
+    readonly_fields = ['date_created', 'date_modified']
+
 admin.site.register(Redirect, RedirectAdmin)

context_preprocessors/__init__.py

 from django.conf import settings
 from django.contrib.sites.models import Site
+from milton.models import Story, Section
 
 def general(request):
     return {
         "site": Site.objects.get_current(),
+        "stories": Story.published.all(),
+        "sections": Section.objects.all(),
     }
 
 ### Model Objects ###
 
+class Section(SPObject):
+    # TODO: Create admin class that auto-gens the slug
+    name = models.CharField("Section Name", max_length=255)
+    slug = models.SlugField("Section Slug", max_length=255)
+    # page = models.ForeignKey(Page, null=True, blank=True, help_text="A page to display instead of a section index.")
+    
+    class Meta:
+        verbose_name = "section"
+        verbose_name_plural = "sections"
+    
+    def __unicode__(self):
+        return self.name
+    
+    @models.permalink
+    def get_absolute_url(self):
+        return ('story-archive',(), {'section':self.slug})
+
+
 class Resource(SPObject):
     # Properties
     sites = models.ManyToManyField(Site, default=[settings.SITE_ID], null=False, blank=False, help_text='The site(s) this item is accessible at.')
             ch.save()
 
 
-class Section(SPObject):
-    # TODO: Create admin class that auto-gens the slug
-    name = models.CharField("Section Name", max_length=255)
-    slug = models.SlugField("Section Slug", max_length=255)
-    # page = models.ForeignKey(Page, null=True, blank=True, help_text="A page to display instead of a section index.")
-    
-    class Meta:
-        verbose_name = "section"
-        verbose_name_plural = "sections"
-    
-    def __unicode__(self):
-        return self.name
-    
-    @models.permalink
-    def get_absolute_url(self):
-        return ('section-archive',(), {'section':self.slug})
-
-
 class Page(Resource):
     url = models.CharField("URL", max_length=255, db_index=True, help_text="The URL for this page. Ensure it begins and ends with a slash.")
     template_name = models.CharField("Template", max_length=255, blank=True, help_text="If specified, this template will be used instead of 'page.html'")
         verbose_name = "page"
         verbose_name_plural = "pages"
         get_latest_by = 'date_published'
-        ordering = ['-date_published','-date_modified']
     
     def __unicode__(self):
         return "%s; %s" % (self.url, self.title)
 
 class Redirect(SPObject):
     site = models.ForeignKey(Site, default=settings.SITE_ID, help_text='The site this redirect is applicable to.')
-    original = models.CharField("Original path", max_length=255, unique=True, db_index=True,
+    original = models.CharField("Original path", max_length=255, db_index=True,
         help_text='The original path for this resource.  This must be an absolute path starting from the root of the site.')
     current = models.CharField("Current path", max_length=255, null=True, blank=True,
         help_text='The current path to this resource, if it is not an object.')
         verbose_name = "redirect"
         verbose_name_plural = "redirects"
         ordering = ['-date_created']
+        unique_together = ("site", "original")
     
     def __unicode__(self):
         return "%s to (%s, %s)" % (self.original, self.current, self.target_object)
         ordering = ['-date_created', 'content_type', 'object_id']
     
     def __unicode__(self):
-        return "%s: %s" % (self.owner, self.field_name)
+        return u"%s: %s" % (self.owner, self.field_name)
     
     @classmethod
     def history(owner, field):
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 ProjectModifiedEvent.java.
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.