Skip to content
Snippets Groups Projects
Commit f55c9b79 authored by Piotr Gawron's avatar Piotr Gawron
Browse files

id changed to subject_id

parent 205dddbe
No related branches found
No related tags found
1 merge request!350Additional pylint checks
...@@ -29,7 +29,7 @@ class ContactAttemptViewTests(LoggedInWithWorkerTestCase): ...@@ -29,7 +29,7 @@ class ContactAttemptViewTests(LoggedInWithWorkerTestCase):
response = self.client.post( response = self.client.post(
reverse('web.views.contact_add', kwargs={'subject_id': subject.id}), data=form_data) reverse('web.views.contact_add', kwargs={'subject_id': subject.id}), data=form_data)
# check correct redirection to subject edit page # check correct redirection to subject edit page
self.assertRedirects(response, reverse('web.views.subject_edit', kwargs={'id': subject.id})) self.assertRedirects(response, reverse('web.views.subject_edit', kwargs={'subject_id': subject.id}))
contact_attempts = ContactAttempt.objects.filter(subject=subject).all() contact_attempts = ContactAttempt.objects.filter(subject=subject).all()
self.assertEqual(1, len(contact_attempts)) self.assertEqual(1, len(contact_attempts))
contact_attempt = contact_attempts[0] contact_attempt = contact_attempts[0]
...@@ -82,9 +82,10 @@ class ContactAttemptViewTests(LoggedInWithWorkerTestCase): ...@@ -82,9 +82,10 @@ class ContactAttemptViewTests(LoggedInWithWorkerTestCase):
response = self.client.post( response = self.client.post(
reverse('web.views.contact_edit', reverse('web.views.contact_edit',
kwargs={'subject_id': contact_attempt.subject.id, 'contact_attempt_id': contact_attempt.id}), kwargs={'subject_id': contact_attempt.subject.id, 'contact_attempt_id': contact_attempt.id}),
data=form_data) data=form_data,
follow=True)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 200)
def test_contact_attempt_edit_from_appointment(self): def test_contact_attempt_edit_from_appointment(self):
contact_attempt = create_contact_attempt() contact_attempt = create_contact_attempt()
......
...@@ -34,7 +34,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -34,7 +34,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_render_subject_edit(self): def test_render_subject_edit(self):
response = self.client.get(reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id})) response = self.client.get(reverse('web.views.subject_edit', kwargs={'subject_id': self.study_subject.id}))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
def test_render_subject_edit_with_mail_templates(self): def test_render_subject_edit_with_mail_templates(self):
...@@ -47,7 +47,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -47,7 +47,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
MailTemplate(name=template_name, language=language, context=MAIL_TEMPLATE_CONTEXT_SUBJECT, MailTemplate(name=template_name, language=language, context=MAIL_TEMPLATE_CONTEXT_SUBJECT,
template_file=template_file).save() template_file=template_file).save()
response = self.client.get(reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id})) response = self.client.get(reverse('web.views.subject_edit', kwargs={'subject_id': self.study_subject.id}))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue(template_name.encode('utf8') in response.content) self.assertTrue(template_name.encode('utf8') in response.content)
...@@ -70,7 +70,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -70,7 +70,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data['subject-dead'] = "True" form_data['subject-dead'] = "True"
form_data['study_subject-resigned'] = "True" form_data['study_subject-resigned'] = "True"
response = self.client.post( response = self.client.post(
reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id}), data=form_data) reverse('web.views.subject_edit', kwargs={'subject_id': self.study_subject.id}), data=form_data)
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
self.assertTrue("Resign reason cannot be empty".encode('utf8') in response.content) self.assertTrue("Resign reason cannot be empty".encode('utf8') in response.content)
...@@ -87,7 +87,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -87,7 +87,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data['study_subject-endpoint_reached'] = "True" form_data['study_subject-endpoint_reached'] = "True"
response = self.client.post( response = self.client.post(
reverse('web.views.subject_edit', kwargs={'id': study_subject.id}), data=form_data) reverse('web.views.subject_edit', kwargs={'subject_id': study_subject.id}), data=form_data)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
updated_study_subject = StudySubject.objects.filter(id=study_subject.id)[0] updated_study_subject = StudySubject.objects.filter(id=study_subject.id)[0]
...@@ -108,7 +108,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -108,7 +108,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data['study_subject-resigned'] = "True" form_data['study_subject-resigned'] = "True"
form_data['study_subject-resign_reason'] = "Doesn't want to participate" form_data['study_subject-resign_reason'] = "Doesn't want to participate"
response = self.client.post( response = self.client.post(
reverse('web.views.subject_edit', kwargs={'id': study_subject.id}), data=form_data) reverse('web.views.subject_edit', kwargs={'subject_id': study_subject.id}), data=form_data)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
updated_study_subject = StudySubject.objects.filter(id=study_subject.id)[0] updated_study_subject = StudySubject.objects.filter(id=study_subject.id)[0]
...@@ -123,7 +123,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -123,7 +123,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data['study_subject-resigned'] = "True" form_data['study_subject-resigned'] = "True"
form_data['study_subject-resign_reason'] = "doesn't want to participate" form_data['study_subject-resign_reason'] = "doesn't want to participate"
url = reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id}) url = reverse('web.views.subject_edit', kwargs={'subject_id': self.study_subject.id})
response = self.client.post(url, data=form_data) response = self.client.post(url, data=form_data)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
...@@ -135,11 +135,11 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -135,11 +135,11 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
form_data = self.create_edit_form_data_for_study_subject() form_data = self.create_edit_form_data_for_study_subject()
form_data['_continue'] = True form_data['_continue'] = True
response = self.client.post(reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id}), response = self.client.post(reverse('web.views.subject_edit', kwargs={'subject_id': self.study_subject.id}),
data=form_data) data=form_data,
follow=True)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 200)
self.assertTrue("edit" in response.url)
def test_delete_subject(self): def test_delete_subject(self):
self.login_as_super() self.login_as_super()
...@@ -240,7 +240,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -240,7 +240,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
subject = StudySubject.objects.all().order_by("-id")[0] subject = StudySubject.objects.all().order_by("-id")[0]
# check if edit page renders properly # check if edit page renders properly
response = self.client.get(reverse('web.views.subject_edit', kwargs={'id': subject.id})) response = self.client.get(reverse('web.views.subject_edit', kwargs={'subject_id': subject.id}))
self.assertEqual(response.status_code, 200) self.assertEqual(response.status_code, 200)
# check if file can be downloaded # check if file can be downloaded
...@@ -350,7 +350,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase): ...@@ -350,7 +350,7 @@ class SubjectsViewTests(LoggedInWithWorkerTestCase):
count = Provenance.objects.all().count() count = Provenance.objects.all().count()
form_data["study_subject-type"] = get_patient_subject_type().id form_data["study_subject-type"] = get_patient_subject_type().id
response = self.client.post( response = self.client.post(
reverse('web.views.subject_edit', kwargs={'id': self.study_subject.id}), data=form_data) reverse('web.views.subject_edit', kwargs={'subject_id': self.study_subject.id}), data=form_data)
self.assertEqual(response.status_code, 302) self.assertEqual(response.status_code, 302)
......
...@@ -89,7 +89,7 @@ urlpatterns = [ ...@@ -89,7 +89,7 @@ urlpatterns = [
url(r'^study/(?P<study_id>\d+)/subjects/add$', views.subject.subject_add, name='web.views.subject_add'), url(r'^study/(?P<study_id>\d+)/subjects/add$', views.subject.subject_add, name='web.views.subject_add'),
url(r'^subjects/subject_visit_details/(?P<id>\d+)$', views.subject.subject_visit_details, url(r'^subjects/subject_visit_details/(?P<id>\d+)$', views.subject.subject_visit_details,
name='web.views.subject_visit_details'), name='web.views.subject_visit_details'),
url(r'^subjects/edit/(?P<id>\d+)$', views.subject.subject_edit, name='web.views.subject_edit'), url(r'^subjects/edit/(?P<subject_id>\d+)$', views.subject.subject_edit, name='web.views.subject_edit'),
url(r'^subjects/(?P<pk>\d+)/delete$', views.subject.SubjectDeleteView.as_view(), url(r'^subjects/(?P<pk>\d+)/delete$', views.subject.SubjectDeleteView.as_view(),
name='web.views.subject_delete'), name='web.views.subject_delete'),
......
...@@ -15,7 +15,7 @@ def contact_add(request, subject_id): ...@@ -15,7 +15,7 @@ def contact_add(request, subject_id):
if 'from_appointment' in request.GET: if 'from_appointment' in request.GET:
return redirect('web.views.appointment_edit', appointment_id=request.GET.get('from_appointment', '')) return redirect('web.views.appointment_edit', appointment_id=request.GET.get('from_appointment', ''))
else: else:
return redirect('web.views.subject_edit', id=subject_id) return redirect('web.views.subject_edit', subject_id=subject_id)
else: else:
form = ContactAttemptAddForm(user=request.user, subject=subject) form = ContactAttemptAddForm(user=request.user, subject=subject)
...@@ -32,7 +32,7 @@ def contact_edit(request, subject_id, contact_attempt_id): ...@@ -32,7 +32,7 @@ def contact_edit(request, subject_id, contact_attempt_id):
if 'from_appointment' in request.GET: if 'from_appointment' in request.GET:
return redirect('web.views.appointment_edit', appointment_id=request.GET.get('from_appointment', '')) return redirect('web.views.appointment_edit', appointment_id=request.GET.get('from_appointment', ''))
else: else:
return redirect('web.views.subject_edit', id=contact_attempt.subject.id) return redirect('web.views.subject_edit', subject_id=contact_attempt.subject.id)
else: else:
form = ContactAttemptEditForm(instance=contact_attempt, user=request.user) form = ContactAttemptEditForm(instance=contact_attempt, user=request.user)
......
...@@ -48,7 +48,7 @@ def subject_add(request, study_id): ...@@ -48,7 +48,7 @@ def subject_add(request, study_id):
study_subject = study_subject_form.save() study_subject = study_subject_form.save()
persist_custom_file_fields(request, study_subject) persist_custom_file_fields(request, study_subject)
messages.add_message(request, messages.SUCCESS, 'Subject created') messages.add_message(request, messages.SUCCESS, 'Subject created')
return redirect('web.views.subject_edit', id=study_subject_form.instance.id) return redirect('web.views.subject_edit', subject_id=study_subject_form.instance.id)
else: else:
messages.add_message(request, messages.ERROR, 'Invalid data. Please fix data and try again.') messages.add_message(request, messages.ERROR, 'Invalid data. Please fix data and try again.')
...@@ -122,8 +122,8 @@ def subject_require_contact(request): ...@@ -122,8 +122,8 @@ def subject_require_contact(request):
return subject_list(request, SUBJECT_LIST_REQUIRE_CONTACT) return subject_list(request, SUBJECT_LIST_REQUIRE_CONTACT)
def subject_edit(request, id): # pylint: disable=redefined-builtin def subject_edit(request, subject_id):
study_subject = get_object_or_404(StudySubject, id=id) study_subject = get_object_or_404(StudySubject, id=subject_id)
contact_attempts = study_subject.contactattempt_set.order_by('-datetime_when').all() contact_attempts = study_subject.contactattempt_set.order_by('-datetime_when').all()
was_dead = study_subject.subject.dead was_dead = study_subject.subject.dead
was_resigned = study_subject.resigned was_resigned = study_subject.resigned
...@@ -197,7 +197,7 @@ def subject_edit(request, id): # pylint: disable=redefined-builtin ...@@ -197,7 +197,7 @@ def subject_edit(request, id): # pylint: disable=redefined-builtin
p.save() p.save()
messages.success(request, "Modifications saved") messages.success(request, "Modifications saved")
if '_continue' in request.POST: if '_continue' in request.POST:
return redirect('web.views.subject_edit', id=study_subject.id) return redirect('web.views.subject_edit', subject_id=study_subject.id)
return redirect('web.views.subjects') return redirect('web.views.subjects')
else: else:
messages.add_message(request, messages.ERROR, 'Invalid data. Please fix data and try again.') messages.add_message(request, messages.ERROR, 'Invalid data. Please fix data and try again.')
......
...@@ -57,7 +57,7 @@ class VoucherCreateView(CreateView, WrappedView): ...@@ -57,7 +57,7 @@ class VoucherCreateView(CreateView, WrappedView):
def get_success_url(self, **kwargs): def get_success_url(self, **kwargs):
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
return reverse_lazy('web.views.subject_edit', kwargs={'id': self.request.GET.get("study_subject_id", -1)}) return reverse_lazy('web.views.subject_edit', kwargs={'subject_id': self.request.GET.get("study_subject_id", -1)})
def get_form_kwargs(self): def get_form_kwargs(self):
kwargs = super().get_form_kwargs() kwargs = super().get_form_kwargs()
...@@ -79,7 +79,7 @@ class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView): ...@@ -79,7 +79,7 @@ class VoucherEditView(SuccessMessageMixin, UpdateView, WrappedView):
def get_success_url(self, **kwargs): def get_success_url(self, **kwargs):
# noinspection PyUnresolvedReferences # noinspection PyUnresolvedReferences
return reverse_lazy('web.views.subject_edit', kwargs={'id': self.get_study_subject_id()}) return reverse_lazy('web.views.subject_edit', kwargs={'subject_id': self.get_study_subject_id()})
def get_study_subject_id(self): def get_study_subject_id(self):
return Voucher.objects.get(id=self.kwargs['pk']).study_subject.id return Voucher.objects.get(id=self.kwargs['pk']).study_subject.id
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment