Skip to content

Commit

Permalink
updated admin to make all blog post fields readonly
Browse files Browse the repository at this point in the history
also made subscription readonly once it is created.
  • Loading branch information
madisona committed Apr 3, 2012
1 parent f7cf123 commit c7afd76
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
9 changes: 7 additions & 2 deletions README.txt
Expand Up @@ -42,6 +42,11 @@ Blogger publishes the feed (I think) using the
``<blog_name>.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.
14 changes: 14 additions & 0 deletions blogger/admin.py
Expand Up @@ -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
Expand All @@ -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)

0 comments on commit c7afd76

Please sign in to comment.