From 4c59c651baa7e9d29f90419c905745fd3ab025d8 Mon Sep 17 00:00:00 2001 From: Weitian LI Date: Mon, 21 Apr 2014 16:09:36 +0800 Subject: * implemented 'list_approved' view, added related template * updated related link in 'navbar.html' --- account/models.py | 12 ++++++++ account/templates/account/list_approved.html | 45 ++++++++++++++++++++++++++++ account/urls.py | 5 +++- account/views.py | 21 +++++++++++++ templates/navbar.html | 3 ++ 5 files changed, 85 insertions(+), 1 deletion(-) create mode 100644 account/templates/account/list_approved.html diff --git a/account/models.py b/account/models.py index 38047d6..684f2d8 100644 --- a/account/models.py +++ b/account/models.py @@ -55,6 +55,18 @@ class UserProfile(models.Model): def __unicode__(self): return u'UserProfile for %s' % self.user + def get_approved(self, *args, **kwargs): + """ + return list of approved object + """ + return self.objects.filter(is_approved='Y') + + def get_sponsored(self, *args, **kwargs): + """ + return list of sponsored object + """ + return self.objects.filter(is_sponsored='Y') + ###### signal callback ###### def user_registered_callback(sender, user, request, **kwargs): diff --git a/account/templates/account/list_approved.html b/account/templates/account/list_approved.html new file mode 100644 index 0000000..4bae4a2 --- /dev/null +++ b/account/templates/account/list_approved.html @@ -0,0 +1,45 @@ +{% extends 'base.html' %} +{% load staticfiles %} +{% load url from future %} +{% load bootstrap3 %} + +{# login template #} + +{% block title %} +审定名单 | 2014 SKA Summer School +{% endblock %} + +{% block content %} +
+

审定名单

+
+ {% if object_list %} + + + + + + + + + + {# mark out current user if approved #} + {% for profile in object_list %} + + + + + + {% endfor %} + +
序号姓名单位
{{ forloop.counter }}{{ profile.realname }}{{ profile.institute }}
+

(注:按注册先后排序)

+ {% else %} +
+ 审核正在进行,请稍后查询…… +
+ {% endif %} +
+{% endblock %} + +{# vim: set ts=8 sw=2 tw=0 fenc=utf-8 ft=htmldjango.html: #} diff --git a/account/urls.py b/account/urls.py index b61e0e2..e193772 100644 --- a/account/urls.py +++ b/account/urls.py @@ -12,7 +12,7 @@ from django.contrib.auth.decorators import login_required from registration.backends.default.views import ActivationView from registration.backends.default.views import RegistrationView -from account.views import ProfileView, UpdateProfileView +from account.views import ProfileView, UpdateProfileView, ListApprovedView from account.forms import UserRegForm @@ -48,6 +48,9 @@ urlpatterns = patterns('', url(r'^password/change/done$', 'django.contrib.auth.views.password_change_done', {'template_name': 'account/password_change_done.html'}, name='password_change_done'), + ## show approved user list + url(r'^list/approved/$', login_required(ListApprovedView.as_view()), + name='list_approved'), ) urlpatterns += patterns('', diff --git a/account/views.py b/account/views.py index e6b90b1..3186abb 100644 --- a/account/views.py +++ b/account/views.py @@ -7,6 +7,7 @@ views.py of app 'account' from django.shortcuts import render from django.views.generic.base import TemplateView from django.views.generic.edit import UpdateView +from django.views.generic.list import ListView from django.core.urlresolvers import reverse_lazy from django.http import HttpResponseRedirect @@ -29,6 +30,7 @@ class ProfileView(TemplateView): context['profile'] = profile return context + class UpdateProfileView(UpdateView): form_class = UpdateProfileForm model = UserProfile @@ -66,3 +68,22 @@ class UpdateProfileView(UpdateView): return super(UpdateProfileView, self).form_valid(form) +class ListApprovedView(ListView): + """ + class-based view to show list of approved users + """ + queryset = UserProfile.objects.filter(is_approved='Y') + template_name = 'account/list_approved.html' + # allow queryset/model returns no object, otherwise 404error raised + allow_empty = True + + def get_context_data(self, **kwargs): + """ + add 'user' context + """ + context = super(ListApprovedView, self).get_context_data(**kwargs) + user = self.request.user + context['user'] = user + return context + + diff --git a/templates/navbar.html b/templates/navbar.html index 6296c6c..906bcf2 100644 --- a/templates/navbar.html +++ b/templates/navbar.html @@ -24,6 +24,9 @@