formdata: keep link from evolution objects to related formdata (#17601)
This commit is contained in:
parent
a0e5a686f6
commit
98b74edd3f
|
@ -135,6 +135,13 @@ class Evolution(object):
|
||||||
comment = None
|
comment = None
|
||||||
parts = None
|
parts = None
|
||||||
|
|
||||||
|
def __init__(self, formdata=None):
|
||||||
|
self._formdata = formdata # formdata cache
|
||||||
|
|
||||||
|
@property
|
||||||
|
def formdata(self):
|
||||||
|
return self._formdata
|
||||||
|
|
||||||
def get_author_name(self):
|
def get_author_name(self):
|
||||||
if self.who == '_submitter':
|
if self.who == '_submitter':
|
||||||
return _('Original Submitter')
|
return _('Original Submitter')
|
||||||
|
@ -182,6 +189,13 @@ class Evolution(object):
|
||||||
data['parts'] = parts
|
data['parts'] = parts
|
||||||
return data
|
return data
|
||||||
|
|
||||||
|
# don't pickle _formata cache
|
||||||
|
def __getstate__(self):
|
||||||
|
odict = self.__dict__.copy()
|
||||||
|
if odict.has_key('_formdata'):
|
||||||
|
del odict['_formdata']
|
||||||
|
return odict
|
||||||
|
|
||||||
|
|
||||||
class FormData(StorableObject):
|
class FormData(StorableObject):
|
||||||
_names = 'XX'
|
_names = 'XX'
|
||||||
|
@ -231,6 +245,7 @@ class FormData(StorableObject):
|
||||||
changed = True
|
changed = True
|
||||||
if self.evolution:
|
if self.evolution:
|
||||||
for evo in self.evolution:
|
for evo in self.evolution:
|
||||||
|
evo._formdata = self # link from evolution to formdata
|
||||||
if evo.status and not evo.status.startswith('wf-'):
|
if evo.status and not evo.status.startswith('wf-'):
|
||||||
evo.status = 'wf-%s' % evo.status
|
evo.status = 'wf-%s' % evo.status
|
||||||
changed = True
|
changed = True
|
||||||
|
@ -314,7 +329,7 @@ class FormData(StorableObject):
|
||||||
# we add the initial status to the history, this makes it more readable
|
# we add the initial status to the history, this makes it more readable
|
||||||
# afterwards (also this gets the (previous_status) code to work in all
|
# afterwards (also this gets the (previous_status) code to work in all
|
||||||
# cases)
|
# cases)
|
||||||
evo = Evolution()
|
evo = Evolution(self)
|
||||||
evo.who = '_submitter'
|
evo.who = '_submitter'
|
||||||
evo.time = self.receipt_time
|
evo.time = self.receipt_time
|
||||||
evo.status = self.status
|
evo.status = self.status
|
||||||
|
@ -469,7 +484,7 @@ class FormData(StorableObject):
|
||||||
previous_status = self.pop_previous_marked_status()
|
previous_status = self.pop_previous_marked_status()
|
||||||
assert previous_status, 'failed to compute previous status'
|
assert previous_status, 'failed to compute previous status'
|
||||||
status_id = previous_status.id
|
status_id = previous_status.id
|
||||||
evo = Evolution()
|
evo = Evolution(self)
|
||||||
evo.time = time.localtime()
|
evo.time = time.localtime()
|
||||||
evo.status = 'wf-%s' % status_id
|
evo.status = 'wf-%s' % status_id
|
||||||
if not self.evolution:
|
if not self.evolution:
|
||||||
|
|
|
@ -1130,14 +1130,14 @@ class SqlFormData(SqlMixin, wcs.formdata.FormData):
|
||||||
row = cur.fetchone()
|
row = cur.fetchone()
|
||||||
if row is None:
|
if row is None:
|
||||||
break
|
break
|
||||||
self._evolution.append(self._row2evo(row))
|
self._evolution.append(self._row2evo(row, formdata=self))
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cur.close()
|
cur.close()
|
||||||
return self._evolution
|
return self._evolution
|
||||||
|
|
||||||
@classmethod
|
@classmethod
|
||||||
def _row2evo(cls, row):
|
def _row2evo(cls, row, formdata):
|
||||||
o = wcs.formdata.Evolution()
|
o = wcs.formdata.Evolution(formdata)
|
||||||
o._sql_id, o.who, o.status, o.time, o.comment = [str_encode(x) for x in tuple(row[:5])]
|
o._sql_id, o.who, o.status, o.time, o.comment = [str_encode(x) for x in tuple(row[:5])]
|
||||||
if o.time:
|
if o.time:
|
||||||
o.time = o.time.timetuple()
|
o.time = o.time.timetuple()
|
||||||
|
@ -1179,7 +1179,7 @@ class SqlFormData(SqlMixin, wcs.formdata.FormData):
|
||||||
formdata = object_dict.get(formdata_id)
|
formdata = object_dict.get(formdata_id)
|
||||||
if not formdata:
|
if not formdata:
|
||||||
continue
|
continue
|
||||||
formdata._evolution.append(formdata._row2evo(row))
|
formdata._evolution.append(formdata._row2evo(row, formdata))
|
||||||
|
|
||||||
conn.commit()
|
conn.commit()
|
||||||
cur.close()
|
cur.close()
|
||||||
|
|
Loading…
Reference in New Issue