Webapp: changes for web portion to use new Django interface

This commit is contained in:
Doug Blank 2015-08-21 17:24:14 -04:00
parent a93872a0f3
commit 4f4fe6c0de
7 changed files with 214 additions and 219 deletions

View File

@ -20,7 +20,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from gramps.webapp.utils import _, boolean, update_last_changed, build_search
from gramps.webapp.utils import _, boolean, update_last_changed, build_search, db
from gramps.webapp.grampsdb.models import Event, EventType, EventRef, EventRoleType, Person
from gramps.webapp.grampsdb.forms import *
from gramps.webapp.libdjango import DjangoInterface, lookup_role_index
@ -33,7 +33,6 @@ from django.template import Context, RequestContext
## Globals
dji = DjangoInterface()
db = DbDjango()
dd = displayer.display
dp = parser.parse

View File

@ -20,7 +20,7 @@
""" Views for Person, Name, and Surname """
## Gramps Modules
from gramps.webapp.utils import _, boolean, update_last_changed, StyledNoteFormatter, parse_styled_text, build_search
from gramps.webapp.utils import _, boolean, update_last_changed, StyledNoteFormatter, parse_styled_text, build_search, db
from gramps.webapp.grampsdb.models import Note
from gramps.webapp.grampsdb.forms import *
from gramps.webapp.libdjango import DjangoInterface
@ -32,7 +32,6 @@ from django.template import Context, RequestContext
## Globals
dji = DjangoInterface()
db = DbDjango()
snf = StyledNoteFormatter(db)
# add a note to a person:

View File

@ -57,7 +57,7 @@ from gramps.version import VERSION
# Gramps-connect imports:
import gramps.webapp
from gramps.webapp.utils import _, build_args
from gramps.webapp.utils import _, build_args, db
from gramps.webapp.grampsdb.models import *
from gramps.webapp.grampsdb.view import *
from gramps.webapp.djangodb import DbDjango
@ -196,7 +196,6 @@ def process_report_run(request, handle):
from gramps.webapp.reports import import_file, export_file, download
from gramps.cli.plug import run_report
import traceback
db = DbDjango()
if request.user.is_authenticated():
profile = request.user.profile
report = Report.objects.get(handle=handle)
@ -465,7 +464,6 @@ def action(request, view, handle, act, add_to=None):
/object/handle/action, or /object/add.
"""
from gramps.webapp.reports import get_plugin_options
db = DbDjango()
# redirect:
rd = None
obj = None
@ -1548,7 +1546,6 @@ def process_json_request(request):
"""
import gramps.gen.lib
from gramps.gen.proxy import PrivateProxyDb, LivingProxyDb
db = DbDjango()
if not request.user.is_authenticated():
db = PrivateProxyDb(db)
db = LivingProxyDb(db,

View File

@ -41,9 +41,8 @@
import os, sys
if __name__ == "__main__":
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gramps.webapp.settings")
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "gramps.webapp.default_settings")
from django.core.management import execute_from_command_line
execute_from_command_line(sys.argv)

View File

@ -58,7 +58,7 @@ with open(pystartup) as f:
exec(code, globals(), locals())
from django.conf import settings
import gramps.webapp.settings as default_settings
from gramps.webapp import default_settings
try:
settings.configure(default_settings)
except RuntimeError:
@ -82,7 +82,8 @@ from gramps.cli.user import User as GUser # gramps user
from django.db.models import Q
db = DbDjango()
dji = DjangoInterface()
db.load(os.path.abspath(os.path.dirname(__file__)))
dd = displayer.display
dp = parser.parse

View File

