From 40dc114cf68113a08e11422c297e1d37e19c22e4 Mon Sep 17 00:00:00 2001 From: Ernest W Durbin III Date: Fri, 6 Sep 2019 16:48:41 -0400 Subject: [PATCH 1/2] clarify Contact Email on jobs submission form Associates submissions with a user for contact information and add help text to clarify that the Contact Email field will be displayed publically. --- jobs/admin.py | 2 +- jobs/forms.py | 6 ++++++ jobs/migrations/0019_job_submitted_by.py | 21 +++++++++++++++++++++ jobs/models.py | 8 ++++++++ jobs/tests/test_views.py | 7 ------- jobs/views.py | 3 ++- 6 files changed, 38 insertions(+), 9 deletions(-) create mode 100644 jobs/migrations/0019_job_submitted_by.py diff --git a/jobs/admin.py b/jobs/admin.py index f24e8b077..7c811e95e 100644 --- a/jobs/admin.py +++ b/jobs/admin.py @@ -10,7 +10,7 @@ class JobAdmin(ContentManageableModelAdmin): filter_horizontal = ['job_types'] list_display = ['__str__', 'job_title', 'status', 'company_name'] list_filter = ['status', 'telecommuting'] - raw_id_fields = ['category'] + raw_id_fields = ['category', 'submitted_by'] search_fields = ['id', 'job_title'] diff --git a/jobs/forms.py b/jobs/forms.py index c22caf2a1..15eada85d 100644 --- a/jobs/forms.py +++ b/jobs/forms.py @@ -33,6 +33,12 @@ class Meta: widgets = { 'job_types': CheckboxSelectMultiple(), } + help_texts = { + 'email': ( + "This email address will be shown for applicants to contact " + "if they are interested in the posting." + ), + } def __init__(self, *args, **kwargs): super().__init__(*args, **kwargs) diff --git a/jobs/migrations/0019_job_submitted_by.py b/jobs/migrations/0019_job_submitted_by.py new file mode 100644 index 000000000..62c74fa3a --- /dev/null +++ b/jobs/migrations/0019_job_submitted_by.py @@ -0,0 +1,21 @@ +# Generated by Django 2.0.13 on 2019-09-06 20:29 + +from django.conf import settings +from django.db import migrations, models +import django.db.models.deletion + + +class Migration(migrations.Migration): + + dependencies = [ + migrations.swappable_dependency(settings.AUTH_USER_MODEL), + ('jobs', '0018_auto_20180705_0352'), + ] + + operations = [ + migrations.AddField( + model_name='job', + name='submitted_by', + field=models.ForeignKey(null=True, on_delete=django.db.models.deletion.SET_NULL, to=settings.AUTH_USER_MODEL), + ), + ] diff --git a/jobs/models.py b/jobs/models.py index 3166e15d2..9e26d76a1 100644 --- a/jobs/models.py +++ b/jobs/models.py @@ -13,6 +13,8 @@ from cms.models import ContentManageable, NameSlugModel from fastly.utils import purge_url +from users.models import User + from .managers import JobQuerySet, JobTypeQuerySet, JobCategoryQuerySet from .signals import ( job_was_submitted, job_was_approved, job_was_rejected, comment_was_posted @@ -109,6 +111,12 @@ class Job(ContentManageable): null=True, blank=True) + submitted_by = models.ForeignKey( + User, + null=True, + on_delete=models.SET_NULL, + ) + STATUS_DRAFT = 'draft' STATUS_REVIEW = 'review' STATUS_APPROVED = 'approved' diff --git a/jobs/tests/test_views.py b/jobs/tests/test_views.py index df74676c7..0f087eb42 100644 --- a/jobs/tests/test_views.py +++ b/jobs/tests/test_views.py @@ -320,10 +320,6 @@ def test_job_create(self): creator = User.objects.create_user(username, email, password) self.client.login(username=creator.username, password='secret') - # Check that the email is already there. - response = self.client.get(url) - self.assertEqual(response.context['form'].initial['email'], email) - response = self.client.post(url, post_data, follow=True) # Job was saved in draft mode @@ -380,9 +376,6 @@ def test_job_create_prepopulate_email(self): password=user_data['password']) response = self.client.get(create_url) - self.assertEqual(response.context['form'].initial, - {'email': user_data['email']}) - def test_job_types(self): job_type2 = JobTypeFactory( name='Senior Developer', diff --git a/jobs/views.py b/jobs/views.py index aaf259d86..f1c376c17 100644 --- a/jobs/views.py +++ b/jobs/views.py @@ -361,7 +361,7 @@ def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs['request'] = self.request # We don't allow posting a job without logging in to the site. - kwargs['initial'] = {'email': self.request.user.email} + kwargs['initial'] = {} return kwargs def get_context_data(self, **kwargs): @@ -371,6 +371,7 @@ def get_context_data(self, **kwargs): def form_valid(self, form): form.instance.creator = self.request.user + form.instance.submitted_by = self.request.user form.instance.status = 'draft' return super().form_valid(form) From 46eb5a2ce41c54529ebe7a1b1fa19eb36c1346cc Mon Sep 17 00:00:00 2001 From: Ernest W Durbin III Date: Tue, 15 Oct 2019 10:10:27 -0400 Subject: [PATCH 2/2] address review feedback --- jobs/forms.py | 5 +++-- jobs/views.py | 2 -- 2 files changed, 3 insertions(+), 4 deletions(-) diff --git a/jobs/forms.py b/jobs/forms.py index 15eada85d..08b35ce00 100644 --- a/jobs/forms.py +++ b/jobs/forms.py @@ -35,8 +35,9 @@ class Meta: } help_texts = { 'email': ( - "This email address will be shown for applicants to contact " - "if they are interested in the posting." + "This email address will be publicly displayed for " + "applicants to contact if they are interested in the " + "posting." ), } diff --git a/jobs/views.py b/jobs/views.py index f1c376c17..ea5959bcd 100644 --- a/jobs/views.py +++ b/jobs/views.py @@ -360,8 +360,6 @@ def get_success_url(self): def get_form_kwargs(self): kwargs = super().get_form_kwargs() kwargs['request'] = self.request - # We don't allow posting a job without logging in to the site. - kwargs['initial'] = {} return kwargs def get_context_data(self, **kwargs):