From c4326d0f4b5bd675f377c4582b09122ed6afd8e9 Mon Sep 17 00:00:00 2001 From: gfawcett Date: Fri, 20 Mar 2009 02:47:08 +0000 Subject: [PATCH] added user-preference, 'I want email when new items show up.' Prefs UI to change it. Still no actual mechanism to send the emails though! That's to come. git-svn-id: svn://svn.open-ils.org/ILS-Contrib/servres/trunk@208 6d9bc8c9-1ec2-4278-b937-99fde70a366f --- conifer/syrup/admin.py | 17 ----------------- conifer/syrup/models.py | 10 ++++++++-- conifer/syrup/views.py | 20 ++++++++++++++------ conifer/templates/prefs.xhtml | 32 ++++++++++++++++++++++++++++++++ conifer/templates/setlang.xhtml | 23 ----------------------- 5 files changed, 54 insertions(+), 48 deletions(-) create mode 100644 conifer/templates/prefs.xhtml delete mode 100644 conifer/templates/setlang.xhtml diff --git a/conifer/syrup/admin.py b/conifer/syrup/admin.py index a0f4324..084f743 100644 --- a/conifer/syrup/admin.py +++ b/conifer/syrup/admin.py @@ -3,24 +3,7 @@ from django.contrib import admin import django.db.models -#import conifer.syrup.models as models from conifer.syrup.models import * -# from django.db.models.fields import CharField - -# def unicode_fn(fld): -# def un(self): -# return getattr(self, fld) -# return un - -# for name, value in models.__dict__.items(): -# if isinstance(value, type) and issubclass(value, django.db.models.Model): -# localfields = value._meta.local_fields -# tmp = [x for x in localfields if isinstance(x, CharField)] -# if tmp: -# firstcharfield = tmp[0].name -# print (value.__name__, firstcharfield) -# value.__unicode__ = unicode_fn(firstcharfield) -# admin.site.register(value) for m in [LibraryUnit, ServiceDesk, Member, Department, Course, Term, UserProfile, NewsItem, Target]: diff --git a/conifer/syrup/models.py b/conifer/syrup/models.py index e1338cd..e2ad697 100644 --- a/conifer/syrup/models.py +++ b/conifer/syrup/models.py @@ -4,7 +4,7 @@ from django.contrib.auth.models import AnonymousUser from django.contrib.auth import get_backends from datetime import datetime from genshi import Markup -from gettext import gettext as _ # fixme, is this the right function to import? +from django.utils.translation import ugettext as _ from conifer.custom import course_codes # fixme, not sure if conifer.custom is a good parent. from conifer.custom import course_sections # fixme, not sure if conifer.custom is a good parent. import re @@ -64,9 +64,15 @@ class UserProfile(m.Model): user = m.ForeignKey(User, unique=True) home_phone = m.CharField(max_length=100, blank=True) home_address = m.TextField(blank=True) - ils_userid = m.TextField("Alternate userid in the ILS, if any", + ils_userid = m.CharField(_('Alternate userid in the ILS, if any'), max_length=50, blank=True) + # When we add email notices for new items, this is how we'll set + # the preference, and how far back we'll need to look. + wants_email_notices = m.BooleanField(default=False) + last_email_notice = m.DateTimeField(default=datetime.now, + blank=True, null=True) + def __unicode__(self): return 'UserProfile(%s)' % self.user diff --git a/conifer/syrup/views.py b/conifer/syrup/views.py index 4a99a33..84189cf 100644 --- a/conifer/syrup/views.py +++ b/conifer/syrup/views.py @@ -19,7 +19,7 @@ from conifer.syrup import models from datetime import datetime from django.contrib.auth import authenticate, login, logout from django.contrib.auth.decorators import login_required -from django.contrib.auth.models import User +from django.contrib.auth.models import User, SiteProfileNotAvailable from django.core.paginator import Paginator from django.db.models import Q from django.http import HttpResponse, HttpResponseRedirect @@ -97,6 +97,12 @@ def auth_handler(request, path): _('Sorry, this account has been disabled.')) else: login(request, user) + # initialize the profile if it doesn't exist. + try: + user.get_profile() + except models.UserProfile.DoesNotExist: + profile = models.UserProfile.objects.create(user=user) + profile.save() return HttpResponseRedirect(request.POST.get('next', '/syrup/')) elif path == 'logout': logout(request) @@ -182,9 +188,6 @@ def public(handler): def welcome(request): return g.render('welcome.xhtml') -def setlang(request): - return g.render('setlang.xhtml') - # MARK: propose we get rid of this. We already have a 'Courses' browser. def open_courses(request): page_num = int(request.GET.get('page', 1)) @@ -215,8 +218,13 @@ def departments(request): def user_prefs(request): - # for now, just send to the 'setlang' page. Better than 'under construction.' - return HttpResponseRedirect('../setlang') + if request.method != 'POST': + return g.render('prefs.xhtml') + else: + profile = request.user.get_profile() + profile.wants_email_notices = bool(request.POST.get('wants_email_notices')) + profile.save() + return HttpResponseRedirect('../') def z3950_test(request): conn = zoom.Connection ('z3950.loc.gov', 7090) diff --git a/conifer/templates/prefs.xhtml b/conifer/templates/prefs.xhtml new file mode 100644 index 0000000..ef4b7c2 --- /dev/null +++ b/conifer/templates/prefs.xhtml @@ -0,0 +1,32 @@ + + + + + ${title} + + +

${title}

+

Preferred Language

+
+ + +
+
+

Notification preferences

+
+ + +

+
+
+ + diff --git a/conifer/templates/setlang.xhtml b/conifer/templates/setlang.xhtml deleted file mode 100644 index d9d63b8..0000000 --- a/conifer/templates/setlang.xhtml +++ /dev/null @@ -1,23 +0,0 @@ - - - - - ${title} - - -

${title}

-
- - - -
- - -- 2.11.0