Ticket #2227: django-20060703-nested_transactions.diff
File django-20060703-nested_transactions.diff, 4.9 KB (added by , 18 years ago) |
---|
-
django/db/transaction.py
This patch is a cruded attemt to make @commit_on_success support nested transactions. See http://code.djangoproject.com/ticket/2227 for an explanation why this is usefull. --md@hudora.de
187 187 control in web apps. 188 188 """ 189 189 def _commit_on_success(*args, **kw): 190 try:191 enter_transaction_management()192 managed(True)190 # only use transactions if we don't have already an ongoing transaction 191 thread_ident = thread.get_ident() 192 if thread_ident not in state or state[thread_ident] == []: 193 193 try: 194 res = func(*args, **kw) 195 except Exception, e: 196 if is_dirty(): 197 rollback() 198 raise 199 else: 200 if is_dirty(): 201 commit() 202 return res 203 finally: 204 leave_transaction_management() 194 enter_transaction_management() 195 managed(True) 196 try: 197 res = func(*args, **kw) 198 except Exception, e: 199 if is_dirty(): 200 rollback() 201 raise 202 else: 203 if is_dirty(): 204 commit() 205 return res 206 finally: 207 leave_transaction_management() 208 else: 209 return func(*args, **kw) 205 210 return _commit_on_success 206 211 207 212 def commit_manually(func): -
django/core/management.py
286 286 for klass in app_models: 287 287 if cursor and klass._meta.db_table in table_names: 288 288 # Drop the table now 289 output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'),290 style.SQL_TABLE(backend.quote_name(klass._meta.db_table))))291 289 if backend.supports_constraints and references_to_delete.has_key(klass): 292 290 for rel_class, f in references_to_delete[klass]: 293 291 table = rel_class._meta.db_table … … 300 298 style.SQL_KEYWORD(backend.get_drop_foreignkey_sql()), 301 299 style.SQL_FIELD(backend.quote_name("%s_referencing_%s_%s" % (col, r_table, r_col))))) 302 300 del references_to_delete[klass] 301 output.append('%s %s;' % (style.SQL_KEYWORD('DROP TABLE'), 302 style.SQL_TABLE(backend.quote_name(klass._meta.db_table)))) 303 303 304 304 # Output DROP TABLE statements for many-to-many tables. 305 305 for klass in app_models: -
django/contrib/comments/views/comments.py
252 252 else: 253 253 manipulator.do_html2python(new_data) 254 254 comment = manipulator.save(new_data) 255 return HttpResponseRedirect("../posted/?c=%s:%s " % (content_type_id, object_id))255 return HttpResponseRedirect("../posted/?c=%s:%s&ic=%s" % (content_type_id, object_id, comment.id)) 256 256 else: 257 257 raise Http404, _("The comment form didn't provide either 'preview' or 'post'") 258 258 … … 316 316 else: 317 317 manipulator.do_html2python(new_data) 318 318 comment = manipulator.save(new_data) 319 return HttpResponseRedirect("../posted/?c=%s:%s " % (content_type_id, object_id))319 return HttpResponseRedirect("../posted/?c=%s:%s&if=%s" % (content_type_id, object_id, comment.id)) 320 320 else: 321 321 raise Http404, _("The comment form didn't provide either 'preview' or 'post'") 322 322 … … 330 330 The object the comment was posted on 331 331 """ 332 332 obj = None 333 comment = None 333 334 if request.GET.has_key('c'): 334 335 content_type_id, object_id = request.GET['c'].split(':') 335 336 try: … … 337 338 obj = content_type.get_object_for_this_type(pk=object_id) 338 339 except ObjectDoesNotExist: 339 340 pass 340 return render_to_response('comments/posted.html', {'object': obj}, context_instance=RequestContext(request)) 341 try: 342 comment_id = request.GET['if'] 343 comment = FreeComment.objects.get(pk=comment_id) 344 except ObjectDoesNotExist: 345 pass 346 try: 347 comment_id = request.GET['ic'] 348 comment = Comment.objects.get(pk=comment_id) 349 except ObjectDoesNotExist: 350 pass 351 return render_to_response('comments/posted.html', {'object': obj, 'comment': comment}, context_instance=RequestContext(request))