From c7e3234bad9c0cb157e055f05e248f61d9991283 Mon Sep 17 00:00:00 2001 From: Doug Blank Date: Tue, 6 Dec 2011 13:52:06 +0000 Subject: [PATCH] Updating to Django 1.3; begin update to Gramps DB version 16 svn: r18553 --- src/webapp/grampsdb/models.py | 31 +++++++++++++-------- src/webapp/grampsdb/templatetags/my_tags.py | 14 ++++++---- src/webapp/grampsdb/views.py | 2 +- src/webapp/settings.py | 6 ++++ src/webapp/urls.py | 2 +- src/webapp/utils.py | 6 ++-- 6 files changed, 41 insertions(+), 20 deletions(-) diff --git a/src/webapp/grampsdb/models.py b/src/webapp/grampsdb/models.py index 577cc5223..7d34af8a9 100644 --- a/src/webapp/grampsdb/models.py +++ b/src/webapp/grampsdb/models.py @@ -487,13 +487,26 @@ class Family(PrimaryObject): mother = self.mother.get_primary_name() if self.mother else "No mother" return str("%s and %s" % (father, mother)) +class Citation(PrimaryObject): + confidence = models.IntegerField(blank=True) + page = models.CharField(max_length=50, blank=True) + abbrev = models.CharField(max_length=50, blank=True) + #source = models.ForeignKey('Source') + source = generic.GenericForeignKey("object_type", "object_id") + + def __unicode__(self): + return "Citation to " + str(self.source) + + # Other keys here: + # .datamap_set + class Source(PrimaryObject): title = models.CharField(max_length=50, blank=True) author = models.CharField(max_length=50, blank=True) pubinfo = models.CharField(max_length=50, blank=True) abbrev = models.CharField(max_length=50, blank=True) #datamaps = models.ManyToManyField('Datamap', null=True, blank=True) - references = generic.GenericRelation('SourceRef', related_name="refs", + references = generic.GenericRelation('Citation', related_name="citation", content_type_field="object_type", object_id_field="object_id") # Other keys here: @@ -688,9 +701,13 @@ class Markup(models.Model): class Datamap(models.Model): key = models.CharField(max_length=80, blank=True) value = models.CharField(max_length=80, blank=True) - source = models.ForeignKey("Source", null=True, blank=True) +class CitationDatamap(models.Model): + key = models.CharField(max_length=80, blank=True) + value = models.CharField(max_length=80, blank=True) + source = models.ForeignKey("Citation", null=True, blank=True) + class Address(DateObject, SecondaryObject): #locations = models.ManyToManyField('Location', null=True) person = models.ForeignKey('Person', null=True, blank=True) @@ -765,14 +782,6 @@ class NoteRef(BaseRef): def __unicode__(self): return "NoteRef to " + str(self.ref_object) -class SourceRef(DateObject, BaseRef): - ref_object = models.ForeignKey('Source') - page = models.CharField(max_length=50) - confidence = models.IntegerField() - - def __unicode__(self): - return "SourceRef to " + str(self.ref_object) - class EventRef(BaseRef): ref_object = models.ForeignKey('Event') role_type = models.ForeignKey('EventRoleType') @@ -856,6 +865,7 @@ TABLES = [ ("abstract", PrimaryObject), ("primary", Person), ("primary", Family), + ("primary", Citation), ("primary", Source), ("primary", Event), ("primary", Repository), @@ -874,7 +884,6 @@ TABLES = [ ("secondary", Url), ("abstract", BaseRef), ("ref", NoteRef), - ("ref", SourceRef), ("ref", EventRef), ("ref", RepositoryRef), ("ref", PersonRef), diff --git a/src/webapp/grampsdb/templatetags/my_tags.py b/src/webapp/grampsdb/templatetags/my_tags.py index 51bef1b5f..b76392804 100644 --- a/src/webapp/grampsdb/templatetags/my_tags.py +++ b/src/webapp/grampsdb/templatetags/my_tags.py @@ -24,12 +24,14 @@ import re from django import template -from django.template import escape, Library +from django.template import Library from django.utils.safestring import mark_safe from webapp.utils import * from webapp.grampsdb.views import VIEWS import webapp.utils +#escape = lambda text: text + register = Library() def eval_template_exp(item, context): @@ -105,8 +107,9 @@ register.filter('person_get_events', person_get_event) def preview(text, width=40): text = text.replace("\n", " ") - return escape(text[:width]) -preview.is_safe = True + #return escape(text[:width]) + return text +#preview.is_safe = True register.filter('preview', preview) make_name.is_safe = True @@ -124,8 +127,9 @@ register.filter('preferred', preferred) def missing(data): if data.strip() == "": return "[Missing]" - return escape(data) -missing.is_safe = True + #return escape(data) + return data +#missing.is_safe = True register.filter('missing', missing) def getViewName(item): diff --git a/src/webapp/grampsdb/views.py b/src/webapp/grampsdb/views.py index c79516630..9c120422c 100644 --- a/src/webapp/grampsdb/views.py +++ b/src/webapp/grampsdb/views.py @@ -33,7 +33,7 @@ from django.contrib.auth.models import User from django.core.paginator import Paginator, InvalidPage, EmptyPage from django.http import Http404, HttpResponseRedirect, HttpResponse from django.shortcuts import get_object_or_404, render_to_response, redirect -from django.template import Context, RequestContext, escape +from django.template import Context, RequestContext from django.db.models import Q #------------------------------------------------------------------------ diff --git a/src/webapp/settings.py b/src/webapp/settings.py index 7541c69bc..eb83914f3 100644 --- a/src/webapp/settings.py +++ b/src/webapp/settings.py @@ -130,6 +130,12 @@ CACHE_BACKEND = 'locmem://' TRANSACTIONS_MANAGED = False LOCALE_PATHS = tuple() +# Changes for Django 1.3: +CACHES = {} +USE_L10N = True +FORMAT_MODULE_PATH = "" +## End Changes for Django 1.3 + # In versions < 2.7 python does not properly copy methods when doing a # deepcopy. This workaround makes the copy work properly. When Gramps no longer # supports python 2.6, this workaround can be removed. diff --git a/src/webapp/urls.py b/src/webapp/urls.py index 886a8cc75..1d385a3ef 100644 --- a/src/webapp/urls.py +++ b/src/webapp/urls.py @@ -44,7 +44,7 @@ from webapp.grampsdb.views import (main_page, user_page, logout_page, urlpatterns = patterns('', # Specific matches first: - (r'^admin/(.*)', admin.site.root), + url(r'^admin/', include(admin.site.urls)), ) urlpatterns += patterns('', diff --git a/src/webapp/utils.py b/src/webapp/utils.py index 368487aa2..e9ea5579b 100644 --- a/src/webapp/utils.py +++ b/src/webapp/utils.py @@ -34,7 +34,6 @@ import sys # Django Modules # #------------------------------------------------------------------------ -from django.template import escape from django.utils.safestring import mark_safe from django.contrib.contenttypes.models import ContentType @@ -127,7 +126,10 @@ def probably_alive(handle): def format_number(number, with_grouping=True): # FIXME: should be user's setting locale.setlocale(locale.LC_ALL, "en_US.utf8") - return locale.format("%d", number, with_grouping) + if number != "": + return locale.format("%d", number, with_grouping) + else: + return locale.format("%d", 0, with_grouping) def nbsp(string): """