Skip to content

Commit

Permalink
Fixed problem where errors caused redirects to root above /bechdel
Browse files Browse the repository at this point in the history
  • Loading branch information
shannonturner committed May 27, 2014
1 parent 392e9ba commit a2e30f4
Showing 1 changed file with 7 additions and 7 deletions.
14 changes: 7 additions & 7 deletions apps/bechdel/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -41,12 +41,12 @@ def post(self, request, **kwargs):

if not query:
messages.error(request, 'Please enter your search.')
return HttpResponseRedirect('/')
return HttpResponseRedirect('/bechdel')
else:
if not ''.join([q for q in query if q.isalpha() or q.isdigit()]):
# Eliminate other bad queries
messages.error(request, 'Please enter your search.')
return HttpResponseRedirect('/')
return HttpResponseRedirect('/bechdel')

query = query.replace("'", ''')

Expand Down Expand Up @@ -75,7 +75,7 @@ def post(self, request, **kwargs):
'''An error occurred while searching the Bechdel Test API for {0}.
Please try again.'''.format(query)
)
return HttpResponseRedirect('/')
return HttpResponseRedirect('/bechdel')

if direct_lookup:
# Direct Lookup returns JSON, title search returns a list of items
Expand All @@ -87,7 +87,7 @@ def post(self, request, **kwargs):
Either the movie does not exist in the Bechdel Test API database,
or your search was too complex. Please try again.
'''.format(query))
return HttpResponseRedirect('/')
return HttpResponseRedirect('/bechdel')
else:
# Loop through each response item, add to database
for movie in bechdel_response:
Expand Down Expand Up @@ -128,7 +128,7 @@ def post(self, request, **kwargs):
movie = Movie.objects.get(imdb_id=bechdel_response[0].get('imdbid'))
except ObjectDoesNotExist:
messages.error(request, 'An error occurred. Please try your search again.')
return HttpResponseRedirect('/')
return HttpResponseRedirect('/bechdel')
else:
return HttpResponseRedirect('/bechdel/movie/{0}'.format(movie.id))
elif len(bechdel_response) > 1:
Expand Down Expand Up @@ -174,13 +174,13 @@ def get(self, request, **kwargs):
movie_id = int(kwargs.get('id'))
except (ValueError, TypeError):
messages.error(request, 'Invalid movie ID: {0}, please try again.'.format(request.GET.get('id')))
return HttpResponseRedirect('/')
return HttpResponseRedirect('/bechdel')

try:
movie = Movie.objects.get(id=movie_id)
except ObjectDoesNotExist:
messages.error(request, 'Movie ID #{0} not found in our system, please try again.'.format(movie_id))
return HttpResponseRedirect('/')
return HttpResponseRedirect('/bechdel')

context = self.get_context_data(**{'id': movie_id,
'movie': movie,
Expand Down

0 comments on commit a2e30f4

Please sign in to comment.