diff options
Diffstat (limited to 'account')
-rw-r--r-- | account/models.py | 12 | ||||
-rw-r--r-- | account/templates/account/list_approved.html | 45 | ||||
-rw-r--r-- | account/urls.py | 5 | ||||
-rw-r--r-- | account/views.py | 21 |
4 files changed, 82 insertions, 1 deletions
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 %} + <div class="container"> + <h2>审定名单</h2> + <br> + {% if object_list %} + <table class="table table-striped table-bordered table-hover"> + <thead> + <tr> + <th class="col-md-1">序号</th> + <th class="col-md-3">姓名</th> + <th class="col-md-8">单位</th> + </tr> + </thead> + <tbody> + {# mark out current user if approved #} + {% for profile in object_list %} + <tr{% if profile.user == user %} class="success"{% endif %}> + <td>{{ forloop.counter }}</td> + <td>{{ profile.realname }}</td> + <td>{{ profile.institute }}</td> + </tr> + {% endfor %} + </tbody> + </table> + <p>(注:按注册先后排序)</p> + {% else %} + <div class="alert alert-warning"> + 审核正在进行,请稍后查询…… + </div> + {% endif %} + </div> +{% 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 + + |