added user-preference, 'I want email when new items show up.' Prefs UI to change it.
authorgfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 20 Mar 2009 02:47:08 +0000 (02:47 +0000)
committergfawcett <gfawcett@6d9bc8c9-1ec2-4278-b937-99fde70a366f>
Fri, 20 Mar 2009 02:47:08 +0000 (02:47 +0000)
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
conifer/syrup/models.py
conifer/syrup/views.py
conifer/templates/prefs.xhtml [new file with mode: 0644]
conifer/templates/setlang.xhtml [deleted file]

index a0f4324..084f743 100644 (file)
@@ -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]:
index e1338cd..e2ad697 100644 (file)
@@ -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
 
index 4a99a33..84189cf 100644 (file)
@@ -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 (file)
index 0000000..ef4b7c2
--- /dev/null
@@ -0,0 +1,32 @@
+<?python
+from django.conf import settings
+title = _('Preferences')
+?>
+<html xmlns="http://www.w3.org/1999/xhtml"
+      xmlns:xi="http://www.w3.org/2001/XInclude"
+      xmlns:py="http://genshi.edgewall.org/">
+<xi:include href="master.xhtml"/>
+<head>
+  <title>${title}</title>
+</head>
+<body>
+<h1>${title}</h1>
+<h2>Preferred Language</h2>
+<form action="../i18n/setlang/" method="post">
+<input name="next" type="hidden" value="/syrup/" />
+<select name="language">
+<option py:for="code,descr in settings.LANGUAGES"
+       value="${code}">${_(descr)}</option>
+</select> <input type="submit" value="Change" />
+</form>
+<div py:if="user.is_authenticated">
+  <h2>Notification preferences</h2>
+  <form action="." method="POST">
+    <input type="checkbox" name="wants_email_notices" id="id_wants_email_notices"
+          py:attrs="{'checked':user.get_profile().wants_email_notices or None}"/>
+    <label for="id_wants_email_notices">I would like to receive emails when new items are added to my course sites.</label>
+    <p><input type="submit" value="Update notification preferences"/></p>
+  </form>
+</div>
+</body>
+</html>
diff --git a/conifer/templates/setlang.xhtml b/conifer/templates/setlang.xhtml
deleted file mode 100644 (file)
index d9d63b8..0000000
+++ /dev/null
@@ -1,23 +0,0 @@
-<?python
-from django.conf import settings
-title = _('Choose your language.')
-?>
-<html xmlns="http://www.w3.org/1999/xhtml"
-      xmlns:xi="http://www.w3.org/2001/XInclude"
-      xmlns:py="http://genshi.edgewall.org/">
-<xi:include href="master.xhtml"/>
-<head>
-  <title>${title}</title>
-</head>
-<body>
-<h1>${title}</h1>
-<form action="i18n/setlang/" method="post">
-<input name="next" type="hidden" value="/syrup/" />
-<select name="language">
-<option py:for="code,descr in settings.LANGUAGES"
-       value="${code}">${_(descr)}</option>
-</select>
-<input type="submit" value="Go" />
-</form>
-</body>
-</html>