From c7afd76b16230e2b56045769662f86a99e265166 Mon Sep 17 00:00:00 2001 From: Aaron Madison Date: Tue, 3 Apr 2012 06:33:59 -0500 Subject: [PATCH] updated admin to make all blog post fields readonly also made subscription readonly once it is created. --- README.txt | 9 +++++++-- blogger/admin.py | 14 ++++++++++++++ 2 files changed, 21 insertions(+), 2 deletions(-) diff --git a/README.txt b/README.txt index c40cfe5..40c2dc6 100644 --- a/README.txt +++ b/README.txt @@ -42,6 +42,11 @@ Blogger publishes the feed (I think) using the ``.blogspot.com/feeds/posts/default``. This is what you should use as the 'topic_url' when creating your subscription. +There is a template tag to provide a template with recent posts that +required Django>=1.4 because it uses the new assignment tag. + Todo: - Change to not use the "blog_id" from settings and instead just use the subscription - topic_url. + Change management commands to not use the "blog_id" from settings and instead + just use the subscription topic_url. + + todo: in the admin, display the blog post content as safe instead of raw html. diff --git a/blogger/admin.py b/blogger/admin.py index 697c8d8..9ab5b06 100644 --- a/blogger/admin.py +++ b/blogger/admin.py @@ -8,10 +8,18 @@ class PostAdmin(admin.ModelAdmin): list_display = ('title', 'author', 'published',) list_filter = ('published', 'author',) + exclude = ('content_type',) def has_add_permission(self, request): return False + def get_readonly_fields(self, request, obj=None): + # all fields come from feed, so nothing should be editable. + return [ + 'slug', 'post_id', 'published', + 'updated', 'title', 'content', + 'link_edit', 'link_self', 'link_alternate', 'author' + ] def sync_subscriptions(modeladmin, request, queryset): new_posts = 0 @@ -26,6 +34,12 @@ class HubbubSubscriptionAdmin(admin.ModelAdmin): readonly_fields = ['verify_token', 'is_verified'] actions = [sync_subscriptions] + def get_readonly_fields(self, request, obj=None): + # don't allow changes once the model is created. + if obj: + return ['topic_url', 'host_name'] + self.readonly_fields + return self.readonly_fields + admin.site.register(BloggerPost, PostAdmin) admin.site.register(HubbubSubscription, HubbubSubscriptionAdmin)