[d8a37c]: gramps / webapp / grampsdb / forms.py Maximize Restore History

Download this file

forms.py    304 lines (266 with data), 12.3 kB

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
#
# Gramps - a GTK+/GNOME based genealogy program
#
# Copyright (C) 2000-2007 Donald N. Allingham
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
#
# webapp/grampsdb/forms.py
# forms.py forms for Django web project
# Django Modules:
from django import forms
from django.forms.models import inlineformset_factory
from django.forms.models import BaseModelFormSet
from django.forms.widgets import TextInput, HiddenInput
# Gramps Modules:
from gramps.webapp.grampsdb.models import *
from gramps.gen.mime import get_type
# Python Modules:
import datetime
class PersonForm(forms.ModelForm):
class Meta:
model = Person
exclude = ["death", "birth", "handle", "birth_ref_index",
"death_ref_index", "families", "parent_families",
"cache"]
class NameForm(forms.ModelForm):
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"]
# Add these because they are TextFields, which render as
# Textareas:
first_name = forms.CharField(label="Given",
required=False,
widget=TextInput(attrs={'size':'60'}))
title = forms.CharField(required=False,
widget=TextInput(attrs={'size':'15'}))
call = forms.CharField(label="Call",
required=False,
widget=TextInput(attrs={'size':'15'}))
nick = forms.CharField(label="Nick",
required=False,
widget=TextInput(attrs={'size':'15'}))
group_as = forms.CharField(label="Group as",
required=False,
widget=TextInput(attrs={'size':'30'}))
suffix = forms.CharField(required=False,
initial=' suffix ',
widget=TextInput(attrs={'size':'15',
'style': 'font-style: italic; color: gray; ',
'onFocus': """if (this.value == ' suffix ') {
this.value = '';
}
this.style.color = "black";
this.style.fontStyle = 'normal';
""",
'onBlur': """if (this.value == '') {
this.value = ' suffix ';
this.style.color = "gray";
this.style.fontStyle = 'italic';
}
"""}))
class NameFormFromPerson(NameForm):
class Meta:
model = Name
# Exclude these, so they don't get checked:
# Excludes sort_as and display_as
exclude = ["order", "calendar", "modifier",
"quality",
#"quality_estimated", "quality_calculated",
#"quality_interpreted",
"year1", "day1", "month1",
"sortval", "newyear", "person",
"group_as", "sort_as", "display_as"]
class SurnameForm(forms.ModelForm):
class Meta:
model = Surname
exclude = ['name', 'order']
surname = forms.CharField(label="Surname",
required=False,
widget=TextInput(attrs={'size':'30'}))
connector = forms.CharField(label="Connector",
required=False,
widget=TextInput(attrs={'size':'30'}))
prefix = forms.CharField(label="Prefix",
required=False,
initial=' prefix ',
widget=TextInput(attrs={'size':'15',
'style': 'font-style: italic; color: gray; ',
'onFocus': """if (this.value == ' prefix ') {
this.value = '';
}
this.style.color = "black";
this.style.fontStyle = 'normal';
""",
'onBlur': """if (this.value == '') {
this.value = ' prefix ';
this.style.color = "gray";
this.style.fontStyle = 'italic';
}
"""}))
class FamilyForm(forms.ModelForm):
class Meta:
model = Family
exclude = ["handle", "cache", "mother", "father"]
class EventForm(forms.ModelForm):
class Meta:
model = Event
exclude = ["handle", "sortval", "month1", "year1", "day1",
"newyear", "calendar", "modifier", "quality", "cache",
"place"]
def clean(self):
from gramps.webapp.utils import dp
data = super(EventForm, self).clean()
dobj = dp(data.get('text'))
if not dobj.is_valid():
msg = "Invalid date format"
self._errors["date"] = self.error_class([msg])
del data["text"]
return data
def save(self, commit=True):
from gramps.webapp.utils import dp
from gramps.webapp.libdjango import DjangoInterface
dji = DjangoInterface()
model = super(EventForm, self).save(commit=False)
dobj = dp(self.cleaned_data['text'])
dji.add_date(model, dobj.serialize())
if commit:
model.save()
return model
text = forms.CharField(label="Date",
required=False,
widget=TextInput(attrs={'size':'45'}))
class NoteForm(forms.ModelForm):
class Meta:
model = Note
exclude = ["handle", "text"]
notetext = forms.CharField(label="Text",
widget=forms.widgets.Textarea(attrs={'rows':'10', 'cols': '80', 'class':'wysiwyg'}))
class MediaForm(forms.ModelForm):
class Meta:
model = Media
exclude = ["handle", "sortval", "month1", "year1", "day1",
"newyear", "calendar", "modifier", "quality", "cache"]
def clean(self):
from gramps.webapp.utils import dp
data = super(MediaForm, self).clean()
dobj = dp(data.get('text'))
if not dobj.is_valid():
msg = "Invalid date format"
self._errors["date"] = self.error_class([msg])
del data["text"]
return data
def save(self, commit=True):
from gramps.webapp.utils import dp
from gramps.webapp.libdjango import DjangoInterface
dji = DjangoInterface()
model = super(MediaForm, self).save(commit=False)
model.mime = get_type(model.path)
dobj = dp(self.cleaned_data['text'])
dji.add_date(model, dobj.serialize())
if commit:
model.save()
return model
text = forms.CharField(label="Date",
required=False,
widget=TextInput(attrs={'size':'70'}))
desc = forms.CharField(label="Title",
required=False,
widget=TextInput(attrs={'size':'70'}))
path = forms.CharField(label="Path",
required=False,
widget=TextInput(attrs={'size':'70'}))
class CitationForm(forms.ModelForm):
class Meta:
model = Citation
exclude = ["handle", "sortval", "month1", "year1", "day1",
"newyear", "calendar", "modifier", "quality", "cache"]
def clean(self):
from gramps.webapp.utils import dp
data = super(CitationForm, self).clean()
dobj = dp(data.get('text'))
if not dobj.is_valid():
msg = "Invalid date format"
self._errors["date"] = self.error_class([msg])
del data["text"]
return data
def save(self, commit=True):
from gramps.webapp.utils import dp
from gramps.webapp.libdjango import DjangoInterface
dji = DjangoInterface()
model = super(CitationForm, self).save(commit=False)
dobj = dp(self.cleaned_data['text'])
dji.add_date(model, dobj.serialize())
if commit:
model.save()
return model
text = forms.CharField(label="Date",
required=False,
widget=TextInput(attrs={'size':'70'}))
class SourceForm(forms.ModelForm):
class Meta:
model = Source
exclude = ["handle", "cache"]
class PlaceForm(forms.ModelForm):
class Meta:
model = Place
exclude = ["handle", "cache"]
title = forms.CharField(label="Title",
required=False,
widget=TextInput(attrs={'size':'70'}))
long = forms.CharField(label="Longitude",
required=False,
widget=TextInput(attrs={'size':'70'}))
lat = forms.CharField(label="Latitude",
required=False,
widget=TextInput(attrs={'size':'70'}))
class RepositoryForm(forms.ModelForm):
class Meta:
model = Repository
exclude = ["handle", "cache"]
name = forms.CharField(label="Name",
required=False,
widget=TextInput(attrs={'size':'70'}))
class TagForm(forms.ModelForm):
class Meta:
model = Tag
exclude = ["handle"]
name = forms.CharField(label="Name",
required=False,
widget=TextInput(attrs={'size':'70'}))
class EventRefForm(forms.ModelForm):
class Meta:
model = EventRef
class LogForm(forms.ModelForm):
error_css_class = 'error'
class Meta:
model = Log
fields = ["reason"]
reason = forms.CharField(label="Reason for change",
widget=forms.widgets.Textarea(attrs={'rows':'2',
'cols': '65'}))
class PickForm(forms.Form):
picklist = forms.ChoiceField()
def __init__(self, label, item, order_by, *args, **kwargs):
super(PickForm, self).__init__(*args, **kwargs)
self.fields['picklist'].choices = \
[("", "---------")] + [(p.handle, p) for p in item.objects.all() \
.order_by(*order_by)]