aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorWeitian LI <liweitianux@gmail.com>2014-04-30 19:42:24 +0800
committerWeitian LI <liweitianux@gmail.com>2014-04-30 19:42:24 +0800
commita390abcdd6b90810759a5178b8eae05fca0d7a6f (patch)
tree26ea6941a8c04f24e8d3fc9b8f7983726d30cce0
parent27310879e7bf456bdd33e9432f3255e7d741ece5 (diff)
downloaddjango-skaschool-a390abcdd6b90810759a5178b8eae05fca0d7a6f.tar.bz2
* added 'UserProfileAdmin' with actions and list_display:
o actions: - 'approve_users', - 'sponsor_users', - 'cancel_approve_users', - 'cancel_sponsor_users', - 'reset_approve_users', - 'reset_sponsor_users', o list_display: - 'user', - 'realname', - 'gender', - 'institute', - 'identify', - 'reason', - 'transcript_url', - 'supplement', - 'attachments', - 'is_approved', - 'is_sponsored', * updated zh_CN messages
-rw-r--r--account/admin.py135
-rw-r--r--locale/zh_CN/LC_MESSAGES/django.mobin3966 -> 5513 bytes
-rw-r--r--locale/zh_CN/LC_MESSAGES/django.po92
3 files changed, 221 insertions, 6 deletions
diff --git a/account/admin.py b/account/admin.py
index ee568fc..04ebf3b 100644
--- a/account/admin.py
+++ b/account/admin.py
@@ -1,11 +1,144 @@
# -*- coding: utf-8 -*-
from django.contrib import admin
+from django.utils.html import format_html
+from django.utils.translation import ugettext_lazy as _
from account.models import UserProfile, UserFile
+import os
-admin.site.register(UserProfile)
+
+class UserProfileAdmin(admin.ModelAdmin):
+ """
+ customize the admin interface for UserProfile
+ """
+ actions = [
+ 'approve_users',
+ 'sponsor_users',
+ 'cancel_approve_users',
+ 'cancel_sponsor_users',
+ 'reset_approve_users',
+ 'reset_sponsor_users',
+ ]
+ list_display = (
+ 'user',
+ 'realname',
+ 'gender',
+ 'institute',
+ 'identify',
+ 'reason',
+ 'transcript_url',
+ 'supplement',
+ 'attachments',
+ 'is_approved',
+ 'is_sponsored',
+ )
+
+ ## custom admin actions
+ def approve_users(self, request, queryset):
+ """
+ Approve the selected users.
+ """
+ profiles_updated = queryset.update(is_approved='Y')
+ if profiles_updated == 1:
+ msg = _("1 user was successfully approved.")
+ else:
+ msg = _("%(num)s users were successfully approved." % {'num': profiles_updated})
+ self.message_user(request, msg)
+ approve_users.short_description = _("Approve users")
+
+ def sponsor_users(self, request, queryset):
+ """
+ Sponsor the selected users.
+ """
+ profiles_updated = queryset.update(is_sponsored='Y')
+ if profiles_updated == 1:
+ msg = _("1 user was successfully sponsored.")
+ else:
+ msg = _("%(num)s users were successfully sponsored." % {'num': profiles_updated})
+ self.message_user(request, msg)
+ sponsor_users.short_description = _("Sponsor users")
+
+ def cancel_approve_users(self, request, queryset):
+ """
+ Cancel the approval of the selected users.
+ """
+ profiles_updated = queryset.update(is_approved='N')
+ if profiles_updated == 1:
+ msg = _("1 user was successfully cancelled approval.")
+ else:
+ msg = _("%(num)s users were successfully cancelled approval." % {'num': profiles_updated})
+ self.message_user(request, msg)
+ cancel_approve_users.short_description = _("Cancel approve users")
+
+ def cancel_sponsor_users(self, request, queryset):
+ """
+ Cancel the sponsor of the selected users.
+ """
+ profiles_updated = queryset.update(is_sponsored='N')
+ if profiles_updated == 1:
+ msg = _("1 user was successfully cancelled sponsor.")
+ else:
+ msg = _("%(num)s users were successfully cancelled sponsor." % {'num': profiles_updated})
+ self.message_user(request, msg)
+ cancel_sponsor_users.short_description = _("Cancel sponsor users")
+
+ def reset_approve_users(self, request, queryset):
+ """
+ Reset the approval of the selected users.
+ """
+ profiles_updated = queryset.update(is_approved='C')
+ if profiles_updated == 1:
+ msg = _("1 user was successfully reset approval.")
+ else:
+ msg = _("%(num)s users were successfully reset approval." % {'num': profiles_updated})
+ self.message_user(request, msg)
+ reset_approve_users.short_description = _("Reset approve users")
+
+ def reset_sponsor_users(self, request, queryset):
+ """
+ Reset the sponsor of the selected users.
+ """
+ profiles_updated = queryset.update(is_sponsored='C')
+ if profiles_updated == 1:
+ msg = _("1 user was successfully reset sponsor.")
+ else:
+ msg = _("%(num)s users were successfully reset sponsor." % {'num': profiles_updated})
+ self.message_user(request, msg)
+ reset_sponsor_users.short_description = _("Reset sponsor users")
+
+ ## custom fields
+ def transcript_url(self, obj):
+ """
+ return the html code of transcript with url link
+ """
+ return format_html('<a href="%(url)s">%(name)s</a>' % {
+ 'url': obj.transcript.url,
+ 'name': os.path.basename(obj.transcript.name),
+ })
+ transcript_url.short_description = _("Transcript")
+
+ def attachments(self, obj):
+ """
+ return the html code of attachments with url
+ """
+ user = obj.user
+ files = user.userfile_set.all()
+ if files:
+ attachments = ['<a href="%(url)s">%(name)s</a>' % {
+ 'url': userfile.file.url,
+ 'name': os.path.basename(userfile.file.name),
+ }
+ for userfile in files
+ ]
+ html = '<br>'.join(attachments)
+ else:
+ html = _("Null")
+ return format_html(html)
+
+
+admin.site.register(UserProfile, UserProfileAdmin)
admin.site.register(UserFile)
diff --git a/locale/zh_CN/LC_MESSAGES/django.mo b/locale/zh_CN/LC_MESSAGES/django.mo
index 11ee1e2..9ce7111 100644
--- a/locale/zh_CN/LC_MESSAGES/django.mo
+++ b/locale/zh_CN/LC_MESSAGES/django.mo
Binary files differ
diff --git a/locale/zh_CN/LC_MESSAGES/django.po b/locale/zh_CN/LC_MESSAGES/django.po
index 6009bd7..8af31e4 100644
--- a/locale/zh_CN/LC_MESSAGES/django.po
+++ b/locale/zh_CN/LC_MESSAGES/django.po
@@ -8,7 +8,7 @@ msgid ""
msgstr ""
"Project-Id-Version: 0.1\n"
"Report-Msgid-Bugs-To: \n"
-"POT-Creation-Date: 2014-04-29 09:09+0800\n"
+"POT-Creation-Date: 2014-04-30 19:28+0800\n"
"PO-Revision-Date: YEAR-MO-DA HO:MI+ZONE\n"
"Last-Translator: Weitian LI <liweitianux@gmail.com>\n"
"Language-Team: LANGUAGE <LL@li.org>\n"
@@ -18,6 +18,92 @@ msgstr ""
"Content-Transfer-Encoding: 8bit\n"
"Plural-Forms: nplurals=1; plural=0;\n"
+#: account/admin.py:45
+msgid "1 user was successfully approved."
+msgstr "1个用户被成功审定."
+
+#: account/admin.py:47
+#, python-format
+msgid "%(num)s users were successfully approved."
+msgstr "%(num)s个用户被成功审定."
+
+#: account/admin.py:49
+msgid "Approve users"
+msgstr "审定用户"
+
+#: account/admin.py:57
+msgid "1 user was successfully sponsored."
+msgstr "1个用户被成功资助."
+
+#: account/admin.py:59
+#, python-format
+msgid "%(num)s users were successfully sponsored."
+msgstr "%(num)s个用户被成功资助."
+
+#: account/admin.py:61
+msgid "Sponsor users"
+msgstr "资助用户"
+
+#: account/admin.py:69
+msgid "1 user was successfully cancelled approval."
+msgstr "1个用户的审定被取消."
+
+#: account/admin.py:71
+#, python-format
+msgid "%(num)s users were successfully cancelled approval."
+msgstr "%(num)s个用户的审定被取消."
+
+#: account/admin.py:73
+msgid "Cancel approve users"
+msgstr "取消用户审定"
+
+#: account/admin.py:81
+msgid "1 user was successfully cancelled sponsor."
+msgstr "1个用户的资助被取消."
+
+#: account/admin.py:83
+#, python-format
+msgid "%(num)s users were successfully cancelled sponsor."
+msgstr "%(num)s个用户的资助被取消."
+
+#: account/admin.py:85
+msgid "Cancel sponsor users"
+msgstr "取消用户资助"
+
+#: account/admin.py:93
+msgid "1 user was successfully reset approval."
+msgstr "1个用户的审定被重置."
+
+#: account/admin.py:95
+#, python-format
+msgid "%(num)s users were successfully reset approval."
+msgstr "%(num)s个用户的审定被重置."
+
+#: account/admin.py:97
+msgid "Reset approve users"
+msgstr "重置用户审定"
+
+#: account/admin.py:105
+msgid "1 user was successfully reset sponsor."
+msgstr "1个用户的资助被重置."
+
+#: account/admin.py:107
+#, python-format
+msgid "%(num)s users were successfully reset sponsor."
+msgstr "%(num)s个用户的审定被重置."
+
+#: account/admin.py:109
+msgid "Reset sponsor users"
+msgstr "重置用户资助"
+
+#: account/admin.py:120 account/models.py:74
+msgid "Transcript"
+msgstr "成绩单"
+
+#: account/admin.py:137
+msgid "Null"
+msgstr "无"
+
#: account/extra.py:49
#, python-format
msgid "Please keep filesize under %(maxsize)s. Current filesize %(filesize)s"
@@ -163,10 +249,6 @@ msgstr "用户"
msgid "Why attend"
msgstr "为什么参加"
-#: account/models.py:74
-msgid "Transcript"
-msgstr "成绩单"
-
#: account/models.py:75
msgid ""
"Undergraduate (junior and below) required to upload transcript. PDF format "