Commit b911583d authored by Chris Lamb's avatar Chris Lamb
Browse files

Add ability to create jobs with an application email address too, not just an URL. (Closes: #37)

parent f8fc4e75
......@@ -18,6 +18,7 @@ class AddEditForm(forms.ModelForm):
'job_type',
'location',
'apply_url',
'apply_email',
'description',
'tags',
)
......@@ -32,6 +33,17 @@ class AddEditForm(forms.ModelForm):
# Remove empty label
self.fields['job_type'].choices.pop(0)
def clean(self):
if not self.cleaned_data.get('apply_url') and \
not self.cleaned_data.get('apply_email'):
self.add_error(
'apply_url',
"You must specify at least one application method.",
)
self.add_error('apply_email', '')
return self.cleaned_data
def save(self, user):
instance = super().save(commit=False)
instance.user = user
......
......@@ -34,6 +34,7 @@ class AddTests(TestCase):
'location': "Job location",
'description': "Job description",
'apply_url': 'https://example.com/',
'apply_email': 'foo@bar.com',
'job_type': JobTypeEnum.CONTRACT.value,
}, 'jobs:add-edit:add')
......@@ -42,8 +43,8 @@ class AddTests(TestCase):
def test_POST_invalid(self):
response = self.assertPOST({}, 'jobs:add-edit:add', status_code=200)
self.assertFormError(response, 'form', 'title', [
"This field is required."
self.assertFormError(response, 'form', 'apply_url', [
"You must specify at least one application method.",
])
......
# Generated by Django 2.0.5 on 2018-06-08 16:10
from django.db import migrations, models
class Migration(migrations.Migration):
dependencies = [
('jobs', '0002_auto_20180412_1641'),
]
operations = [
migrations.AddField(
model_name='job',
name='apply_email',
field=models.EmailField(blank=True, max_length=254),
),
migrations.AlterField(
model_name='job',
name='apply_url',
field=models.URLField(blank=True),
),
]
......@@ -34,7 +34,8 @@ class Job(models.Model):
title = models.CharField(max_length=255)
job_type = EnumIntegerField(JobTypeEnum)
location = models.CharField(max_length=255)
apply_url = models.URLField()
apply_url = models.URLField(blank=True)
apply_email = models.EmailField(blank=True)
description = models.TextField()
tags = models.ManyToManyField(
......
......@@ -18,4 +18,9 @@
footer {
padding: 30px 0;
}
// Workaround <https://github.com/twbs/bootstrap/issues/23454>
div.input-group ~ .invalid-feedback {
display: block !important;
}
}
......@@ -104,30 +104,66 @@
{% endfor %}
</div>
<div class="form-group col-md-12">
<label class="col-form-label" for="{{ form.apply_url.id_for_label }}">
URL to apply
</label>
<input
id="{{ form.apply_url.id_for_label }}"
type="url"
class="form-control {% if form.errors %}{% if form.errors.apply_url %}is-invalid{% else %}{% if not form.non_field_errors %}is-valid{% endif %}{% endif %}{% endif %}"
name="{{ form.apply_url.html_name }}"
value="{{ form.apply_url.value|default:"" }}"
maxlength="{{ form.apply_url.field.max_length|default:"" }}"
placeholder=""
{% if form.apply_url.field.required %}required{% endif %}
>
{% for x in form.errors.apply_url %}
<div class="invalid-feedback">{{ x }}</div>
{% empty %}
<small class="form-text text-muted">
Enter the address where applicants should submit their CV, etc.
</small>
{% endfor %}
<div class="form-row col-md-12">
<div class="col-md-6">
<label class="col-form-label" for="{{ form.apply_url.id_for_label }}">
URL to apply
</label>
<div class="input-group">
<div class="input-group-addon">
<span class="input-group-text"><i class="fa fa-home"></i></span>
</div>
<input
id="{{ form.apply_url.id_for_label }}"
type="url"
class="form-control {% if form.errors %}{% if form.errors.apply_url %}is-invalid{% else %}{% if not form.non_field_errors %}is-valid{% endif %}{% endif %}{% endif %}"
name="{{ form.apply_url.html_name }}"
value="{{ form.apply_url.value|default:"" }}"
maxlength="{{ form.apply_url.field.max_length|default:"" }}"
placeholder=""
{% if form.apply_url.field.required %}required{% endif %}
>
</div>
{% for x in form.errors.apply_url %}
<div class="invalid-feedback">{{ x }}</div>
{% endfor %}
</div>
<div class="col-md-6">
<label class="col-form-label" for="{{ form.apply_email.id_for_label }}">
Email to apply
</label>
<div class="input-group">
<div class="input-group-addon">
<span class="input-group-text"><i class="fa fa-envelope"></i></span>
</div>
<input
id="{{ form.apply_email.id_for_label }}"
type="email"
class="form-control {% if form.errors %}{% if form.errors.apply_email %}is-invalid{% else %}{% if not form.non_field_errors %}is-valid{% endif %}{% endif %}{% endif %}"
name="{{ form.apply_email.html_name }}"
value="{{ form.apply_email.value|default:"" }}"
maxlength="{{ form.apply_email.field.max_length|default:"" }}"
placeholder=""
{% if form.apply_email.field.required %}required{% endif %}
>
</div>
{% for x in form.errors.apply_email %}
<div class="invalid-feedback">{{ x }}</div>
{% endfor %}
</div>
</div>
{% if not form.errors.apply_url and not form.errors.email_url %}
<div class="form-group col-md-12">
<small class="form-text text-muted">
Enter the web address and/or email address where applicants should
submit their CV, etc.
</small>
</div>
{% endif %}
<div class="form-group col-md-12 mt-3">
<label class="col-form-label" for="{{ form.description.id_for_label }}">
Description
</label>
......
......@@ -25,5 +25,12 @@
{{ obj.description|markdown }}
<p>
{% if obj.apply_url and obj.apply_email %}
<a href="{{ obj.apply_url }}">Apply directly</a> or email
<a href="mailto:{{ obj.apply_email }}">{{ obj.apply_email }}</a>
{% elif obj.apply_url %}
<a href="{{ obj.apply_url }}">Apply</a>
{% elif obj.apply_email %}
Email <a href="mailto:{{ obj.apply_url }}">{{ obj.apply_email }}</a> to apply.
{% endif %}
</p>
......@@ -76,9 +76,18 @@
{{ job.description|markdown }}
<br>
<div id="apply">
{% if job.apply_url %}
<div id="apply" class="mb-2">
<a rel="nofollow" href="{{ job.apply_url }}" class="btn btn-default btn-block">Apply</a>
</div>
{% endif %}
{% if job.apply_email %}
<p>
{% if job.apply_url %}&hellip; or you can{% else %}Please{% endif %}
apply by emailing <a href="mailto:{{ job.apply_email }}">{{ job.apply_email }}</a>.
</p>
{% endif %}
<div id="tag">
{% for x in job.tags.all %}
......@@ -101,10 +110,12 @@
<a href="#"><i class="fa fa-globe" aria-hidden="true"></i></a>
{% endcomment %}
</div>
<div id="mini-apply">
{% if job.apply_url %}
<div id="mini-apply" class="mb-1">
<a href="{{ job.apply_url }}" rel="nofollow" class="btn btn-default btn-block">Apply</a>
</div>
{% endif %}
</div>
{% if job.user.jobs.live.count %}
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment