diff --git a/src/web/grampsdb/admin.py b/src/web/grampsdb/admin.py index ee2502975..a947ac0cc 100644 --- a/src/web/grampsdb/admin.py +++ b/src/web/grampsdb/admin.py @@ -4,3 +4,4 @@ from django.contrib import admin for type_name in get_tables("all"): admin.site.register(type_name[1]) +admin.site.register(Profile) diff --git a/src/web/grampsdb/fixtures/initial_data.json b/src/web/grampsdb/fixtures/initial_data.json index 234b2e572..7ec73bab3 100644 --- a/src/web/grampsdb/fixtures/initial_data.json +++ b/src/web/grampsdb/fixtures/initial_data.json @@ -18,7 +18,7 @@ "setting" : "db_created" , "description" : "database creation date/time" , "value_type" : "str" , - "value" : "2010-01-01 10:12" + "value" : "2010-01-02 11:30" } }, { diff --git a/src/web/grampsdb/models.py b/src/web/grampsdb/models.py index 8b97b54f0..c6e3dbf0c 100644 --- a/src/web/grampsdb/models.py +++ b/src/web/grampsdb/models.py @@ -36,6 +36,8 @@ from django.contrib.contenttypes import generic from gen.lib.date import Date as GDate, Today from Utils import create_id, create_uid +from web.grampsdb.profile import Profile + #--------------------------------------------------------------------------- # # Support functions @@ -290,7 +292,21 @@ class DateNewYearType(mGrampsType): _DEFAULT = _DATAMAP[NEWYEAR_JAN1] val = models.IntegerField('New Year start date', choices=_DATAMAP, blank=False) - + +class ThemeType(mGrampsType): + _DATAMAP = list(enumerate(["Web_Mainz.css", + "Web_Basic-Ash.css", + "Web_Basic-Cypress.css", + "Web_Nebraska.css", + "Web_Basic-Lilac.css", + "Web_Print-Default.css", + "Web_Basic-Peach.css", + "Web_Visually.css", + "Web_Basic-Spruce.css",])) + + _DEFAULT = _DATAMAP[0] + val = models.IntegerField('Theme', choices=_DATAMAP, blank=False) + #--------------------------------------------------------------------------- # # Support definitions @@ -737,6 +753,7 @@ TABLES = [ ("type", GenderType), ("type", LdsType), ("type", LdsStatus), + ("type", ThemeType), ("abstract", DateObject), ("meta", Config), ("abstract", PrimaryObject), diff --git a/src/web/grampsdb/profile.py b/src/web/grampsdb/profile.py new file mode 100644 index 000000000..8854639ff --- /dev/null +++ b/src/web/grampsdb/profile.py @@ -0,0 +1,48 @@ +# Gramps - a GTK+/GNOME based genealogy program +# +# Copyright (C) 2009 Douglas S. Blank +# +# This program is free software; you can redistribute it and/or modify +# it under the terms of the GNU General Public License as published by +# the Free Software Foundation; either version 2 of the License, or +# (at your option) any later version. +# +# This program is distributed in the hope that it will be useful, +# but WITHOUT ANY WARRANTY; without even the implied warranty of +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the +# GNU General Public License for more details. +# +# You should have received a copy of the GNU General Public License +# along with this program; if not, write to the Free Software +# Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +# +# $Id$ +# + +from django.db import models +from django.db.models.signals import post_save +from django.contrib.auth.models import User + +class Profile(models.Model): + """ + Used to save additional information of a user, such as + themes, bookmarks, etc. + """ + user = models.ForeignKey(User, unique=True) + css_theme = models.CharField(max_length=40, + default="Web_Mainz.css") + + def __unicode__(self): + return unicode(self.user) + +def save_profile(sender, instance, created, **kwargs): + """ + Creates the profile when the user gets created. + """ + if created: + profile = Profile(user=instance) + profile.save() + else: + print sender + +post_save.connect(save_profile, sender=User) diff --git a/src/web/grampsdb/views.py b/src/web/grampsdb/views.py index 670d0ab9a..ff2b46942 100644 --- a/src/web/grampsdb/views.py +++ b/src/web/grampsdb/views.py @@ -65,27 +65,19 @@ def context_processor(request): This function is executed before template processing. takes a request, and returns a dictionary context. """ - # FIXME: make the css_theme based on user's selection context = {} - context["css_theme"] = "Web_Mainz.css" - # FIXME: get the views from a config? + if request.user.is_authenticated(): + profile = request.user.get_profile() + context["css_theme"] = profile.css_theme + else: + context["css_theme"] = "Web_Mainz.css" + # Other things for all environments: context["views"] = VIEWS context["True"] = True context["False"] = False context["default"] = "" return context -# CSS Themes: -#Web_Basic-Ash.css -#Web_Mainz.css -#Web_Basic-Cypress.css -#Web_Nebraska.css -#Web_Basic-Lilac.css -#Web_Print-Default.css -#Web_Basic-Peach.css -#Web_Visually.css -#Web_Basic-Spruce.css - def main_page(request): context = RequestContext(request) context["view"] = 'home' diff --git a/src/web/init.py b/src/web/init.py index 0250b5fbd..7db2bbc01 100644 --- a/src/web/init.py +++ b/src/web/init.py @@ -43,7 +43,8 @@ from gen.lib.srcmediatype import SourceMediaType from gen.lib.eventroletype import EventRoleType from gen.lib.notetype import NoteType -from grampsdb.models import GenderType, LdsType, LdsStatus, NameFormatType +from grampsdb.models import (GenderType, LdsType, LdsStatus, + NameFormatType, ThemeType) def get_datamap(x): """ diff --git a/src/web/settings.py b/src/web/settings.py index d2c97aad6..012264397 100644 --- a/src/web/settings.py +++ b/src/web/settings.py @@ -111,6 +111,8 @@ DEBUG_TOOLBAR_CONFIG = { 'HIDE_DJANGO_SQL': False, } +AUTH_PROFILE_MODULE = "grampsdb.Profile" + # Had to add these to use settings.configure(): DATABASE_OPTIONS = '' URL_VALIDATOR_USER_AGENT = '' diff --git a/src/web/sqlite.db b/src/web/sqlite.db index 007a2a018..db8df5aa7 100644 Binary files a/src/web/sqlite.db and b/src/web/sqlite.db differ