@ -25,6 +25,7 @@
#
#------------------------------------------------------------------------
import sys
import os
import re
import datetime
from html.parser import HTMLParser
@ -117,10 +118,10 @@ util_tags = [
# Module Constants
#
#------------------------------------------------------------------------
dji = libdjango.DjangoInterface()
dd = displayer.display
dp = parser.parse
db = DbDjango()
db.load(os.path.abspath(os.path.dirname(__file__)))
def register_plugins(user):
dbstate = DbState()
@ -199,7 +200,7 @@ class Table(object):
"""
def __init__(self, id, style=None):
self.id = id # css id
self.db = DbDjango()
self.db = db
self.access = SimpleAccess(self.db)
self.table = SimpleTable(self.access)
self.column_widths = None
@ -467,14 +468,14 @@ def name_table(obj, user, act, url=None, *args):
links = []
for name in obj.name_set.all().order_by("order"):
obj_type = ContentType.objects.get_for_model(name)
citationq = dji.CitationRef.filter(object_type=obj_type,
citationq = db.dji.CitationRef.filter(object_type=obj_type,
object_id=name.id).count() > 0
note_refs = dji.NoteRef.filter(object_type=obj_type,
note_refs = db.dji.NoteRef.filter(object_type=obj_type,
object_id=name.id)
note = ""
if note_refs.count() > 0:
try:
note = dji.Note.get(id=note_refs[0].object_id).text[:50]
note = db.dji.Note.get(id=note_refs[0].object_id).text[:50]
except:
note = None
table.row(make_name(name, user),
@ -542,7 +543,7 @@ def citation_table(obj, user, act, url=None, *args):
table.column_widths = [11, 10, 49, 30]
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
citation_refs = dji.CitationRef.filter(object_type=obj_type,
citation_refs = db.dji.CitationRef.filter(object_type=obj_type,
object_id=obj.id).order_by("order")
links = []
count = 1
@ -603,7 +604,7 @@ def repository_table(obj, user, act, url=None, *args):
retval += """</div>"""
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
refs = dji.RepositoryRef.filter(object_type=obj_type,
refs = db.dji.RepositoryRef.filter(object_type=obj_type,
object_id=obj.id)
count = 1
for repo_ref in refs:
@ -645,7 +646,7 @@ def note_table(obj, user, act, url=None, *args):
table.column_widths = [11, 10, 20, 59]
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
note_refs = dji.NoteRef.filter(object_type=obj_type,
note_refs = db.dji.NoteRef.filter(object_type=obj_type,
object_id=obj.id).order_by("order")
links = []
count = 1
@ -744,7 +745,7 @@ def attribute_table(obj, user, act, url=None, *args):
)
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
attributes = dji.Attribute.filter(object_type=obj_type,
attributes = db.dji.Attribute.filter(object_type=obj_type,
object_id=obj.id)
for attribute in attributes:
table.row(attribute.attribute_type.name,
@ -803,7 +804,7 @@ def media_table(obj, user, act, url=None, *args):
)
if user.is_authenticated() or obj.public:
obj_type = ContentType.objects.get_for_model(obj)
media_refs = dji.MediaRef.filter(object_type=obj_type,
media_refs = db.dji.MediaRef.filter(object_type=obj_type,
object_id=obj.id)
for media_ref in media_refs:
media = table.db.get_object_from_handle(
@ -833,7 +834,7 @@ def internet_table(obj, user, act, url=None, *args):
_("Path"),
_("Description"))
if user.is_authenticated() or obj.public:
urls = dji.Url.filter(person=obj)
urls = db.dji.Url.filter(person=obj)
for url_obj in urls:
table.row(str(url_obj.url_type),
url_obj.path,
@ -1264,7 +1265,7 @@ def children_table(obj, user, act, url=None, *args):
family = obj
obj_type = ContentType.objects.get_for_model(family)
childrefs = dji.ChildRef.filter(object_id=family.id,
childrefs = db.dji.ChildRef.filter(object_id=family.id,
object_type=obj_type).order_by("order")
links = []
count = 1
@ -1331,7 +1332,7 @@ def get_title(place):
return ""
def display_date(obj):
date_tuple = dji.get_date(obj)
date_tuple = db.dji.get_date(obj)
if date_tuple:
gdate = GDate()
gdate.unserialize(date_tuple)
@ -1446,7 +1447,7 @@ def date_as_text(obj, user):
"""
if user.is_authenticated() or (obj and obj.public):
if obj:
date_tuple = dji.get_date(obj)
date_tuple = db.dji.get_date(obj)
if date_tuple:
gdate = GDate().unserialize(date_tuple)
return dd(gdate)
@ -1455,7 +1456,7 @@ def date_as_text(obj, user):
return ""
def person_get_event(person, event_type=None):
event_ref_list = dji.get_event_ref_list(person)
event_ref_list = db.dji.get_event_ref_list(person)
if event_type:
index = libdjango.lookup_role_index(event_type, event_ref_list)
if index >= 0:
@ -1710,4 +1711,3 @@ def person_get_death_date(person):
#if event:
# return event.date
return None