Better method for date editing; updates for DateHandler
svn: r19654
This commit is contained in:
parent
e860f32d51
commit
ba9c607ae9
@ -27,8 +27,8 @@
|
||||
<tr>
|
||||
<td class="ColumnAttribute">{{eventform.event_type.label}}:</td>
|
||||
<td class="ColumnValue" id="data"> {% render eventform.event_type user action %}</td>
|
||||
<td class="ColumnAttribute">Date:</td>
|
||||
<td class="ColumnValue" id="data">{% render eventform.date user action %}</td>
|
||||
<td class="ColumnAttribute">{{eventform.text.label}}:</td>
|
||||
<td class="ColumnValue" id="data">{% render eventform.text user action %}</td>
|
||||
</tr>
|
||||
<tr>
|
||||
<td class="ColumnAttribute">Description:</td>
|
||||
|
@ -133,31 +133,14 @@ class EventForm(forms.ModelForm):
|
||||
exclude = ["handle", "sortval", "month1", "year1", "day1",
|
||||
"newyear", "calendar", "modifier", "quality"]
|
||||
|
||||
def __init__(self, *args, **kwargs):
|
||||
from webapp.utils import display_date
|
||||
super(EventForm, self).__init__(*args, **kwargs)
|
||||
|
||||
# Set the form fields based on the model object
|
||||
if kwargs.has_key('instance'):
|
||||
instance = kwargs['instance']
|
||||
sdate = display_date(instance)
|
||||
if sdate != "0000-00-00":
|
||||
self.initial['date'] = sdate
|
||||
try:
|
||||
self.data['date'] = self.initial['date']
|
||||
except:
|
||||
pass
|
||||
|
||||
def clean(self):
|
||||
from webapp.utils import dp
|
||||
data = super(EventForm, self).clean()
|
||||
dobj = dp(data.get('date'))
|
||||
dobj = dp(data.get('text'))
|
||||
if not dobj.is_valid():
|
||||
msg = u"Invalid date format"
|
||||
self._errors["date"] = self.error_class([msg])
|
||||
del data["date"]
|
||||
else:
|
||||
data["date"] = str(dobj)
|
||||
del data["text"]
|
||||
return data
|
||||
|
||||
def save(self, commit=True):
|
||||
@ -165,12 +148,12 @@ class EventForm(forms.ModelForm):
|
||||
from webapp.libdjango import DjangoInterface
|
||||
dji = DjangoInterface()
|
||||
model = super(EventForm, self).save(commit=False)
|
||||
dobj = dp(self.cleaned_data['date'])
|
||||
dobj = dp(self.cleaned_data['text'])
|
||||
dji.add_date(model, dobj.serialize())
|
||||
if commit:
|
||||
model.save()
|
||||
return model
|
||||
|
||||
date = forms.CharField(label="Date",
|
||||
text = forms.CharField(label="Date",
|
||||
required=False,
|
||||
widget=TextInput(attrs={'size':'30'}))
|
||||
widget=TextInput(attrs={'size':'45'}))
|
||||
|
@ -26,7 +26,7 @@ from webapp.utils import _, boolean, update_last_changed
|
||||
from webapp.grampsdb.models import Event
|
||||
from webapp.grampsdb.forms import *
|
||||
from webapp.libdjango import DjangoInterface
|
||||
import DateHandler
|
||||
from gen.datehandler import displayer, parser
|
||||
|
||||
## Django Modules
|
||||
from django.shortcuts import get_object_or_404, render_to_response, redirect
|
||||
@ -34,8 +34,8 @@ from django.template import Context, RequestContext
|
||||
|
||||
## Globals
|
||||
dji = DjangoInterface()
|
||||
dd = DateHandler.displayer.display
|
||||
dp = DateHandler.parser.parse
|
||||
dd = displayer.display
|
||||
dp = parser.parse
|
||||
|
||||
def process_event(request, context, handle, action): # view, edit, save
|
||||
"""
|
||||
|
@ -11,13 +11,12 @@ from webapp.grampsdb.forms import *
|
||||
from webapp.dbdjango import DbDjango
|
||||
from webapp.reports import import_file
|
||||
from webapp.libdjango import DjangoInterface, totime, todate
|
||||
|
||||
import DateHandler
|
||||
from gen.datehandler import displayer, parser
|
||||
|
||||
db = DbDjango()
|
||||
dji = DjangoInterface()
|
||||
dd = DateHandler.displayer.display
|
||||
dp = DateHandler.parser.parse
|
||||
dd = displayer.display
|
||||
dp = parser.parse
|
||||
|
||||
#def Print(m):
|
||||
# print m
|
||||
|
@ -56,7 +56,7 @@ from webapp.dbdjango import DbDjango
|
||||
from Simple import SimpleTable, SimpleAccess, make_basic_stylesheet
|
||||
import Utils
|
||||
import DbState
|
||||
import gen.datehandler
|
||||
from gen.datehandler import displayer, parser
|
||||
from gen.lib.date import Date as GDate, Today
|
||||
import gen.lib
|
||||
from gen.utils import get_birth_or_fallback, get_death_or_fallback
|
||||
@ -97,8 +97,8 @@ util_tags = [
|
||||
#
|
||||
#------------------------------------------------------------------------
|
||||
dji = libdjango.DjangoInterface()
|
||||
dd = DateHandler.displayer.display
|
||||
dp = DateHandler.parser.parse
|
||||
dd = displayer.display
|
||||
dp = parser.parse
|
||||
db = DbDjango()
|
||||
|
||||
def register_plugins():
|
||||
|
Loading…
Reference in New Issue
Block a user