[open-ils-commits] r208 - in servres/trunk/conifer: syrup templates (gfawcett)

svn at svn.open-ils.org svn at svn.open-ils.org
Thu Mar 19 22:47:10 EDT 2009


Author: gfawcett
Date: 2009-03-19 22:47:08 -0400 (Thu, 19 Mar 2009)
New Revision: 208

Added:
   servres/trunk/conifer/templates/prefs.xhtml
Removed:
   servres/trunk/conifer/templates/setlang.xhtml
Modified:
   servres/trunk/conifer/syrup/admin.py
   servres/trunk/conifer/syrup/models.py
   servres/trunk/conifer/syrup/views.py
Log:
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.

Modified: servres/trunk/conifer/syrup/admin.py
===================================================================
--- servres/trunk/conifer/syrup/admin.py	2009-03-20 02:05:16 UTC (rev 207)
+++ servres/trunk/conifer/syrup/admin.py	2009-03-20 02:47:08 UTC (rev 208)
@@ -3,25 +3,8 @@
 
 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]:
     admin.site.register(m)

Modified: servres/trunk/conifer/syrup/models.py
===================================================================
--- servres/trunk/conifer/syrup/models.py	2009-03-20 02:05:16 UTC (rev 207)
+++ servres/trunk/conifer/syrup/models.py	2009-03-20 02:47:08 UTC (rev 208)
@@ -4,7 +4,7 @@
 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 @@
     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
 

Modified: servres/trunk/conifer/syrup/views.py
===================================================================
--- servres/trunk/conifer/syrup/views.py	2009-03-20 02:05:16 UTC (rev 207)
+++ servres/trunk/conifer/syrup/views.py	2009-03-20 02:47:08 UTC (rev 208)
@@ -19,7 +19,7 @@
 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 @@
                     _('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 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 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)

Added: servres/trunk/conifer/templates/prefs.xhtml
===================================================================
--- servres/trunk/conifer/templates/prefs.xhtml	                        (rev 0)
+++ servres/trunk/conifer/templates/prefs.xhtml	2009-03-20 02:47:08 UTC (rev 208)
@@ -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>

Deleted: servres/trunk/conifer/templates/setlang.xhtml
===================================================================
--- servres/trunk/conifer/templates/setlang.xhtml	2009-03-20 02:05:16 UTC (rev 207)
+++ servres/trunk/conifer/templates/setlang.xhtml	2009-03-20 02:47:08 UTC (rev 208)
@@ -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>



More information about the open-ils-commits mailing list