Skip to content
This repository has been archived by the owner on Feb 1, 2020. It is now read-only.

Commit

Permalink
Remove action_args dict
Browse files Browse the repository at this point in the history
The views were defining action_args dictionaries and only using a string
inside it. I've removed the dictionaries since only the string is
needed.
  • Loading branch information
nikolas committed Apr 26, 2017
1 parent aaaf092 commit 3b26f0e
Show file tree
Hide file tree
Showing 2 changed files with 60 additions and 89 deletions.
26 changes: 12 additions & 14 deletions uelc/main/tests/test_views.py
Expand Up @@ -209,8 +209,8 @@ def test_uelc_admin_create_already_existing_hierarchy(self):
self.assertEqual(response.status_code, 200)
m = list(response.context['messages'])
self.assertEqual(len(m), 1)
tmp_stg = "Hierarchy exists! Please use the exisiting one,\
or create one with a different name and url."
tmp_stg = ("Hierarchy exists! Please use the exisiting one, "
"or create one with a different name and url.")
er_msg = str(m[0])
self.assertEqual(tmp_stg.strip(), er_msg.strip())

Expand Down Expand Up @@ -461,8 +461,7 @@ def test_uelc_admin_delete_superuser(self):
self.assertEqual(response.status_code, 200)
m = list(response.context['messages'])
self.assertEqual(len(m), 1)
tmp_stg = "Sorry, you are not permitted to \
delete superuser accounts."
tmp_stg = "Sorry, you are not permitted to delete superuser accounts."
er_msg = str(m[0])
self.assertEqual(tmp_stg.strip(), er_msg.strip())

Expand Down Expand Up @@ -544,8 +543,8 @@ def test_admin_create_case_no_duplicate_names(self):
m = list(response2.context['messages'])
self.assertEqual(len(m), 1)
self.assertEqual(len(list(response2.context['messages'])), 1)
tmp_stg = 'Case with this name already exists!' + \
' Please use existing case or rename.'
tmp_stg = ('Case with this name already exists! '
'Please use existing case or rename.')
er_msg = str(m[0]).strip()
self.assertEqual(tmp_stg.strip(), er_msg)

Expand Down Expand Up @@ -573,12 +572,11 @@ def test_admin_create_case_no_case_for_hierarchy(self):
self.assertRedirects(response2, '/uelcadmin/')
m = list(response2.context['messages'])
self.assertEqual(len(m), 1)
tmp_stg = (
'Case already exists! A case has already' +
' been created that is attached to the' +
' selected hierarchy. Do you need to create' +
' another hierarchy or should you use' +
' an existing case?')
tmp_stg = ('Case already exists! A case has already '
'been created that is attached to the '
'selected hierarchy. Do you need to create '
'another hierarchy or should you use '
'an existing case?')
er_msg = str(m[0])
self.assertEqual(tmp_stg.strip(), er_msg.strip())

Expand All @@ -600,8 +598,8 @@ def test_admin_edit_case_case_for_hierarchy_exists(self):
self.assertRedirects(response, '/uelcadmin/')
m = list(response.context['messages'])
self.assertEqual(len(m), 1)
tmp_stg = 'Case with this name already exists!' + \
' Please use existing case or rename.'
tmp_stg = ('Case with this name already exists! '
'Please use existing case or rename.')
er_msg = str(m[0])
self.assertEqual(tmp_stg.strip(), er_msg.strip())

Expand Down
123 changes: 48 additions & 75 deletions uelc/main/views.py
Expand Up @@ -102,22 +102,18 @@ def root_section_check(self, section, next_section):

if not self.request.user.profile.is_group_user():
# then root has no children yet
action_args = dict(
error="You just tried accessing a case that has \
no content. You have been forwarded over \
to the root page of the case so that you \
can and add some content if you wish to.")
messages.error(self.request, action_args['error'],
extra_tags='rootUrlError')
error = ("You just tried accessing a case that has "
"no content. You have been forwarded over "
"to the root page of the case so that you "
"can and add some content if you wish to.")
messages.error(self.request, error, extra_tags='rootUrlError')
path = section.hierarchy.base_url + 'edit/'
else:
action_args = dict(
error="For some reason the case you tried to \
access does not have any content yet. \
Please choose another case, or alert \
your facilitator.")
messages.error(self.request, action_args['error'],
extra_tags='rootUrlError')
error = ("For some reason the case you tried to "
"access does not have any content yet. "
"Please choose another case, or alert "
"your facilitator.")
messages.error(self.request, error, extra_tags='rootUrlError')
path = self.no_root_fallback_url
return HttpResponseRedirect(path)

Expand Down Expand Up @@ -603,11 +599,9 @@ def post(self, request):
if not user.is_superuser:
user.delete()
else:
action_args = dict(
error="Sorry, you are not permitted to \
delete superuser accounts.")
messages.error(request, action_args['error'],
extra_tags='deleteSuperUser')
error = ("Sorry, you are not permitted to "
"delete superuser accounts.")
messages.error(request, error, extra_tags='deleteSuperUser')
url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)

