Working add/edit people and names; working privacy (living and private); unified templates for display/edit
svn: r13952
This commit is contained in:
parent
eba1c9d264
commit
c800392ffd
@ -39,7 +39,11 @@
|
||||
<li><a href="/admin">Admin</a></li>
|
||||
{% endif %}
|
||||
{% else %}
|
||||
{% if next %}
|
||||
<li><a href="/login/?next={{next}}">Login</a></li>
|
||||
{% else %}
|
||||
<li><a href="/login/">Login</a></li>
|
||||
{% endif %}
|
||||
{% endif %}
|
||||
</ul>
|
||||
{% endblock %}
|
||||
|
@ -29,7 +29,11 @@
|
||||
</td>
|
||||
</tr>
|
||||
</table>
|
||||
{% if next %}
|
||||
<input type="hidden" name="next" value="{{next}}" />
|
||||
{% else %}
|
||||
<input type="hidden" name="next" value="/" />
|
||||
{% endif %}
|
||||
<input type="submit" value="Login" />
|
||||
</form>
|
||||
{% endblock %}
|
||||
|
@ -26,33 +26,35 @@
|
||||
{% endif %}
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.surname.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.surname|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.surname user action %}</td>
|
||||
<td class="ColumnAttribute">{{form.prefix.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.prefix|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.prefix user action %}</td>
|
||||
</tr>
|
||||
<td class="ColumnAttribute">{{form.first_name.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.first_name|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.first_name user action %}</td>
|
||||
<td class="ColumnAttribute">{{form.call.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.call|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.call user action %}</td>
|
||||
<tr>
|
||||
</tr>
|
||||
<td class="ColumnAttribute">{{form.title.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.title|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.title user action %}</td>
|
||||
<td class="ColumnAttribute">{{form.suffix.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.suffix|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.suffix user action %}</td>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.patronymic.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.patronymic|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.patronymic user action %}</td>
|
||||
<td class="ColumnAttribute">{{form.name_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{{form.name_type|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.name_type user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{form.preferred.label}}:</td>
|
||||
{% if form.model.preferred %}
|
||||
<td class="ColumnValue" id="data" colspan="3">True</td>
|
||||
<td class="ColumnValue" id="data">True</td>
|
||||
{% else %}
|
||||
<td class="ColumnValue" id="data" colspan="3">{{form.preferred|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render form.preferred user action %}</td>
|
||||
{% endif %}
|
||||
<td class="ColumnAttribute">{{form.private.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render form.private user action %}</td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -65,6 +67,7 @@
|
||||
<div class="ui-tabs ui-widget ui-widget-content ui-corner-all" id="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-general">General</a></li>
|
||||
<li class="ui-corner-top ui-state-default"><a href="#tab-names">Names</a></li>
|
||||
<li class="ui-corner-top ui-state-default"><a href="#tab-sources">Sources</a></li>
|
||||
<li class="ui-corner-top ui-state-default"><a href="#tab-notes">Notes</a></li>
|
||||
</ul>
|
||||
@ -74,21 +77,24 @@
|
||||
<div style="overflow: auto; height:150px; color: black; background-color: white;">
|
||||
<table border="1">
|
||||
<tr><td style="background-color: #FFF2C5;">{{form.group_as.label}}: </td>
|
||||
<td>{{form.group_as|render:action}}</td>
|
||||
<td>{% render form.group_as user action %}</td>
|
||||
</tr>
|
||||
<tr><td style="background-color: #FFF2C5;">{{form.sort_as.label}}: </td>
|
||||
<td>{{form.sort_as|render:action}}</td>
|
||||
<td>{% render form.sort_as user action %}</td>
|
||||
</tr>
|
||||
<tr><td style="background-color: #FFF2C5;">{{form.display_as.label}}: </td>
|
||||
<td>{{form.display_as|render:action}}</td>
|
||||
<td>{% render form.display_as user action %}</td>
|
||||
</tr>
|
||||
<tr><td style="background-color: #FFF2C5;">{{form.text.label}}: </td>
|
||||
<td>{{form.text|render:action}}</td>
|
||||
<td>{% render form.text user action %}</td>
|
||||
</tr>
|
||||
</table>
|
||||
</div>
|
||||
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-names">
|
||||
{% name_table person user action "/person/%s/name" person.handle %}
|
||||
</div>
|
||||
<div class="ui-tabs-panel ui-widget-content ui-corner-bottom ui-tabs-hide" id="tab-sources">
|
||||
{% source_table form.model user action "/person/%s/name/%s/source" person.handle form.model.order %}
|
||||
</div>
|
||||
@ -107,6 +113,7 @@
|
||||
{% else %}
|
||||
[<a href="/person/{{person.handle}}/name/{{order}}/edit">Edit Name</a>]
|
||||
[<a href="/person/{{person.handle}}/name/{{order}}/delete">Delete Name</a>]
|
||||
[<a href="/person/{{person.handle}}/name/add">Add Name</a>]
|
||||
{% endifequal %}
|
||||
{% else %}
|
||||
{% endif %}
|
||||
|
@ -13,82 +13,14 @@
|
||||
</form>
|
||||
</div>
|
||||
|
||||
<div class="pagination">
|
||||
<span class="step-links">
|
||||
<div id="alphabet" style="padding: 0pt 0 0pt 0;">
|
||||
<ul>
|
||||
{% ifequal page.number 1 %}
|
||||
<li>first</li>
|
||||
{% else %}
|
||||
<li><a href="?page=1{{search_query}}">first</a></li>
|
||||
{% endifequal %}
|
||||
{% if page.has_previous %}
|
||||
<li><a href="?page={{page.previous_page_number}}{{search_query}}">previous</a></li>
|
||||
{% else %}
|
||||
<li>previous</li>
|
||||
{% endif %}
|
||||
{% paginator %}
|
||||
|
||||
<span class="current">
|
||||
<li>Page {{ page.number }} of {{ page.paginator.num_pages }}</li>
|
||||
</span>
|
||||
|
||||
{% if page.has_next %}
|
||||
<li><a href="?page={{ page.next_page_number }}{{search_query}}">next</a></li>
|
||||
{% else %}
|
||||
<li>next</li>
|
||||
{% endif %}
|
||||
{% ifequal page.number page.paginator.num_pages %}
|
||||
<li>last</li>
|
||||
{% else %}
|
||||
<li><a href="?page={{page.paginator.num_pages}}{{search_query}}">last</a></li>
|
||||
{% endifequal %}
|
||||
<b>Matches</b>: {{page.paginator.count}}/{{total}}
|
||||
</ul>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
|
||||
<p> </p>
|
||||
|
||||
<div style="overflow:auto; height:450px;width:700px;">
|
||||
<div style="overflow:auto; height:500px;width:800px;">
|
||||
|
||||
{% block table_data %} <table></table> {% endblock %}
|
||||
|
||||
</div>
|
||||
|
||||
<div class="pagination">
|
||||
<span class="step-links">
|
||||
<div id="alphabet" style="padding: 10pt 0 10pt 0;">
|
||||
<ul>
|
||||
{% ifequal page.number 1 %}
|
||||
<li>first</li>
|
||||
{% else %}
|
||||
<li><a href="?page=1{{search_query}}">first</a></li>
|
||||
{% endifequal %}
|
||||
{% if page.has_previous %}
|
||||
<li><a href="?page={{page.previous_page_number}}{{search_query}}">previous</a></li>
|
||||
{% else %}
|
||||
<li>previous</li>
|
||||
{% endif %}
|
||||
|
||||
<span class="current">
|
||||
<li>Page {{ page.number }} of {{ page.paginator.num_pages }}</li>
|
||||
</span>
|
||||
|
||||
{% if page.has_next %}
|
||||
<li><a href="?page={{ page.next_page_number }}{{search_query}}">next</a></li>
|
||||
{% else %}
|
||||
<li>next</li>
|
||||
{% endif %}
|
||||
{% ifequal page.number page.paginator.num_pages %}
|
||||
<li>last</li>
|
||||
{% else %}
|
||||
<li><a href="?page={{page.paginator.num_pages}}{{search_query}}">last</a></li>
|
||||
{% endifequal %}
|
||||
<b>Matches</b>: {{page.paginator.count}}/{{total}}
|
||||
</ul>
|
||||
</div>
|
||||
</span>
|
||||
</div>
|
||||
{% include "paginator.html" %}
|
||||
|
||||
{% endblock %}
|
||||
|
@ -24,13 +24,19 @@
|
||||
</td>
|
||||
<td><a href="{{name.person.handle}}/" class="grampsid">[{{name.person.gramps_id}}]</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.gender_type}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.birth}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.death}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.birth|render_date:user}}</a></td>
|
||||
<td><a href="{{name.person.handle}}/" class="noThumb">{{name.person.death|render_date:user}}</a></td>
|
||||
{% endif %}
|
||||
</tr>
|
||||
{% endfor %}
|
||||
</tbody>
|
||||
</table>
|
||||
|
||||
{% if user.is_authenticated %}
|
||||
|
||||
{% make_button "Add a new Person" "/person/add" %}
|
||||
|
||||
{% endif %}
|
||||
|
||||
{% endblock %}
|
||||
|
||||
|
@ -11,7 +11,7 @@
|
||||
</script>
|
||||
|
||||
<div class="content" id="IndividualDetail">
|
||||
<h3>{{nameform|make_name:user}} [{{person.gramps_id}}]</h3>
|
||||
<h3>{{nameform|render_name:user}} [{{person.gramps_id}}]</h3>
|
||||
<div id="summaryarea">
|
||||
<table class="infolist"> {% comment %} 5 cols {% endcomment %}
|
||||
<tbody>
|
||||
@ -19,10 +19,10 @@
|
||||
{% if user.is_authenticated %}
|
||||
{% ifequal action "edit" %}
|
||||
{% for error in personform.errors %}
|
||||
{{error}}<br>
|
||||
Error in person: {{error}}<br>
|
||||
{% endfor %}
|
||||
{% for error in nameform.errors %}
|
||||
{{error}}<br>
|
||||
Error in name: {{error}}<br>
|
||||
{% endfor %}
|
||||
<form method="post">
|
||||
{% endifequal %}
|
||||
@ -30,43 +30,45 @@
|
||||
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{nameform.surname.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.surname|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.surname user action %}</td>
|
||||
<td class="ColumnAttribute">{{nameform.prefix.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.prefix|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.prefix user action %}</td>
|
||||
<td rowspan="6" colspan="2" style="border:solid 2px #7D5925;">Image:</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute" colspan="2"></td>
|
||||
<td class="ColumnAttribute">{{nameform.suffix.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.suffix|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.suffix user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{nameform.first_name.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.first_name|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.first_name user action nameform.model.person.probably_alive "[Living]" %}</td>
|
||||
<td class="ColumnAttribute">{{nameform.call.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.call|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.call user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{nameform.name_type.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.name_type|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.name_type user action %}</td>
|
||||
<td class="ColumnAttribute">{{nameform.patronymic.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.patronymic|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.patronymic user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute" colspan="2"></td>
|
||||
<td class="ColumnAttribute">{{nameform.title.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{nameform.title|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render nameform.title user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{personform.gender_type.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{personform.gender_type|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render personform.gender_type user action %}</td>
|
||||
<td class="ColumnAttribute">{{personform.gramps_id.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{personform.gramps_id|render:action}}</td>
|
||||
<td class="ColumnValue" id="data">{% render personform.gramps_id user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{personform.marker_type.label}}</td>
|
||||
<td class="ColumnValue" id="data">{{personform.marker_type|render:action}}</td>
|
||||
<td class="ColumnAttribute" colspan="3"></td>
|
||||
<td class="ColumnValue" id="data">{% render personform.marker_type user action %}</td>
|
||||
<td class="ColumnAttribute">{{personform.private.label}}</td>
|
||||
<td class="ColumnValue" id="data">{% render personform.private user action %}</td>
|
||||
<td class="ColumnAttribute" colspan="1"></td>
|
||||
</tr>
|
||||
</tbody>
|
||||
</table>
|
||||
@ -135,6 +137,7 @@
|
||||
</form>
|
||||
{% else %}
|
||||
{% make_button "Back to People" "/person/" %}
|
||||
{% make_button "Add Person" "/person/add" %}
|
||||
{% make_button "Edit Person" "/person/%s/edit" person.handle %}
|
||||
{% make_button "Delete Person" "/person/%s/delete" person.handle %}
|
||||
{% endifequal %}
|
||||
|
@ -86,8 +86,12 @@ class DjangoDb(DbReadBase, DbWriteBase):
|
||||
return obj
|
||||
|
||||
def get_person_from_handle(self, handle):
|
||||
data = self.dji.get_person(self.dji.Person.select_related().get(handle=handle))
|
||||
obj = gen.lib.Person.create(data)
|
||||
try:
|
||||
person = self.dji.Person.select_related().get(handle=handle)
|
||||
except:
|
||||
return None
|
||||
data = self.dji.get_person(person)
|
||||
obj = gen.lib.Person().unserialize(data)
|
||||
return obj
|
||||
|
||||
def get_place_from_handle(self, handle):
|
||||
|
@ -18,7 +18,7 @@
|
||||
"setting" : "db_created" ,
|
||||
"description" : "database creation date/time" ,
|
||||
"value_type" : "str" ,
|
||||
"value" : "2009-12-28 22:19"
|
||||
"value" : "2010-01-01 10:12"
|
||||
}
|
||||
},
|
||||
{
|
||||
|
@ -11,11 +11,8 @@ class PersonForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Person
|
||||
|
||||
'''def clean(self):
|
||||
cleaned_data['last_changed'] = datetime.datetime.now()
|
||||
super(PersonForm, self).clean() # validate based on model
|
||||
return self.cleaned_data'''
|
||||
|
||||
exclude = ["death", "birth", "handle"]
|
||||
|
||||
class NameForm(forms.ModelForm):
|
||||
class Meta:
|
||||
model = Name
|
||||
@ -50,51 +47,14 @@ class NameForm(forms.ModelForm):
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'30'}))
|
||||
|
||||
'''class NameFormset(BaseModelFormSet):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.form = NameForm
|
||||
super(NameFormset, self).__init__(*args, **kwargs)
|
||||
|
||||
def makeNameFormset(pid):
|
||||
class NameFormset(BaseFormSet):
|
||||
def __init__(self, *args, **kwargs):
|
||||
self.form = NameForm
|
||||
self.queryset = Name.objects.filter(person=pid)
|
||||
super(NameFormset, self).__init__(*args, **kwargs)
|
||||
def clean(self):
|
||||
super(NameFormset, self).clean() # validate based on model
|
||||
if any(self.errors):
|
||||
# formset is not valid as long as any one form is invalid
|
||||
return
|
||||
# allow only one name per person to be preferred
|
||||
ctPref = 0
|
||||
for i in range(0, self.total_form_count()):
|
||||
form = self.forms[i]
|
||||
ctPref += form.cleaned_data['preferred']
|
||||
if ctPref > 1:
|
||||
raise forms.ValidationError, "Only one name may be the preferred name."
|
||||
return NameFormset'''
|
||||
|
||||
NameInlineFormSet = inlineformset_factory(Person, Name,
|
||||
fields=('preferred','prefix','first_name',
|
||||
'surname','suffix','name_type'),
|
||||
form=NameForm)
|
||||
|
||||
def cleanPreferred(fmst):
|
||||
if fmst.total_form_count() == 3: # person has no names (assumes default 3 extra forms)
|
||||
return "Error: Each person must have at least one name."
|
||||
ctPref = 0
|
||||
for i in range (0,fmst.total_form_count()-3):
|
||||
form = fmst.forms[i]
|
||||
try: # when preferred is false, its value is not in the form data
|
||||
if form.data[fmst.prefix + '-' + str(i) + '-preferred'] == 'on':
|
||||
val = 1
|
||||
else:
|
||||
val = 0
|
||||
except:
|
||||
val = 0
|
||||
ctPref += val
|
||||
if ctPref != 1:
|
||||
return "Error: Exactly one name may be the preferred name."
|
||||
else:
|
||||
return "none"
|
||||
class NameFormFromPerson(NameForm):
|
||||
class Meta:
|
||||
model = Name
|
||||
# Exclude these, so they don't get checked:
|
||||
exclude = ["order", "calendar", "modifier",
|
||||
"quality",
|
||||
#"quality_estimated", "quality_calculated",
|
||||
#"quality_interpreted",
|
||||
"year1", "day1", "month1",
|
||||
"sortval", "newyear", "person",
|
||||
"sort_as", "display_as"]
|
||||
|
@ -300,23 +300,23 @@ class DateNewYearType(mGrampsType):
|
||||
class DateObject(models.Model):
|
||||
class Meta: abstract = True
|
||||
|
||||
calendar = models.IntegerField()
|
||||
modifier = models.IntegerField()
|
||||
quality = models.IntegerField()
|
||||
calendar = models.IntegerField(default=0)
|
||||
modifier = models.IntegerField(default=0)
|
||||
quality = models.IntegerField(default=0)
|
||||
#quality_estimated = models.BooleanField()
|
||||
#quality_calculated = models.BooleanField()
|
||||
#quality_interpreted = models.BooleanField()
|
||||
day1 = models.IntegerField()
|
||||
month1 = models.IntegerField()
|
||||
year1 = models.IntegerField()
|
||||
slash1 = models.BooleanField()
|
||||
day1 = models.IntegerField(default=0)
|
||||
month1 = models.IntegerField(default=0)
|
||||
year1 = models.IntegerField(default=0)
|
||||
slash1 = models.BooleanField(default=False)
|
||||
day2 = models.IntegerField(blank=True, null=True)
|
||||
month2 = models.IntegerField(blank=True, null=True)
|
||||
year2 = models.IntegerField(blank=True, null=True)
|
||||
slash2 = models.NullBooleanField(blank=True, null=True)
|
||||
text = models.CharField(max_length=80, blank=True)
|
||||
sortval = models.IntegerField()
|
||||
newyear = models.IntegerField()
|
||||
sortval = models.IntegerField(default=0)
|
||||
newyear = models.IntegerField(default=0)
|
||||
|
||||
def set_date_from_datetime(self, date_time, text=""):
|
||||
"""
|
||||
@ -401,8 +401,8 @@ class Person(PrimaryObject):
|
||||
references = generic.GenericRelation('PersonRef', related_name="refs",
|
||||
content_type_field="object_type",
|
||||
object_id_field="object_id")
|
||||
birth = models.ForeignKey("Event", related_name="birth", null=True)
|
||||
death = models.ForeignKey("Event", related_name="death", null=True)
|
||||
birth = models.ForeignKey("Event", related_name="birth", blank=True, null=True)
|
||||
death = models.ForeignKey("Event", related_name="death", blank=True, null=True)
|
||||
|
||||
# Others keys here:
|
||||
# .name_set
|
||||
@ -414,12 +414,7 @@ class Person(PrimaryObject):
|
||||
"""
|
||||
Return the preferred name of a person.
|
||||
"""
|
||||
names = self.name_set.all().order_by("order")
|
||||
if names.count() > 0:
|
||||
name = names[0]
|
||||
else:
|
||||
name = None
|
||||
return name
|
||||
return self.name_set.get(preferred=True)
|
||||
|
||||
class Family(PrimaryObject):
|
||||
father = models.ForeignKey('Person', related_name="father_ref",
|
||||
@ -509,10 +504,12 @@ class SecondaryObject(models.Model):
|
||||
last_saved = models.DateTimeField('last changed', auto_now=True)
|
||||
last_changed = models.DateTimeField('last changed', null=True,
|
||||
blank=True) # user edits
|
||||
order = models.PositiveIntegerField()
|
||||
order = models.PositiveIntegerField(default=1)
|
||||
|
||||
class Name(DateObject, SecondaryObject):
|
||||
name_type = models.ForeignKey('NameType', related_name="name_code")
|
||||
name_type = models.ForeignKey('NameType',
|
||||
related_name="name_code",
|
||||
default=2)
|
||||
preferred = models.BooleanField('Preferred name?')
|
||||
first_name = models.TextField(blank=True)
|
||||
surname = models.TextField(blank=True)
|
||||
@ -523,12 +520,14 @@ class Name(DateObject, SecondaryObject):
|
||||
call = models.TextField(blank=True)
|
||||
group_as = models.TextField(blank=True)
|
||||
sort_as = models.ForeignKey('NameFormatType',
|
||||
related_name="sort_as")
|
||||
related_name="sort_as",
|
||||
default=1)
|
||||
display_as = models.ForeignKey('NameFormatType',
|
||||
related_name="display_as")
|
||||
|
||||
related_name="display_as",
|
||||
default=1)
|
||||
## Key:
|
||||
person = models.ForeignKey("Person")
|
||||
_sanitized = False
|
||||
|
||||
def __unicode__(self):
|
||||
return "%s%s%s, %s" % (self.prefix,
|
||||
@ -541,12 +540,13 @@ class Name(DateObject, SecondaryObject):
|
||||
#name.
|
||||
|
||||
def sanitize(self):
|
||||
self.first_name = "[Private]"
|
||||
self.prefix = ""
|
||||
self.suffix = ""
|
||||
self.prefix = ""
|
||||
self.prefix = ""
|
||||
self.prefix = ""
|
||||
if not self._sanitized:
|
||||
self._sanitized = True
|
||||
if self.person.probably_alive:
|
||||
self.first_name = "[Living]"
|
||||
self.call = ""
|
||||
self.group_as = ""
|
||||
self.title = ""
|
||||
|
||||
class Lds(DateObject, SecondaryObject):
|
||||
"""
|
||||
|
@ -8,6 +8,16 @@ import web.utils
|
||||
|
||||
register = Library()
|
||||
|
||||
def eval_template_exp(item, context):
|
||||
"""
|
||||
Wrapper to allow negation of variables in templates. Use
|
||||
"!variable".
|
||||
"""
|
||||
if item.var.startswith("!"):
|
||||
return not template.Variable(item.var[1:]).resolve(context)
|
||||
else:
|
||||
return item.resolve(context)
|
||||
|
||||
class TemplateNode(template.Node):
|
||||
def __init__(self, args, var_name, func):
|
||||
self.args = map(template.Variable, args)
|
||||
@ -15,7 +25,8 @@ class TemplateNode(template.Node):
|
||||
self.func = func
|
||||
|
||||
def render(self, context):
|
||||
value = self.func(*[item.resolve(context) for item in self.args])
|
||||
value = self.func(*[eval_template_exp(item, context)
|
||||
for item in self.args])
|
||||
if self.var_name:
|
||||
context[self.var_name] = value
|
||||
return ''
|
||||
@ -123,34 +134,9 @@ def paginator(context, adjacent_pages=2):
|
||||
view.
|
||||
|
||||
"""
|
||||
## Alternative page_numbers:
|
||||
page_numbers = range(max(0, context['page']-adjacent_pages),
|
||||
min(context['pages'],
|
||||
context['page']+adjacent_pages)+1)
|
||||
results_this_page = context['object_list'].__len__()
|
||||
range_base = ((context['page'] - 1) * context['results_per_page'])
|
||||
|
||||
# # Original
|
||||
# # page_numbers = [n for n in range(context['page'] - adjacent_pages,
|
||||
# # context['page'] + adjacent_pages + 1)
|
||||
# # if n > 0 and n <= context['pages']]
|
||||
|
||||
return {
|
||||
'hits': context['hits'],
|
||||
'results_per_page': context['results_per_page'],
|
||||
'results_this_page': results_this_page,
|
||||
'first_this_page': range_base + 1,
|
||||
'last_this_page': range_base + results_this_page,
|
||||
'page': context['page'],
|
||||
'pages': context['pages'],
|
||||
'page_numbers': page_numbers,
|
||||
'next': context['next'],
|
||||
'previous': context['previous'],
|
||||
'has_next': context['has_next'],
|
||||
'has_previous': context['has_previous'],
|
||||
'show_first': 1 not in page_numbers,
|
||||
'show_last': context['pages'] not in page_numbers,
|
||||
}
|
||||
results_this_page = context["page"].object_list.count()
|
||||
context.update({'results_this_page': results_this_page,})
|
||||
return context
|
||||
|
||||
register.inclusion_tag('paginator.html',
|
||||
takes_context=True)(paginator)
|
||||
|
@ -41,11 +41,11 @@ from django.db.models import Q
|
||||
#------------------------------------------------------------------------
|
||||
import web
|
||||
from web.grampsdb.models import *
|
||||
from web.grampsdb.forms import NameForm, PersonForm
|
||||
from web.utils import probably_alive
|
||||
from web.grampsdb.forms import *
|
||||
from web.djangodb import DjangoDb
|
||||
|
||||
import gen.proxy
|
||||
from Utils import create_id
|
||||
|
||||
_ = lambda text: text
|
||||
|
||||
@ -70,6 +70,9 @@ def context_processor(request):
|
||||
context["css_theme"] = "Web_Mainz.css"
|
||||
# FIXME: get the views from a config?
|
||||
context["views"] = VIEWS
|
||||
context["True"] = True
|
||||
context["False"] = False
|
||||
context["default"] = ""
|
||||
return context
|
||||
|
||||
# CSS Themes:
|
||||
@ -107,6 +110,40 @@ def user_page(request, username):
|
||||
context["tview"] = _('User')
|
||||
return render_to_response('user_page.html', context)
|
||||
|
||||
def fix_person(request, person):
|
||||
try:
|
||||
name = person.name_set.get(preferred=True)
|
||||
except:
|
||||
names = person.name_set.all().order_by("order")
|
||||
if names.count() == 0:
|
||||
name = Name(person=person,
|
||||
surname="? Fixed",
|
||||
first_name="? Missing name",
|
||||
preferred=True)
|
||||
name.save()
|
||||
else:
|
||||
order = 1
|
||||
for name in names:
|
||||
if order == 1:
|
||||
name.preferred = True
|
||||
else:
|
||||
name.preferred = False
|
||||
name.order = order
|
||||
name.save()
|
||||
order += 1
|
||||
if request:
|
||||
return redirect("/person/%s" % person.handle, request)
|
||||
|
||||
def set_date(obj):
|
||||
obj.calendar = 0
|
||||
obj.modifier = 0
|
||||
obj.quality = 0
|
||||
obj.text = ""
|
||||
obj.sortval = 0
|
||||
obj.newyear = 0
|
||||
obj.day1, obj.month1, obj.year1, obj.slash1 = 0, 0, 0, 0
|
||||
obj.day2, obj.month2, obj.year2, obj.slash2 = 0, 0, 0, 0
|
||||
|
||||
def view_name_detail(request, handle, order, action="view"):
|
||||
if order == "add":
|
||||
order = 0
|
||||
@ -115,50 +152,53 @@ def view_name_detail(request, handle, order, action="view"):
|
||||
action = request.POST.get("action")
|
||||
if action == "view":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(order=order)
|
||||
try:
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
except:
|
||||
return fix_person(request, person)
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
elif action == "edit":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(order=order)
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
form = NameForm(instance=name)
|
||||
form.model = name
|
||||
elif action == "delete":
|
||||
person = Person.objects.get(handle=handle)
|
||||
name_to_delete = person.name_set.get(order=order)
|
||||
was_preferred = name_to_delete.preferred
|
||||
name_to_delete.delete()
|
||||
names = person.name_set.all().order_by("order")
|
||||
for count in range(names.count()):
|
||||
if was_preferred:
|
||||
names[count].preferred = True
|
||||
was_preferred = False
|
||||
names[count].order = count
|
||||
names[count].save()
|
||||
print "delete", names.count()
|
||||
if names.count() > 1:
|
||||
print "more than 1"
|
||||
name_to_delete = names[0]
|
||||
was_preferred = name_to_delete.preferred
|
||||
name_to_delete.delete()
|
||||
names = person.name_set.all().order_by("order")
|
||||
for count in range(names[1:].count()):
|
||||
print count
|
||||
if was_preferred:
|
||||
names[count].preferred = True
|
||||
was_preferred = False
|
||||
names[count].order = count
|
||||
names[count].save()
|
||||
form = NameForm()
|
||||
name = Name()
|
||||
action = "back"
|
||||
elif action == "add":
|
||||
elif action == "add": # add name
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = Name()
|
||||
name.sort_as = NameFormatType.objects.get(val=0)
|
||||
name.display_as = NameFormatType.objects.get(val=0)
|
||||
name.name_type = NameType.objects.get(val=2) # Birth Name
|
||||
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
|
||||
action = "edit"
|
||||
elif action == "save":
|
||||
person = Person.objects.get(handle=handle)
|
||||
try:
|
||||
name = person.name_set.get(order=order)
|
||||
name = person.name_set.filter(order=order)[0]
|
||||
except:
|
||||
order = person.name_set.count() + 1
|
||||
name = Name(calendar=0, modifier=0, quality=0,
|
||||
year1=0, day1=0, month1=0,
|
||||
sortval = 0, newyear=0, order=order,
|
||||
sort_as=NameFormatType(val=0),
|
||||
display_as=NameFormatType(val=0),
|
||||
person_id=person.id)
|
||||
name = Name(person=person, order=order)
|
||||
form = NameForm(request.POST, instance=name)
|
||||
form.model = name
|
||||
if form.is_valid():
|
||||
@ -174,6 +214,7 @@ def view_name_detail(request, handle, order, action="view"):
|
||||
.update(preferred=False)
|
||||
# else some other name is preferred
|
||||
print "save"
|
||||
set_date(name)
|
||||
n = form.save()
|
||||
print n.preferred
|
||||
else:
|
||||
@ -187,6 +228,7 @@ def view_name_detail(request, handle, order, action="view"):
|
||||
context["person"] = person
|
||||
context["form"] = form
|
||||
context["order"] = name.order
|
||||
context["next"] = "/person/%s/name/%d" % (person.handle, name.order)
|
||||
view_template = "view_name_detail.html"
|
||||
print "action:", action
|
||||
if action == "save":
|
||||
@ -200,13 +242,6 @@ def view_name_detail(request, handle, order, action="view"):
|
||||
return render_to_response(view_template, context)
|
||||
|
||||
|
||||
class PrivateProxy(object):
|
||||
def __init__(self, obj):
|
||||
self.obj = obj
|
||||
|
||||
def __getattr__(self, attr):
|
||||
return getattr(self.obj, attr)
|
||||
|
||||
def view_detail(request, view, handle, action="view"):
|
||||
context = RequestContext(request)
|
||||
context["action"] = action
|
||||
@ -265,56 +300,104 @@ def view_detail(request, view, handle, action="view"):
|
||||
else:
|
||||
raise Http404(_("Requested page type not known"))
|
||||
context[view] = obj
|
||||
context["next"] = "/%s/%s" % (view, obj.handle)
|
||||
return render_to_response(view_template, context)
|
||||
|
||||
def get_gramps_db(request):
|
||||
dbase = DjangoDb()
|
||||
#if request.user.is_authenticated():
|
||||
private_filter=False
|
||||
living_filter=False
|
||||
#else:
|
||||
# private_filter=True
|
||||
# living_filter=True
|
||||
# If the private flag is set, apply the PrivateProxyDb
|
||||
if private_filter:
|
||||
dbase = gen.proxy.PrivateProxyDb(dbase)
|
||||
# If the restrict flag is set, apply the LivingProxyDb
|
||||
if living_filter:
|
||||
dbase = gen.proxy.LivingProxyDb(
|
||||
dbase,
|
||||
gen.proxy.LivingProxyDb.MODE_INCLUDE_LAST_NAME_ONLY)
|
||||
return dbase
|
||||
|
||||
def view_person_detail(request, view, handle, action="view"):
|
||||
context = RequestContext(request)
|
||||
print view, handle, action
|
||||
if handle == "add":
|
||||
if request.POST.has_key("action"):
|
||||
action = request.POST.get("action")
|
||||
else:
|
||||
action = "add"
|
||||
elif request.POST.has_key("action"):
|
||||
action = request.POST.get("action")
|
||||
if request.user.is_authenticated():
|
||||
if action == "edit":
|
||||
# get all of the data:
|
||||
person = Person.objects.get(handle=handle)
|
||||
try:
|
||||
name = person.name_set.get(preferred=True)
|
||||
except:
|
||||
name = Name(person=person, preferred=True)
|
||||
pf = PersonForm(instance=person)
|
||||
pf.model = person
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
elif action == "add":
|
||||
# make new data:
|
||||
person = Person()
|
||||
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))
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
pf = PersonForm(instance=person)
|
||||
pf.model = person
|
||||
action = "edit"
|
||||
elif action == "save":
|
||||
try:
|
||||
person = Person.objects.get(handle=handle)
|
||||
except:
|
||||
person = Person(handle=create_id())
|
||||
if person.id: # editing
|
||||
name = person.name_set.get(preferred=True)
|
||||
else: # adding a new person with new name
|
||||
name = Name(person=person, preferred=True)
|
||||
pf = PersonForm(request.POST, instance=person)
|
||||
pf.model = person
|
||||
nf = NameFormFromPerson(request.POST, instance=name)
|
||||
nf.model = name
|
||||
print "checking:", person.handle
|
||||
if nf.is_valid() and pf.is_valid():
|
||||
person = pf.save()
|
||||
name = nf.save(commit=False)
|
||||
name.person = person
|
||||
name.save()
|
||||
else:
|
||||
action = "edit"
|
||||
else: # view
|
||||
person = Person.objects.get(handle=handle)
|
||||
try:
|
||||
name = person.name_set.get(preferred=True)
|
||||
except:
|
||||
return fix_person(request, person)
|
||||
pf = PersonForm(instance=person)
|
||||
pf.model = person
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
else: # view person detail
|
||||
# BEGIN NON-AUTHENTICATED ACCESS
|
||||
person = Person.objects.get(handle=handle)
|
||||
if person:
|
||||
if person.private:
|
||||
raise Http404(_("Requested %s is not accessible.") % view)
|
||||
name = person.name_set.get(preferred=True)
|
||||
if person.probably_alive:
|
||||
name.sanitize()
|
||||
else:
|
||||
raise Http404(_("Requested %s does not exist.") % view)
|
||||
pf = PersonForm(instance=person)
|
||||
pf.model = person
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
# END NON-AUTHENTICATED ACCESS
|
||||
if action == "save":
|
||||
context["action"] = "view"
|
||||
return redirect("/person/%s" % person.handle, context)
|
||||
context["action"] = action
|
||||
context["view"] = view
|
||||
context["tview"] = _("Person")
|
||||
view_template = 'view_person_detail.html'
|
||||
if request.user.is_authenticated():
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(preferred=True)
|
||||
else:
|
||||
db = get_gramps_db(request)
|
||||
gramps_person = db.get_person_from_handle(handle)
|
||||
if not gramps_person:
|
||||
raise Http404(_("Requested %s is not accessible.") % view)
|
||||
person = Person.objects.get(handle=handle)
|
||||
name = person.name_set.get(preferred=True)
|
||||
# fill forms with data from db
|
||||
name.surname = gramps_person.get_primary_name().get_surname()
|
||||
name.first_name = gramps_person.get_primary_name().get_first_name()
|
||||
pf = PersonForm(instance=person)
|
||||
pf.model = person
|
||||
nf = NameForm(instance=name)
|
||||
nf.model = name
|
||||
context["personform"] = pf
|
||||
context["nameform"] = nf
|
||||
context["person"] = person
|
||||
context["next"] = "/person/%s" % person.handle
|
||||
view_template = 'view_person_detail.html'
|
||||
return render_to_response(view_template, context)
|
||||
|
||||
def view(request, view):
|
||||
db = get_gramps_db(request)
|
||||
search = ""
|
||||
if view == "event":
|
||||
if request.user.is_authenticated():
|
||||
@ -366,12 +449,14 @@ def view(request, view):
|
||||
if request.GET.has_key("search"):
|
||||
search = request.GET.get("search")
|
||||
if "," in search:
|
||||
search, trash = [term.strip() for term in search.split(",", 1)]
|
||||
search_text, trash = [term.strip() for term in search.split(",", 1)]
|
||||
else:
|
||||
search_text = search
|
||||
object_list = Family.objects \
|
||||
.filter((Q(gramps_id__icontains=search) |
|
||||
Q(family_rel_type__name__icontains=search) |
|
||||
Q(father__name__surname__istartswith=search) |
|
||||
Q(mother__name__surname__istartswith=search)) &
|
||||
.filter((Q(gramps_id__icontains=search_text) |
|
||||
Q(family_rel_type__name__icontains=search_text) |
|
||||
Q(father__name__surname__istartswith=search_text) |
|
||||
Q(mother__name__surname__istartswith=search_text)) &
|
||||
Q(private=False) &
|
||||
Q(mother__private=False) &
|
||||
Q(father__private=False)
|
||||
@ -450,11 +535,14 @@ def view(request, view):
|
||||
# BEGIN NON-AUTHENTICATED users
|
||||
if request.GET.has_key("search"):
|
||||
search = request.GET.get("search")
|
||||
print "search:", search
|
||||
if "," in search:
|
||||
search, trash = [term.strip() for term in search.split(",", 1)]
|
||||
search_text, trash = [term.strip() for term in search.split(",", 1)]
|
||||
else:
|
||||
search_text = search
|
||||
object_list = Name.objects \
|
||||
.select_related() \
|
||||
.filter(Q(surname__istartswith=search) &
|
||||
.filter(Q(surname__istartswith=search_text) &
|
||||
Q(private=False) &
|
||||
Q(person__private=False)
|
||||
) \
|
||||
@ -548,9 +636,10 @@ def view(request, view):
|
||||
context["tview"] = _(view.title())
|
||||
context["search"] = search
|
||||
context["total"] = total
|
||||
context["db"] = db
|
||||
context["object_list"] = object_list
|
||||
context["next"] = "/person/"
|
||||
if search:
|
||||
context["search_query"] = ("&search=%s" % escape(search))
|
||||
context["search_query"] = ("&search=%s" % search)
|
||||
else:
|
||||
context["search_query"] = ""
|
||||
return render_to_response(view_template, context)
|
||||
|
Binary file not shown.
150
src/web/utils.py
150
src/web/utils.py
@ -66,10 +66,12 @@ _ = lambda msg: msg
|
||||
|
||||
util_filters = [
|
||||
'nbsp',
|
||||
'render',
|
||||
'render_date',
|
||||
'render_name',
|
||||
]
|
||||
|
||||
util_tags = [
|
||||
'render',
|
||||
"get_person_from_handle",
|
||||
"event_table",
|
||||
"name_table",
|
||||
@ -178,15 +180,6 @@ class Table(object):
|
||||
|
||||
_ = lambda text: text
|
||||
|
||||
def render(formfield, action):
|
||||
retval = "error"
|
||||
fieldname = formfield.name # 'surname'
|
||||
if action == "view": # gets the unicode from model
|
||||
retval = str(getattr(formfield.form.model, fieldname))
|
||||
else: # renders as default
|
||||
retval = formfield.as_widget()
|
||||
return retval
|
||||
|
||||
def make_button(text, url, *args):
|
||||
url = url % args
|
||||
return """[ <a href="%s">%s</a> ] """ % (url, text)
|
||||
@ -215,7 +208,7 @@ def event_table(obj, user, action, url=None, *args):
|
||||
get_title(djevent.place),
|
||||
str(event_ref.role_type))
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add event"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -244,7 +237,7 @@ def name_table(obj, user, action, url=None, *args):
|
||||
except:
|
||||
note = None
|
||||
table.row(make_name(name, user),
|
||||
str(name.name_type),
|
||||
str(name.name_type) + ["", " (preferred)"][int(name.preferred)],
|
||||
name.group_as,
|
||||
["No", "Yes"][sourceq],
|
||||
note)
|
||||
@ -253,7 +246,7 @@ def name_table(obj, user, action, url=None, *args):
|
||||
(url % name.person.handle) + ("/%s" % name.order)))
|
||||
table.links(links)
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add name"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -278,7 +271,7 @@ def source_table(obj, user, action, url=None, *args):
|
||||
source_ref.page,
|
||||
)
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add source"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -302,7 +295,7 @@ def note_table(obj, user, action, url=None, *args):
|
||||
str(note_ref.ref_object.note_type),
|
||||
note_ref.ref_object.text[:50])
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add note"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -322,7 +315,7 @@ def attribute_table(obj, user, action, url=None, *args):
|
||||
table.row(attribute.attribute_type.name,
|
||||
attribute.value)
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add attribute"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -346,7 +339,7 @@ def address_table(obj, user, action, url=None, *args):
|
||||
location.state,
|
||||
location.country)
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add address"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -359,7 +352,7 @@ def gallery_table(obj, user, action, url=None, *args):
|
||||
_("Type"),
|
||||
)
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add gallery"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -378,7 +371,7 @@ def internet_table(obj, user, action, url=None, *args):
|
||||
url_obj.path,
|
||||
url_obj.desc)
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add internet"), ((str(url) % args) + "/add"))
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -392,11 +385,12 @@ def association_table(obj, user, action, url=None, *args):
|
||||
_("Association"))
|
||||
if user.is_authenticated():
|
||||
gperson = table.db.get_person_from_handle(obj.handle)
|
||||
associations = gperson.get_person_ref_list()
|
||||
for association in associations:
|
||||
table.row()
|
||||
if gperson:
|
||||
associations = gperson.get_person_ref_list()
|
||||
for association in associations:
|
||||
table.row()
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add association"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -420,7 +414,7 @@ def lds_table(obj, user, action, url=None, *args):
|
||||
lds.temple,
|
||||
get_title(lds.place))
|
||||
retval += table.get_html()
|
||||
if user.is_authenticated() and url and action != "edit":
|
||||
if user.is_authenticated() and url and action == "view":
|
||||
retval += make_button(_("Add LDS"), (url + "/add") % args)
|
||||
else:
|
||||
retval += nbsp("") # to keep tabs same height
|
||||
@ -492,6 +486,71 @@ def display_date(obj):
|
||||
else:
|
||||
return ""
|
||||
|
||||
def render(formfield, user, action, test=False, truetext=""):
|
||||
if not user.is_authenticated():
|
||||
action = "view"
|
||||
if action == "view":
|
||||
if (not user.is_authenticated() and not test) or user.is_authenticated():
|
||||
fieldname = formfield.name # 'surname'
|
||||
retval = str(getattr(formfield.form.model, fieldname))
|
||||
else:
|
||||
retval = truetext
|
||||
else:
|
||||
retval = formfield.as_widget()
|
||||
return retval
|
||||
|
||||
def render_name(name, user):
|
||||
"""
|
||||
Given a Django or Gramps object, render the name and return. This
|
||||
function uses authentication, privacy and probably_alive settings.
|
||||
"""
|
||||
if isinstance(name, models.Name):
|
||||
if not user.is_authenticated():
|
||||
name.sanitize()
|
||||
return "%s, %s" % (name.surname, name.first_name)
|
||||
elif isinstance(name, forms.NameForm):
|
||||
if not user.is_authenticated():
|
||||
name.model.sanitize()
|
||||
return "%s, %s" % (name.model.surname, name.model.first_name)
|
||||
elif isinstance(name, gen.lib.Person): # name is a gen.lib.Person
|
||||
person = name
|
||||
try:
|
||||
name = person.get_primary_name()
|
||||
except:
|
||||
name = None
|
||||
if name is None:
|
||||
return "[No preferred name]"
|
||||
if not user.is_authenticated():
|
||||
name.sanitize()
|
||||
return "%s, %s" % (name.surname, name.first_name)
|
||||
elif isinstance(name, models.Person): # django person
|
||||
person = name
|
||||
try:
|
||||
name = person.name_set.get(preferred=True)
|
||||
except:
|
||||
return "Error"
|
||||
return render_name(name, user)
|
||||
else: # no name object
|
||||
return "[No preferred name]"
|
||||
|
||||
def make_name(name, user):
|
||||
return render_name(name, user)
|
||||
|
||||
def render_date(obj, user):
|
||||
"""
|
||||
Given a Django object, render the date as text and return. This
|
||||
function uses authentication settings.
|
||||
"""
|
||||
if (user.is_authenticated() or
|
||||
(not user.is_authenticated() and obj and not obj.private)):
|
||||
if obj:
|
||||
date_tuple = dji.get_date(obj)
|
||||
if date_tuple:
|
||||
gdate = GDate().unserialize(date_tuple)
|
||||
return _dd(gdate)
|
||||
return ""
|
||||
return "[Private]"
|
||||
|
||||
def person_get_event(person, event_type=None):
|
||||
event_ref_list = dji.get_event_ref_list(person)
|
||||
if event_type:
|
||||
@ -513,42 +572,6 @@ def person_get_event(person, event_type=None):
|
||||
for event_handle in event_ref_list]
|
||||
return [j for i in retval for j in i]
|
||||
|
||||
def make_name(name, user):
|
||||
if isinstance(name, models.Name):
|
||||
surname = name.surname.strip()
|
||||
if not surname:
|
||||
surname = "[Missing]"
|
||||
if user.is_authenticated():
|
||||
return "%s, %s" % (surname, name.first_name)
|
||||
else:
|
||||
if name.person.probably_alive:
|
||||
return "%s, %s" % (surname, "[Living]")
|
||||
else:
|
||||
return "%s, %s" % (surname, name.first_name)
|
||||
elif isinstance(name, forms.NameForm):
|
||||
surname = name.model.surname.strip()
|
||||
if not surname:
|
||||
surname = "[Missing]"
|
||||
if user.is_authenticated():
|
||||
return "%s, %s" % (surname, name.model.first_name)
|
||||
else:
|
||||
if name.model.person.probably_alive:
|
||||
return "%s, %s" % (surname, "[Living]")
|
||||
else:
|
||||
return "%s, %s" % (surname, name.model.first_name)
|
||||
elif isinstance(name, gen.lib.Person): # name is a gen.lib.Person
|
||||
person = name
|
||||
name = person.get_primary_name()
|
||||
if name is None:
|
||||
return "[No preferred name]"
|
||||
else:
|
||||
return "%s, %s" % (name.get_surname(), name.get_first_name())
|
||||
elif isinstance(name, models.Person): # django person
|
||||
person = name
|
||||
return make_name(person.name_set.get(preferred=True), user)
|
||||
else: # no name
|
||||
return ""
|
||||
|
||||
class lazy(object):
|
||||
EMPTY = []
|
||||
used = 0
|
||||
@ -573,6 +596,13 @@ class lazy(object):
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return getattr(object.__getattribute__(self, "result"), attr)
|
||||
|
||||
def myclass(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
return object.__getattribute__(self, "result").__class__
|
||||
|
||||
#__class__ = property(myclass)
|
||||
|
||||
def __str__(self):
|
||||
if object.__getattribute__(self, "result") is lazy.EMPTY:
|
||||
object.__getattribute__(self, "thaw")()
|
||||
|
Loading…
Reference in New Issue
Block a user