Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion jobs/admin.py
Original file line number Diff line number Diff line change
Expand Up @@ -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']


Expand Down
7 changes: 7 additions & 0 deletions jobs/forms.py
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,13 @@ class Meta:
widgets = {
'job_types': CheckboxSelectMultiple(),
}
help_texts = {
'email': (
"<b>This email address will be publicly displayed for "
"applicants to contact if they are interested in the "
"posting.</b>"
),
}

def __init__(self, *args, **kwargs):
super().__init__(*args, **kwargs)
Expand Down
21 changes: 21 additions & 0 deletions jobs/migrations/0019_job_submitted_by.py
Original file line number Diff line number Diff line change
@@ -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),
),
]
8 changes: 8 additions & 0 deletions jobs/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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'
Expand Down
7 changes: 0 additions & 7 deletions jobs/tests/test_views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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',
Expand Down
3 changes: 1 addition & 2 deletions jobs/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -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'] = {'email': self.request.user.email}
return kwargs

def get_context_data(self, **kwargs):
Expand All @@ -371,6 +369,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)

Expand Down