Refinements on default values for new objects

svn: r19664
This commit is contained in:
Doug Blank 2012-05-26 20:56:27 +00:00
parent 0ba29c2d8b
commit b206ade3d3
15 changed files with 73 additions and 39 deletions

View File

@ -7,6 +7,7 @@
$(function(){
$('#tabs').tabs();
$('#general-tabs').tabs();
});
</script>
@ -77,7 +78,7 @@
<hr>
<h2>Shared source information</h2>
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="tabs">
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="general-tabs">
<ul class="ui-tabs-nav ui-helper-reset ui-helper-clearfix ui-widget-header ui-corner-all">
<li class="ui-state-default ui-corner-top ui-tabs-selected ui-state-active"><a href="#tab-shared-general">General</a></li>
<li class="ui-corner-top ui-state-default"><a href="#tab-shared-notes">Notes</a></li>
@ -114,6 +115,7 @@
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-shared-notes">
{% note_table source user action "/note/add/source/%s" source.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-shared-gallery">
</div>

View File

@ -95,25 +95,25 @@
</ul>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom" id="tab-children">
<!-- Events -->
{% children_table family user action "/family/%s/children" family.handle %}
{% children_table family user action "/family/%s/add/child" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-events">
{% event_table family user action "/family/%s/children" family.handle %}
{% event_table family user action "/event/add/family/%s" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources">
{% source_table family user action "/family/%s/children" family.handle %}
{% source_table family user action "/source/add/family/%s" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-attributes">
{% attribute_table family user action "/family/%s/children" family.handle %}
{% attribute_table family user action "/attribute/add/family/%s" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-notes">
{% note_table family user action "/family/%s/children" family.handle %}
{% note_table family user action "/note/add/family/%s" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-gallery">
{% gallery_table family user action "/family/%s/children" family.handle %}
{% gallery_table family user action "/media/add/family/%s" family.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-lds">
{% lds_table family user action "/family/%s/children" family.handle %}
{% lds_table family user action "/lds/add/family/%s" family.handle %}
</div>
</div>

View File

@ -102,7 +102,7 @@
{% citation_table person user action "/citation/add/person/%s" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-attributes">
{% attribute_table person user action "/person/%s/attribute" person.handle %}
{% attribute_table person user action "/attribute/add/person/%s" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-addresses">
{% address_table person user action "/place/add/person/%s" person.handle %}
@ -115,13 +115,13 @@
{% gallery_table person user action "/media/add/person/%s" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-internet">
{% internet_table person user action "/person/%s/internet" person.handle %}
{% internet_table person user action "/person/%s/add/internet" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-association">
{% association_table person user action "/person/%s/association" person.handle %}
{% association_table person user action "/person/%s/add/association" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-lds">
{% lds_table person user action "/person/%s/lds" person.handle %}
{% lds_table person user action "/person/%s/add/lds" person.handle %}
</div>
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-references">
{% reference_table person user action "/reference/add/person/%s" person.handle %}

View File

@ -382,6 +382,9 @@ class Config(models.Model):
value_type = models.CharField('type of value', max_length=25)
value = models.TextField('value')
def __unicode__(self):
return str(self.setting)
class Tag(models.Model):
handle = models.CharField(max_length=19, unique=True)
gramps_id = models.TextField(blank=True, null=True)
@ -511,6 +514,9 @@ class Source(PrimaryObject):
pubinfo = models.CharField("Pub. info.", max_length=50, blank=True, null=True)
abbrev = models.CharField("Abbreviation", max_length=50, blank=True, null=True)
def __unicode__(self):
return str(self.title)
# Other keys here:
# .datamap_set
@ -522,6 +528,9 @@ class Event(DateObject, PrimaryObject):
content_type_field="object_type",
object_id_field="object_id")
def __unicode__(self):
return str(self.description)
class Repository(PrimaryObject):
repository_type = models.ForeignKey('RepositoryType', verbose_name="Type")
name = models.TextField(blank=True)
@ -531,6 +540,9 @@ class Repository(PrimaryObject):
object_id_field="object_id")
#url_list = models.ManyToManyField('Url', null=True, blank=True)
def __unicode__(self):
return str(self.name)
# Others keys here:
# .address_set
# .url_set
@ -542,6 +554,9 @@ class Place(PrimaryObject):
lat = models.TextField(blank=True)
#url_list = models.ManyToManyField('Url', null=True, blank=True)
def __unicode__(self):
return str(self.title)
# Others keys here:
# .url_set
# .location_set
@ -558,6 +573,9 @@ class Media(DateObject, PrimaryObject):
def make_tag_list(self):
return tuple()
def __unicode__(self):
return str(self.desc)
class Note(PrimaryObject):
note_type = models.ForeignKey('NoteType', verbose_name="Type")
text = models.TextField(blank=True)
@ -570,6 +588,9 @@ class Note(PrimaryObject):
def make_tag_list(self):
return tuple()
def __unicode__(self):
return str(self.gramps_id)
#---------------------------------------------------------------------------
#
# Secondary Tables

View File

@ -50,10 +50,10 @@ def process_citation(request, context, handle, action, add_to=None): # view, edi
# Handle: edit, view, add, create, save, delete
if action == "add":
source = Source()
source = Source(gramps_id=dji.get_next_id(Source, "S"))
sourceform = SourceForm(instance=source)
sourceform.model = source
citation = Citation(source=source)
citation = Citation(source=source, gramps_id=dji.get_next_id(Citation, "C"))
citationform = CitationForm(instance=citation)
citationform.model = citation
elif action in ["view", "edit"]:

View File

@ -53,7 +53,7 @@ def process_event(request, context, handle, action, add_to=None): # view, edit,
# Handle: edit, view, add, create, save, delete
if action == "add":
event = Event()
event = Event(gramps_id=dji.get_next_id(Event, "E"))
eventform = EventForm(instance=event)
eventform.model = event
elif action in ["view", "edit"]:

View File

@ -50,6 +50,7 @@ def process_family(request, context, handle, action, add_to=None): # view, edit,
# Handle: edit, view, add, create, save, delete
if action == "add":
family = Family(
gramps_id=dji.get_next_id(Family, "F"),
family_rel_type=FamilyRelType.objects.get(
val=FamilyRelType._DEFAULT[0]))
familyform = FamilyForm(instance=family)

View File

@ -50,7 +50,7 @@ def process_media(request, context, handle, action, add_to=None): # view, edit,
# Handle: edit, view, add, create, save, delete
if action == "add":
media = Media()
media = Media(gramps_id=dji.get_next_id(Media, "M"))
mediaform = MediaForm(instance=media)
mediaform.model = media
elif action in ["view", "edit"]:

View File

@ -50,7 +50,7 @@ def process_note(request, context, handle, action, add_to=None): # view, edit, s
# Handle: edit, view, add, create, save, delete
if action == "add":
note = Note()
note = Note(gramps_id=dji.get_next_id(Note, "N"))
noteform = NoteForm(instance=note)
noteform.model = note
elif action in ["view", "edit"]:

View File

@ -28,6 +28,7 @@ from webapp.grampsdb.forms import *
from webapp.libdjango import DjangoInterface
## Django Modules
from django.http import Http404
from django.shortcuts import get_object_or_404, render_to_response, redirect
from django.template import Context, RequestContext
@ -273,9 +274,7 @@ def process_name(request, handle, order, action="view"):
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
surname.primary = True # FIXME: why is this False?
surname.save()
# FIXME: last_saved, last_changed, last_changed_by
dji.rebuild_cache(person)
# FIXME: update probably_alive
return redirect("/person/%s/name/%s" % (person.handle, name.order))
else:
action = "add"
@ -309,9 +308,7 @@ def process_name(request, handle, order, action="view"):
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
surname.primary = True # FIXME: why is this False?
surname.save()
# FIXME: last_saved, last_changed, last_changed_by
dji.rebuild_cache(person)
# FIXME: update probably_alive
return redirect("/person/%s/name/%s" % (person.handle, name.order))
else:
action = "edit"
@ -387,7 +384,6 @@ def process_person(request, context, handle, action, add_to=None): # view, edit,
surname.prefix = sf.cleaned_data["prefix"] if sf.cleaned_data["prefix"] != " prefix " else ""
surname.primary = True # FIXME: why is this False?
surname.save()
# FIXME: last_saved, last_changed, last_changed_by
dji.rebuild_cache(person)
# FIXME: update probably_alive
if add_to:
@ -430,8 +426,7 @@ def get_person_forms(handle, protect=False, empty=False, order=None):
if handle:
person = Person.objects.get(handle=handle)
else:
person = Person()
#person.gramps_id = "I0000" # FIXME: get next ID
person = Person(gramps_id=dji.get_next_id(Person, "I"))
## get a name
name = None
if order is not None:

View File

@ -50,7 +50,7 @@ def process_place(request, context, handle, action, add_to=None): # view, edit,
# Handle: edit, view, add, create, save, delete
if action == "add":
place = Place()
place = Place(gramps_id=dji.get_next_id(Place, "P"))
placeform = PlaceForm(instance=place)
placeform.model = place
elif action in ["view", "edit"]:

View File

@ -50,7 +50,7 @@ def process_repository(request, context, handle, action, add_to=None): # view, e
# Handle: edit, view, add, create, save, delete
if action == "add":
repository = Repository()
repository = Repository(gramps_id=dji.get_next_id(Repository, "R"))
repositoryform = RepositoryForm(instance=repository)
repositoryform.model = repository
elif action in ["view", "edit"]:

View File

@ -50,7 +50,7 @@ def process_source(request, context, handle, action, add_to=None): # view, edit,
# Handle: edit, view, add, create, save, delete
if action == "add":
source = Source()
source = Source(gramps_id=dji.get_next_id(Source, "S"))
sourceform = SourceForm(instance=source)
sourceform.model = source
elif action in ["view", "edit"]:

View File

@ -145,6 +145,21 @@ class DjangoInterface(object):
else:
raise AttributeError("no such model: '%s'" % name)
def get_next_id(self, obj, prefix):
"""
Get next gramps_id
>>> dji.get_next_id(Person, "P")
'P0002'
>>> dji.get_next_id(Media, "M")
'M2349'
"""
ids = [o["gramps_id"] for o in obj.objects.values("gramps_id")]
count = 1
while "%s%04d" % (prefix, count) in ids:
count += 1
return "%s%04d" % (prefix, count)
def get_model(self, name):
if hasattr(models, name.title()):
return getattr(models, name.title())

View File

@ -243,7 +243,7 @@ def event_table(obj, user, action, url=None, *args):
str(event_ref.role_type))
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add event"), (url + "/add") % args)
retval += make_button(_("Add event"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -281,7 +281,7 @@ def name_table(obj, user, action, url=None, *args):
table.links(links)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add name"), (url + "/add") % args)
retval += make_button(_("Add name"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -309,7 +309,7 @@ def surname_table(obj, user, action, url=None, *args):
else:
retval += "<p id='error'>No such name order = %s</p>" % order
if user.is_superuser and url and action == "view":
retval += make_button(_("Add surname"), (url + "/add") % args)
retval += make_button(_("Add surname"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -336,7 +336,7 @@ def source_table(obj, user, action, url=None, *args):
)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add source"), (url + "/add") % args)
retval += make_button(_("Add source"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -361,7 +361,7 @@ def citation_table(obj, user, action, url=None, *args):
)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add citation"), (url + "/add") % args)
retval += make_button(_("Add citation"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -405,7 +405,7 @@ def attribute_table(obj, user, action, url=None, *args):
attribute.value)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add attribute"), (url + "/add") % args)
retval += make_button(_("Add attribute"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -429,7 +429,7 @@ def address_table(obj, user, action, url=None, *args):
location.country)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add address"), (url + "/add") % args)
retval += make_button(_("Add address"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -442,7 +442,7 @@ def gallery_table(obj, user, action, url=None, *args):
)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add gallery"), (url + "/add") % args)
retval += make_button(_("Add gallery"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -461,7 +461,7 @@ def internet_table(obj, user, action, url=None, *args):
url_obj.desc)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add internet"), ((str(url) % args) + "/add"))
retval += make_button(_("Add internet"), (str(url) % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -480,7 +480,7 @@ def association_table(obj, user, action, url=None, *args):
table.row()
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add association"), (url + "/add") % args)
retval += make_button(_("Add association"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -504,7 +504,7 @@ def lds_table(obj, user, action, url=None, *args):
get_title(lds.place))
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add LDS"), (url + "/add") % args)
retval += make_button(_("Add LDS"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval
@ -570,7 +570,7 @@ def children_table(obj, user, action, url=None, *args):
table.links(links)
retval += table.get_html()
if user.is_superuser and url and action == "view":
retval += make_button(_("Add child"), (url + "/child/add") % args)
retval += make_button(_("Add child"), (url % args))
else:
retval += nbsp("") # to keep tabs same height
return retval