File tree Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Expand file tree Collapse file tree 3 files changed +14
-9
lines changed Original file line number Diff line number Diff line change 22from django .contrib .auth import login as auth_login
33from django .http import HttpResponseRedirect
44
5+ from .utils import is_ajax
6+
57
68class PassRequestMixin (object ):
79 """
@@ -38,8 +40,7 @@ class CreateUpdateAjaxMixin(object):
3840 """
3941
4042 def save (self , commit = True ):
41- # if not self.request.is_ajax() or self.request.POST.get('closeOnSubmit') == 'False':
42- if not self .request .is_ajax () or self .request .POST .get ('asyncUpdate' ) == 'True' :
43+ if not is_ajax (self .request .META ) or self .request .POST .get ('asyncUpdate' ) == 'True' :
4344 instance = super (CreateUpdateAjaxMixin , self ).save (commit = commit )
4445 else :
4546 instance = super (CreateUpdateAjaxMixin , self ).save (commit = False )
@@ -66,7 +67,7 @@ class LoginAjaxMixin(object):
6667 """
6768
6869 def form_valid (self , form ):
69- if not self .request .is_ajax ( ):
70+ if not is_ajax ( self .request .META ):
7071 auth_login (self .request , form .get_user ())
7172 messages .success (self .request , self .success_message )
72- return HttpResponseRedirect (self .get_success_url ())
73+ return HttpResponseRedirect (self .get_success_url ())
Original file line number Diff line number Diff line change 1+ def is_ajax (meta ):
2+ if 'HTTP_X_REQUESTED_WITH' not in meta :
3+ return False
4+
5+ if meta ['HTTP_X_REQUESTED_WITH' ] == 'XMLHttpRequest' :
6+ return True
7+
8+ return False
Original file line number Diff line number Diff line change @@ -30,7 +30,7 @@ def test_signup_login(self):
3030
3131 # User sees error in form
3232 error = self .wait_for (class_name = 'help-block' )
33- self .assertEqual (error .text , 'The two password fields didn\' t match.' )
33+ self .assertEqual (error .text , 'The two password fields didn’ t match.' )
3434
3535 # User fills in and submits sign up form correctly
3636 form = modal .find_element_by_tag_name ('form' )
@@ -278,10 +278,6 @@ def test_delete_object(self):
278278 alert = self .wait_for (class_name = 'alert' )
279279 self .assertEqual (alert .text [:- 2 ], 'Success: Book was deleted.' )
280280
281- # User sees 'No books added yet.'
282- no_books = self .browser .find_element_by_class_name ('no-books' )
283- self .assertEqual (no_books .text , 'No books added yet.' )
284-
285281 # There is no books in database anymore
286282 books = Book .objects .all ()
287283 self .assertEqual (books .count (), 0 )
You can’t perform that action at this time.
0 commit comments