Coding Guidelines: relative and absolute imports, some fixes and shortenings

svn: r20496
This commit is contained in:
Benny Malengier 2012-10-03 07:39:26 +00:00
parent 809c60fd77
commit e6cd5b5d2d
10 changed files with 64 additions and 59 deletions

View File

@ -36,7 +36,7 @@ import sys
# Gramps Modules
#
#------------------------------------------------------------------------
import gramps.gen.user
from gramps.gen.user import User
#------------------------------------------------------------------------
#
@ -50,7 +50,7 @@ _SPINNER = ['|', '/', '-', '\\']
# User class
#
#-------------------------------------------------------------------------
class User(gramps.gen.user.User):
class User(User):
"""
This class provides a means to interact with the user via CLI.
It implements the interface in gramps.gen.user.User()

View File

@ -88,7 +88,7 @@ QUAL_TEXT = (
(Date.QUAL_ESTIMATED, _('Estimated')),
(Date.QUAL_CALCULATED, _('Calculated')) )
CAL_TO_MONTHS_NAMES = {
CAL_TO_MONTHS_NAMES = {
Date.CAL_GREGORIAN : displayer.short_months,
Date.CAL_JULIAN : displayer.short_months,
Date.CAL_HEBREW : displayer.hebrew,

View File

@ -45,7 +45,7 @@ from gramps.gui.dialog import (WarningDialog, ErrorDialog, DBErrorDialog,
# User class
#
#-------------------------------------------------------------------------
class User(gramps.gen.user.User):
class User(User):
"""
This class provides a means to interact with the user via GTK.
It implements the interface in gramps.gen.user.User()

View File

@ -56,15 +56,16 @@ from cgi import escape
from gramps.gen.db import DbTxn
from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.errors import WindowActiveError
from gramps.gui.editors import EditPerson, EditFamily
from gramps.gui.widgets.reorderfam import Reorder
from gramps.gen.lib import ChildRef, Family, Name, Person, Surname
from gramps.gui.utils import color_graph_box, hex_to_rgb, is_right_click
from gramps.gui.ddtargets import DdTargets
from gramps.gen.lib.date import Today
from ..editors import EditPerson, EditFamily
from .reorderfam import Reorder
from ..utils import color_graph_box, hex_to_rgb, is_right_click
from ..ddtargets import DdTargets
from gramps.gen.utils.alive import probably_alive
from gramps.gen.utils.libformatting import FormattingHelper
from gramps.gen.utils.db import (find_children, find_parents, find_witnessed_people,
get_age, get_timeperiod, preset_name)
get_age, get_timeperiod, preset_name)
#-------------------------------------------------------------------------
#
@ -364,7 +365,7 @@ class FanChartBaseWidget(Gtk.DrawingArea):
self.set_userdata_timeperiod(child, userdata)
#now create gradient data, 5 values from min to max rounded to nearest 50
if self.maxperiod < self.minperiod:
self.maxperiod = self.minperiod = gen.lib.date.Today().get_year()
self.maxperiod = self.minperiod = Today().get_year()
rper = self.maxperiod // 50
if rper * 50 != self.maxperiod:
self.maxperiod = rper * 50 + 50

View File

@ -55,15 +55,15 @@ from cgi import escape
#-------------------------------------------------------------------------
from gramps.gen.display.name import displayer as name_displayer
from gramps.gen.errors import WindowActiveError
from gramps.gui.editors import EditPerson, EditFamily
from gramps.gui.utils import hex_to_rgb
from gramps.gui.ddtargets import DdTargets
from ..editors import EditPerson, EditFamily
from ..utils import hex_to_rgb
from ..ddtargets import DdTargets
from gramps.gen.utils.alive import probably_alive
from gramps.gen.utils.libformatting import FormattingHelper
from gramps.gen.utils.db import (find_children, find_parents, find_witnessed_people,
get_age, get_timeperiod)
from gramps.gen.plug.report.utils import find_spouse
from gramps.gui.widgets.fanchart import *
from fanchart import *
#-------------------------------------------------------------------------
#

View File

@ -52,7 +52,7 @@ from gi.repository import Gdk
# Gramps Modules
#
#-------------------------------------------------------------------------
import constants
from gramps.plugins.lib.maps import constants
from dummylayer import DummyLayer
from dummynogps import DummyMapNoGpsPoint
from selectionlayer import SelectionLayer

View File

@ -56,7 +56,9 @@ from gi.repository import GObject
#
#------------------------------------------------------------------------
from gramps.gen.const import URL_MANUAL_PAGE, VERSION_DIR
from gramps.gen.lib import ChildRefType, EventRoleType, EventType, FamilyRelType, NameType, Person
from gramps.gen.lib import (ChildRefType, EventRoleType, EventType,
FamilyRelType, NameType, Person)
from gramps.gen.lib.date import Today
from gramps.gui.editors import EditPerson, EditFamily
from gramps.gen.utils.db import family_name
from gramps.gui.display import display_help
@ -82,7 +84,7 @@ WIKI_HELP_SEC = _('manual|Verify_the_Data...')
_person_cache = {}
_family_cache = {}
_event_cache = {}
_today = gen.lib.date.Today().get_sort_value()
_today = Today().get_sort_value()
def find_event(db, handle):
if handle in _event_cache:

