Working on name editing with refactor
svn: r19610
This commit is contained in:
@@ -116,35 +116,35 @@ class NameType(mGrampsType):
|
||||
from gen.lib.nametype import NameType
|
||||
_DATAMAP = get_datamap(NameType)
|
||||
_CUSTOM = NameType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NameType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NameType._DEFAULT][0]
|
||||
val = models.IntegerField('name type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class NameOriginType(mGrampsType):
|
||||
from gen.lib.nameorigintype import NameOriginType
|
||||
_DATAMAP = get_datamap(NameOriginType)
|
||||
_CUSTOM = NameOriginType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NameOriginType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NameOriginType._DEFAULT][0]
|
||||
val = models.IntegerField('name origin type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class AttributeType(mGrampsType):
|
||||
from gen.lib.attrtype import AttributeType
|
||||
_DATAMAP = get_datamap(AttributeType)
|
||||
_CUSTOM = AttributeType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == AttributeType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == AttributeType._DEFAULT][0]
|
||||
val = models.IntegerField('attribute type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class UrlType(mGrampsType):
|
||||
from gen.lib.urltype import UrlType
|
||||
_DATAMAP = get_datamap(UrlType)
|
||||
_CUSTOM = UrlType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == UrlType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == UrlType._DEFAULT][0]
|
||||
val = models.IntegerField('url type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class ChildRefType(mGrampsType):
|
||||
from gen.lib.childreftype import ChildRefType
|
||||
_DATAMAP = get_datamap(ChildRefType)
|
||||
_CUSTOM = ChildRefType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == ChildRefType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == ChildRefType._DEFAULT][0]
|
||||
val = models.IntegerField('child reference type', choices=_DATAMAP,
|
||||
blank=False)
|
||||
|
||||
@@ -152,14 +152,14 @@ class RepositoryType(mGrampsType):
|
||||
from gen.lib.repotype import RepositoryType
|
||||
_DATAMAP = get_datamap(RepositoryType)
|
||||
_CUSTOM = RepositoryType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == RepositoryType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == RepositoryType._DEFAULT][0]
|
||||
val = models.IntegerField('repository type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class EventType(mGrampsType):
|
||||
from gen.lib.eventtype import EventType
|
||||
_DATAMAP = get_datamap(EventType)
|
||||
_CUSTOM = EventType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == EventType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == EventType._DEFAULT][0]
|
||||
BIRTH = 12
|
||||
DEATH = 13
|
||||
val = models.IntegerField('event type', choices=_DATAMAP, blank=False)
|
||||
@@ -168,7 +168,7 @@ class FamilyRelType(mGrampsType):
|
||||
from gen.lib.familyreltype import FamilyRelType
|
||||
_DATAMAP = get_datamap(FamilyRelType)
|
||||
_CUSTOM = FamilyRelType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == FamilyRelType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == FamilyRelType._DEFAULT][0]
|
||||
val = models.IntegerField('family relation type', choices=_DATAMAP,
|
||||
blank=False)
|
||||
|
||||
@@ -176,7 +176,7 @@ class SourceMediaType(mGrampsType):
|
||||
from gen.lib.srcmediatype import SourceMediaType
|
||||
_DATAMAP = get_datamap(SourceMediaType)
|
||||
_CUSTOM = SourceMediaType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == SourceMediaType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == SourceMediaType._DEFAULT][0]
|
||||
val = models.IntegerField('source medium type', choices=_DATAMAP,
|
||||
blank=False)
|
||||
|
||||
@@ -184,14 +184,14 @@ class EventRoleType(mGrampsType):
|
||||
from gen.lib.eventroletype import EventRoleType
|
||||
_DATAMAP = get_datamap(EventRoleType)
|
||||
_CUSTOM = EventRoleType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == EventRoleType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == EventRoleType._DEFAULT][0]
|
||||
val = models.IntegerField('event role type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class NoteType(mGrampsType):
|
||||
from gen.lib.notetype import NoteType
|
||||
_DATAMAP = get_datamap(NoteType)
|
||||
_CUSTOM = NoteType._CUSTOM
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NoteType._DEFAULT]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NoteType._DEFAULT][0]
|
||||
val = models.IntegerField('note type', choices=_DATAMAP, blank=False)
|
||||
|
||||
class MarkupType(mGrampsType):
|
||||
@@ -258,7 +258,7 @@ class CalendarType(mGrampsType):
|
||||
(CAL_ISLAMIC, "Islamic"),
|
||||
(CAL_SWEDISH, "Swedish")]
|
||||
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == CAL_GREGORIAN]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == CAL_GREGORIAN][0]
|
||||
val = models.IntegerField('Calendar', choices=_DATAMAP, blank=False)
|
||||
|
||||
class DateModifierType(mGrampsType):
|
||||
@@ -278,7 +278,7 @@ class DateModifierType(mGrampsType):
|
||||
(MOD_SPAN, "Span"),
|
||||
(MOD_TEXTONLY, "Text only")]
|
||||
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == MOD_NONE]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == MOD_NONE][0]
|
||||
val = models.IntegerField('Date modifier', choices=_DATAMAP, blank=False)
|
||||
|
||||
class DateNewYearType(mGrampsType):
|
||||
@@ -292,20 +292,19 @@ class DateNewYearType(mGrampsType):
|
||||
(NEWYEAR_MAR25, "March 25"),
|
||||
(NEWYEAR_SEP1, "September 1")]
|
||||
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NEWYEAR_JAN1]
|
||||
_DEFAULT = [x for x in _DATAMAP if x[0] == NEWYEAR_JAN1][0]
|
||||
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",]))
|
||||
|
||||
"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)
|
||||
|
||||
|
||||
@@ -174,8 +174,8 @@ def view_surname(request, handle, order, sorder, action="view"):
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
surname = name.surname_set.filter()[int(sorder) - 1] # sorder is 1-based
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
nameform = NameForm(instance=name)
|
||||
nameform.model = name
|
||||
|
||||
if action == "save":
|
||||
active = "view"
|
||||
@@ -187,7 +187,7 @@ def view_surname(request, handle, order, sorder, action="view"):
|
||||
context["id"] = id
|
||||
context["person"] = person
|
||||
context["object"] = person
|
||||
context["form"] = form
|
||||
context["nameform"] = form
|
||||
context["order"] = name.order
|
||||
context["sorder"] = sorder
|
||||
view_template = 'view_surname.html'
|
||||
@@ -199,19 +199,12 @@ def view_name(request, handle, order, action="view"):
|
||||
action = "add"
|
||||
if request.POST.has_key("action"):
|
||||
action = request.POST.get("action")
|
||||
### Process action:
|
||||
if action == "view":
|
||||
person = Person.objects.get(handle=handle)
|
||||
try:
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
except:
|
||||
return fix_person(request, person)
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
pf, nf, sf, person = get_person_forms(handle)
|
||||
name = nf.model
|
||||
elif action == "edit":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
pf, nf, sf, person = get_person_forms(handle)
|
||||
elif action == "delete":
|
||||
person = Person.objects.get(handle=handle)
|
||||
names = person.name_set.all().order_by("order")
|
||||
@@ -226,17 +219,18 @@ def view_name(request, handle, order, action="view"):
|
||||
was_preferred = False
|
||||
names[count].order = count
|
||||
names[count].save()
|
||||
form = NameForm()
|
||||
nf = NameForm()
|
||||
name = Name()
|
||||
nf.model = name
|
||||
action = "back"
|
||||
elif action == "add": # add name
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = Name(person=person,
|
||||
display_as=NameFormatType.objects.get(val=0),
|
||||
sort_as=NameFormatType.objects.get(val=0),
|
||||
name_type=NameType.objects.get(val=2))
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
display_as=NameFormatType._DEFAULT[0],
|
||||
sort_as=NameFormatType._DEFAULT[0],
|
||||
name_type=NameType._DEFAULT[0])
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
action = "edit"
|
||||
elif action == "save":
|
||||
person = Person.objects.get(handle=handle)
|
||||
@@ -272,10 +266,11 @@ def view_name(request, handle, order, action="view"):
|
||||
context["id"] = id
|
||||
context["person"] = person
|
||||
context["object"] = person
|
||||
context["form"] = form
|
||||
context["nameform"] = nf
|
||||
context["surnameform"] = sf
|
||||
context["order"] = name.order
|
||||
context["next"] = "/person/%s/name/%d" % (person.handle, name.order)
|
||||
view_template = "view_name.html"
|
||||
view_template = "view_name_detail.html"
|
||||
if action == "save":
|
||||
context["action"] = "view"
|
||||
return redirect("/person/%s/name/%d" % (person.handle, name.order))
|
||||
@@ -939,14 +934,15 @@ def get_person_forms(handle, protect=False, empty=False):
|
||||
name = person.name_set.get(preferred=True)
|
||||
except:
|
||||
name = Name(person=person, preferred=True,
|
||||
display_as=NameFormatType.objects.get(val=0),
|
||||
sort_as=NameFormatType.objects.get(val=0),
|
||||
name_type=NameType.objects.get(val=2))
|
||||
display_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
|
||||
sort_as=NameFormatType.objects.get(val=NameFormatType._DEFAULT[0]),
|
||||
name_type=NameType.objects.get(val=NameType._DEFAULT[0]))
|
||||
## get a surname
|
||||
try:
|
||||
surname = name.surname_set.get(primary=True)
|
||||
except:
|
||||
surname = Surname(name=name, primary=True)
|
||||
surname = Surname(name=name, primary=True, name_origin_type=NameOriginType.objects.get(val=NameOriginType._DEFAULT[0]),)
|
||||
|
||||
if protect and person.probably_alive:
|
||||
name.sanitize()
|
||||
pf = PersonForm(instance=person)
|
||||
|
||||
@@ -75,7 +75,7 @@ urlpatterns += patterns('',
|
||||
{"action": "view"}), # /object/handle/
|
||||
(r'^(?P<view>(\w+))/(?P<handle>(\w+))/(?P<action>(\w+))$',
|
||||
action), # /object/handle/action
|
||||
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name),
|
||||
(r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))$', view_name),
|
||||
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/(?P<action>(\w+))$', view_name),
|
||||
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))$', view_surname),
|
||||
# (r'^person/(?P<handle>(\w+))/name/(?P<order>(\w+))/surname/(?P<sorder>(\w+))/(?P<action>(\w+))$', view_surname),
|
||||
|
||||
Reference in New Issue
Block a user