@@ -179,7 +179,7 @@ def get_stream_mapping():
179179@django .db .transaction .commit_on_success
180180def insert_to_databaseREDESIGN (data ):
181181 from ietf .person .models import Person
182- from ietf .doc .models import Document , DocAlias , DocEvent , RelatedDocument , State
182+ from ietf .doc .models import Document , DocAlias , DocEvent , RelatedDocument , State , save_document_in_history
183183 from ietf .group .models import Group
184184 from ietf .name .models import DocTagName , DocRelationshipName
185185 from ietf .name .utils import name
@@ -233,26 +233,24 @@ def insert_to_databaseREDESIGN(data):
233233
234234
235235 # check attributes
236- changed = False
236+ changed_attributes = {}
237+ changed_states = []
238+ created_relations = []
239+ other_changes = False
237240 if title != doc .title :
238- doc .title = title
239- changed = True
241+ changed_attributes ["title" ] = title
240242
241243 if std_level_mapping [current_status ] != doc .std_level :
242- doc .std_level = std_level_mapping [current_status ]
243- changed = True
244+ changed_attributes ["std_level" ] = std_level_mapping [current_status ]
244245
245246 if doc .get_state_slug () != "rfc" :
246- doc .set_state (State .objects .get (type = "draft" , slug = "rfc" ))
247- changed = True
247+ changed_states .append (State .objects .get (type = "draft" , slug = "rfc" ))
248248
249249 if doc .stream != stream_mapping [stream ]:
250- doc .stream = stream_mapping [stream ]
251- changed = True
250+ changed_attributes ["stream" ] = stream_mapping [stream ]
252251
253252 if not doc .group and wg :
254- doc .group = Group .objects .get (acronym = wg )
255- changed = True
253+ changed_attributes ["group" ] = Group .objects .get (acronym = wg )
256254
257255 pubdate = datetime .strptime (rfc_published_date , "%Y-%m-%d" )
258256 if not doc .latest_event (type = "published_rfc" , time = pubdate ):
@@ -261,7 +259,10 @@ def insert_to_databaseREDESIGN(data):
261259 e .by = system
262260 e .desc = "RFC published"
263261 e .save ()
264- changed = True
262+ other_changes = True
263+
264+ if doc .get_state_slug ("draft-iesg" ) == "rfcqueue" :
265+ changed_states .append (State .objects .get (type = "draft-iesg" , slug = "pub" ))
265266
266267 def parse_relation_list (s ):
267268 if not s :
@@ -282,35 +283,43 @@ def parse_relation_list(s):
282283
283284 for x in parse_relation_list (obsoletes ):
284285 if not RelatedDocument .objects .filter (source = doc , target = x , relationship = relationship_obsoletes ):
285- RelatedDocument .objects .create (source = doc , target = x , relationship = relationship_obsoletes )
286- changed = True
287-
286+ created_relations .append (RelatedDocument (source = doc , target = x , relationship = relationship_obsoletes ))
287+
288288 for x in parse_relation_list (updates ):
289289 if not RelatedDocument .objects .filter (source = doc , target = x , relationship = relationship_updates ):
290- RelatedDocument .objects .create (source = doc , target = x , relationship = relationship_updates )
291- changed = True
292-
290+ created_relations .append (RelatedDocument (source = doc , target = x , relationship = relationship_updates ))
291+
293292 if also :
294293 for a in also .lower ().split ("," ):
295294 if not DocAlias .objects .filter (name = a ):
296295 DocAlias .objects .create (name = a , document = doc )
297- changed = True
296+ other_changes = True
298297
299298 if has_errata :
300299 if not doc .tags .filter (pk = tag_has_errata .pk ):
301- doc .tags .add (tag_has_errata )
302- changed = True
300+ changed_attributes ["tags" ] = list (doc .tags .all ()) + [tag_has_errata ]
303301 else :
304302 if doc .tags .filter (pk = tag_has_errata .pk ):
305- doc .tags .remove (tag_has_errata )
306- changed = True
303+ changed_attributes ["tags" ] = set (doc .tags .all ()) - set ([tag_has_errata ])
304+
305+ if changed_attributes or changed_states or created_relations or other_changes :
306+ # apply changes
307+ save_document_in_history (doc )
308+ for k , v in changed_attributes .iteritems ():
309+ setattr (doc , k , v )
310+
311+ for s in changed_states :
312+ doc .set_state (s )
313+
314+ for o in created_relations :
315+ o .save ()
307316
308- if changed :
309- if not created :
310- log ("%s changed" % name )
311317 doc .time = datetime .now ()
312318 doc .save ()
313-
319+
320+ if not created :
321+ log ("%s changed" % name )
322+
314323
315324if settings .USE_DB_REDESIGN_PROXY_CLASSES :
316325 insert_to_database = insert_to_databaseREDESIGN
0 commit comments