View File

@ -77,8 +77,10 @@ log = logging.getLogger(".NarrativeWeb")
# GRAMPS module
#------------------------------------------------
from gramps.gen.ggettext import sgettext as _
from gramps.gen.lib import ChildRefType, Date, EventType, FamilyRelType, Name, NameType, Person
from gramps.gen.lib import UrlType, date, NoteType, EventRoleType
from gramps.gen.lib import (ChildRefType, Date, EventType, FamilyRelType, Name,
NameType, Person, UrlType, NoteType,
EventRoleType)
from gramps.gen.lib.date import Today, get_start_day
from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION
from gramps.gen.sort import Sort
from gramps.gen.plug.menu import PersonOption, NumberOption, StringOption, \
@ -1385,7 +1387,7 @@ class BasePage(object):
text = ''
if copyright == 0:
if self.author:
year = date.Today().get_year()
year = Today().get_year()
text = '&copy; %(year)d %(person)s' % {
'person' : self.author,
'year' : year}
@ -1499,7 +1501,7 @@ class BasePage(object):
msg = _('Generated by <a href = "%(homepage)s">'
'Gramps</a> %(version)s on %(date)s') % {
'date': _dd.display(date.Today()),
'date': _dd.display(Today()),
'homepage' : URL_HOMEPAGE,
'version': VERSION}
@ -1523,7 +1525,7 @@ class BasePage(object):
text = ''
if copy_nr == 0:
if self.author:
year = date.Today().get_year()
year = Today().get_year()
text = '&copy; %(year)d %(person)s' % {
'person' : self.author,
'year' : year}
@ -6123,7 +6125,7 @@ class IndividualPage(BasePage):
birth_date = birth.get_date_object()
if birth_date and birth_date is not Date.EMPTY:
alive = probably_alive(self.person, self.dbase_, date.Today() )
alive = probably_alive(self.person, self.dbase_, Today() )
death_date = _find_death_date(self.dbase_, self.person)
if not alive and death_date is not None:

View File

@ -50,6 +50,7 @@ log = logging.getLogger(".WebPage")
# GRAMPS module
#------------------------------------------------------------------------
from gramps.gen.lib import Date, Name, NameType, Person
from gramps.gen.lib.date import Today
from gramps.gen.const import PROGRAM_NAME, URL_HOMEPAGE, USER_HOME, VERSION
from gramps.gen.constfunc import win
from gramps.gen.plug.report import Report
@ -148,7 +149,7 @@ class WebCalReport(Report):
self.email = researcher.email
# set to today's date
self.today = gen.lib.date.Today()
self.today = Today()
self.warn_dir = True # Only give warning once.
@ -559,7 +560,7 @@ class WebCalReport(Report):
elif url_fname == 'fullyearlinked':
myTitle = _('Full year at a Glance')
else:
myTitle = _(url_fname)
myTitle = _(url_fname)
hyper = Html("a", nav_text, href = url, name = url_fname, title = myTitle)
if check_cs:
@ -1185,8 +1186,7 @@ class WebCalReport(Report):
# Display date as user set in preferences
msg = _('Generated by <a href="http://gramps-project.org">'
'Gramps</a> on %(date)s') % {'date' : _dd.display(
gen.lib.date.Today())}
'Gramps</a> on %(date)s') % {'date' : _dd.display(Today())}
footer += Html("p", msg, id = 'createdate')
copy_nr = self.copy
@ -1369,7 +1369,7 @@ class WebCalOptions(MenuReportOptions):
category_name = _("Content Options")
# set to today's date for use in menu, etc.
today = gen.lib.date.Today()
today = Today()
self.__multiyear = BooleanOption(_('Create multiple year calendars'), False)
self.__multiyear.set_help(_('Whether to create Multiple year calendars or not.'))

View File

