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]:
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
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
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
_('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)
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))
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)
--- /dev/null
+<?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>
+++ /dev/null
-<?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>