Expand Down Expand Up @@ -680,10 +674,8 @@ def post(self, request, pk):
password = request.POST.get('newPassword1', '')
user.set_password(password)
user.save()
action_args = dict(
success="User password has been updated!")
messages.success(request, action_args['success'],
extra_tags='userPasswordSuccess')
success = "User password has been updated!"
messages.success(request, success, extra_tags='userPasswordSuccess')
return HttpResponseRedirect(reverse('uelcadmin'))


Expand All @@ -698,10 +690,9 @@ def post(self, request):
hier = Hierarchy.objects.filter(Q(base_url=url) | Q(name=name))

if hier.exists():
action_args = dict(
error="Hierarchy exists! Please use the exisiting one,\
or create one with a different name and url.")
messages.error(request, action_args['error'],
error = ("Hierarchy exists! Please use the exisiting one, "
"or create one with a different name and url.")
messages.error(request, error,
extra_tags='createCaseViewError')
url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)
Expand Down Expand Up @@ -785,12 +776,10 @@ def post(self, request):
cohort = Cohort.objects.create(name=name)
cohort.save()
except IntegrityError:
action_args = dict(
error="A cohort with that name already exists!\
Please change the name,\
or use the existing cohort.")
messages.error(request, action_args['error'],
extra_tags='createCohortViewError')
error = ("A cohort with that name already exists! "
"Please change the name, "
"or use the existing cohort.")
messages.error(request, error, extra_tags='createCohortViewError')

url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)
Expand Down Expand Up @@ -853,12 +842,10 @@ def post(self, request, pk):
user.profile.save()

except IntegrityError:
action_args = dict(
error="A cohort with that name already exists!\
Please change the name,\
or use the existing cohort.")
messages.error(request, action_args['error'],
extra_tags='editCohortViewError')
error = ("A cohort with that name already exists! "
"Please change the name, "
"or use the existing cohort.")
messages.error(request, error, extra_tags='editCohortViewError')

url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)
Expand All @@ -877,30 +864,23 @@ def post(self, request):
case_exists_name = Case.objects.filter(name=name)
case_exists_hier = Case.objects.filter(hierarchy=hierarchy)
if case_exists_name.exists():
action_args = dict(
error="Case with this name already exists!\
Please use existing case or rename.")
messages.error(request, action_args['error'],
extra_tags='createCaseViewError')
error = ("Case with this name already exists! "
"Please use existing case or rename.")
messages.error(request, error, extra_tags='createCaseViewError')
url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)
if case_exists_hier.exists():
action_args = dict(
error="Case already exists! A case has already\
been created that is attached to the\
selected hierarchy. Do you need to create\
another hierarchy or should you use\
an existing case?")
messages.error(request, action_args['error'],
extra_tags='createCaseViewError')
error = ("Case already exists! A case has already "
"been created that is attached to the "
"selected hierarchy. Do you need to create "
"another hierarchy or should you use "
"an existing case?")
messages.error(request, error, extra_tags='createCaseViewError')
url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)
if hierarchy == "" or cohort == "":
action_args = dict(
error="Please make sure a hierarchy and\
cohort is selected")
messages.error(request, action_args['error'],
extra_tags='createCaseViewError')
error = "Please make sure a hierarchy and cohort is selected"
messages.error(request, error, extra_tags='createCaseViewError')
url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)

Expand Down Expand Up @@ -941,30 +921,23 @@ def post(self, request):
case_id = request.POST.get('case_id', '')

if case_exists_name.count() > 1:
action_args = dict(
error="Case with this name already exists!\
Please use existing case or rename.")
messages.error(request, action_args['error'],
extra_tags='createCaseViewError')
error = ("Case with this name already exists! "
"Please use existing case or rename.")
messages.error(request, error, extra_tags='createCaseViewError')
url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)
if case_exists_hier.count() > 1:
action_args = dict(
error="Case already exists! A case has already\
been created that is attached to the\
selected hierarchy. Do you need to create\
another hierarchy or should you use\
an existing case?")
messages.error(request, action_args['error'],
extra_tags='createCaseViewError')
error = ("Case already exists! A case has already "
"been created that is attached to the "
"selected hierarchy. Do you need to create "
"another hierarchy or should you use "
"an existing case?")
messages.error(request, error, extra_tags='createCaseViewError')
url = request.META.get('HTTP_REFERER')
return HttpResponseRedirect(url)
if hierarchy == "" or cohorts == "":
action_args = dict(
error="Please make sure a hierarchy and\
cohort is selected")
messages.error(request, action_args['error'],
extra_tags='createCaseViewError')
error = "Please make sure a hierarchy and cohort is selected"
messages.error(request, error, extra_tags='createCaseViewError')
return HttpResponseRedirect('/uelcadmin/')

coh_obj = Cohort.objects.filter(id__in=cohorts)
Expand Down

0 comments on commit 3b26f0e

Please sign in to comment.