@ -185,48 +185,48 @@ class DbDjango(DbWriteBase, DbReadBase):
# First we add the primary objects:
for key in self.import_cache.keys():
obj = self.import_cache[key]
if isinstance(obj, gen.lib.Person):
if isinstance(obj, Person):
self.dji.add_person(obj.serialize())
elif isinstance(obj, gen.lib.Family):
elif isinstance(obj, Family):
self.dji.add_family(obj.serialize())
elif isinstance(obj, gen.lib.Event):
elif isinstance(obj, Event):
self.dji.add_event(obj.serialize())
elif isinstance(obj, gen.lib.Place):
elif isinstance(obj, Place):
self.dji.add_place(obj.serialize())
elif isinstance(obj, gen.lib.Repository):
elif isinstance(obj, Repository):
self.dji.add_repository(obj.serialize())
elif isinstance(obj, gen.lib.Citation):
elif isinstance(obj, Citation):
self.dji.add_citation(obj.serialize())
elif isinstance(obj, gen.lib.Source):
elif isinstance(obj, Source):
self.dji.add_source(obj.serialize())
elif isinstance(obj, gen.lib.Note):
elif isinstance(obj, Note):
self.dji.add_note(obj.serialize())
elif isinstance(obj, gen.lib.MediaObject):
elif isinstance(obj, MediaObject):
self.dji.add_media(obj.serialize())
elif isinstance(obj, gen.lib.Tag):
elif isinstance(obj, Tag):
self.dji.add_tag(obj.serialize())
# Next we add the links:
for key in self.import_cache.keys():
obj = self.import_cache[key]
if isinstance(obj, gen.lib.Person):
if isinstance(obj, Person):
self.dji.add_person_detail(obj.serialize())
elif isinstance(obj, gen.lib.Family):
elif isinstance(obj, Family):
self.dji.add_family_detail(obj.serialize())
elif isinstance(obj, gen.lib.Event):
elif isinstance(obj, Event):
self.dji.add_event_detail(obj.serialize())
elif isinstance(obj, gen.lib.Place):
elif isinstance(obj, Place):
self.dji.add_place_detail(obj.serialize())
elif isinstance(obj, gen.lib.Repository):
elif isinstance(obj, Repository):
self.dji.add_repository_detail(obj.serialize())
elif isinstance(obj, gen.lib.Citation):
elif isinstance(obj, Citation):
self.dji.add_citation_detail(obj.serialize())
elif isinstance(obj, gen.lib.Source):
elif isinstance(obj, Source):
self.dji.add_source_detail(obj.serialize())
elif isinstance(obj, gen.lib.Note):
elif isinstance(obj, Note):
self.dji.add_note_detail(obj.serialize())
elif isinstance(obj, gen.lib.MediaObject):
elif isinstance(obj, MediaObject):
self.dji.add_media_detail(obj.serialize())
elif isinstance(obj, gen.lib.Tag):
elif isinstance(obj, Tag):
self.dji.add_tag_detail(obj.serialize())
self.use_import_cache = False
self.import_cache = {}
@ -495,7 +495,7 @@ class DbDjango(DbWriteBase, DbReadBase):
return None
def get_researcher(self):
obj = gen.lib.Researcher()
obj = Researcher()
return obj
def get_tag_handles(self, sort_handles=False):
@ -619,67 +619,67 @@ class DbDjango(DbWriteBase, DbReadBase):
data = cPickle.loads(base64.decodestring(repository.cache))
else:
data = self.dji.get_repository(repository)
return gen.lib.Repository.create(data)
return Repository.create(data)
def make_citation(self, citation):
if self.use_db_cache and citation.cache:
data = cPickle.loads(base64.decodestring(citation.cache))
else:
data = self.dji.get_citation(citation)
return gen.lib.Citation.create(data)
return Citation.create(data)
def make_source(self, source):
if self.use_db_cache and source.cache:
data = cPickle.loads(base64.decodestring(source.cache))
else:
data = self.dji.get_source(source)
return gen.lib.Source.create(data)
return Source.create(data)
def make_family(self, family):
if self.use_db_cache and family.cache:
data = cPickle.loads(base64.decodestring(family.cache))
else:
data = self.dji.get_family(family)
return gen.lib.Family.create(data)
return Family.create(data)
def make_person(self, person):
if self.use_db_cache and person.cache:
data = cPickle.loads(base64.decodestring(person.cache))
else:
data = self.dji.get_person(person)
return gen.lib.Person.create(data)
return Person.create(data)
def make_event(self, event):
if self.use_db_cache and event.cache:
data = cPickle.loads(base64.decodestring(event.cache))
else:
data = self.dji.get_event(event)
return gen.lib.Event.create(data)
return Event.create(data)
def make_note(self, note):
if self.use_db_cache and note.cache:
data = cPickle.loads(base64.decodestring(note.cache))
else:
data = self.dji.get_note(note)
return gen.lib.Note.create(data)
return Note.create(data)
def make_tag(self, tag):
data = self.dji.get_tag(tag)
return gen.lib.Tag.create(data)
return Tag.create(data)
def make_place(self, place):
if self.use_db_cache and place.cache:
data = cPickle.loads(base64.decodestring(place.cache))
else:
data = self.dji.get_place(place)
return gen.lib.Place.create(data)
return Place.create(data)
def make_media(self, media):
if self.use_db_cache and media.cache:
data = cPickle.loads(base64.decodestring(media.cache))
else:
data = self.dji.get_media(media)
return gen.lib.MediaObject.create(data)
return MediaObject.create(data)
def get_place_from_handle(self, handle):
if handle in self.import_cache: