HG changeset patch User Yury Yurevich the pythy gmail com Date 1239293

  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
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
# HG changeset patch
# User Yury Yurevich <the.pythy@gmail.com>
# Date 1239293591 -25200
# Node ID 59b1ca9944fd8341df135492e3ee83083cb984b5
# Parent b2fb12916ade5e385f97c918111610cd5393c542
blog: move custom model admin baseclass to separate module:
welcome lib.libadmin.BFAdmin
diff -r b2fb12916ade -r 59b1ca9944fd apps/blog/admin.py
--- a/apps/blog/admin.py Thu Apr 09 23:10:47 2009 +0700
+++ b/apps/blog/admin.py Thu Apr 09 23:13:11 2009 +0700
@@ -3,11 +3,11 @@
from django.contrib.auth.models import User
from django.utils.translation import ugettext_lazy as _
from django.conf import settings
-
+from lib import libadmin
from blog.models import Post
-class PostAdmin(admin.ModelAdmin):
+class PostAdmin(libadmin.BFAdmin):
prepopulated_fields = {'slug': ('name', )}
list_display = ('name', 'date', 'author', 'enable_comments', 'comments_open', 'is_draft', 'site', 'view_link')
search_fields = ('name', 'text')
@@ -26,24 +26,4 @@
if settings.RENDER_METHOD in ('html', 'markdown', 'rst'):
js = (settings.STATIC_URL + 'js/postimage.js', )
- def queryset(self, request):
- qs = super(PostAdmin, self).queryset(request)
- if not request.user.is_superuser:
- qs = qs.filter(author=request.user)
- return qs
-
- def get_form(self, request, obj=None, **kwargs):
- '''
- Overwrite get_form to select the currently logged in user as the author
- '''
- form = super(PostAdmin, self).get_form(request, obj, **kwargs)
- f = form.base_fields['author']
- f.initial = request.user.pk
- if request.user.is_superuser:
- f.queryset = User.objects.filter(is_staff=True)
- else:
- f.queryset = User.objects.filter(pk=request.user.pk)
- form.base_fields['site'].initial = settings.SITE_ID
- return form
-
admin.site.register(Post, PostAdmin)
diff -r b2fb12916ade -r 59b1ca9944fd apps/lib/libadmin.py
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/apps/lib/libadmin.py Thu Apr 09 23:13:11 2009 +0700
@@ -0,0 +1,30 @@
+from django.contrib import admin
+from django.contrib.auth.models import User
+from django.contrib.sites.models import Site
+
+class BFAdmin(admin.ModelAdmin):
+ """
+ Model admin with default values for site and author
+ fields
+ """
+
+ def queryset(self, request):
+ qs = super(BFAdmin, self).queryset(request)
+ if not request.user.is_superuser:
+ qs = qs.filter(author=request.user)
+ return qs
+
+ def get_form(self, request, obj=None, **kwargs):
+ '''
+ Overwrite get_form to select the currently logged in user as the author
+ '''
+ form = super(BFAdmin, self).get_form(request, obj, **kwargs)
+ f = form.base_fields['author']
+ f.initial = request.user.pk
+ if request.user.is_superuser:
+ f.queryset = User.objects.filter(is_staff=True)
+ else:
+ f.queryset = User.objects.filter(pk=request.user.pk)
+ form.base_fields['site'].initial = Site.objects.get_current().pk
+ return form
+
# HG changeset patch
# User Yury Yurevich <the.pythy@gmail.com>
# Date 1239293775 -25200
# Node ID 1d59275d67f5c67d38f18bc7c70762ffadb0a012
# Parent 59b1ca9944fd8341df135492e3ee83083cb984b5
friends: use custom baseclass for admin,
previously separated from blog's PostAdmin (lib.libadmin.BFAdmin)
diff -r 59b1ca9944fd -r 1d59275d67f5 apps/friends/admin.py
--- a/apps/friends/admin.py Thu Apr 09 23:13:11 2009 +0700
+++ b/apps/friends/admin.py Thu Apr 09 23:16:15 2009 +0700
@@ -1,9 +1,9 @@
from django.contrib import admin
-
+from lib import libadmin
from friends.models import FriendBlog
-class FriendBlogAdmin(admin.ModelAdmin):
+class FriendBlogAdmin(libadmin.BFAdmin):
list_display = ('name', 'feed', 'link', 'active')
search_fields = ('name', 'feed', 'link')