Commit 1c8af3dd authored by smilin_desperado's avatar smilin_desperado

Add status metadata collection and date appliedj

- Add debug_toolbar
- Add some tests
parent f113a589
......@@ -23,3 +23,8 @@ urlpatterns = [
path('accounts/', include('accounts.urls')),
]
if settings.DEBUG:
import debug_toolbar
urlpatterns = [
path('__debug__/', include(debug_toolbar.urls))
] + urlpatterns
from django.apps import AppConfig
class TrackerConfig(AppConfig):
name = 'tracker'
def ready(self):
import tracker.signals
......@@ -15,6 +15,7 @@ class JobForm(ModelForm):
'company',
'url',
'salary',
'date_applied',
'contact_person',
'contact_email',
'phone_number',
......@@ -23,4 +24,8 @@ class JobForm(ModelForm):
'user'
]
widgets = {
'date_applied': TextInput(attrs={'type': 'date'}),
}
# Generated by Django 2.0.3 on 2018-04-05 11:37
from django.db import migrations, models
import django.db.models.deletion
class Migration(migrations.Migration):
dependencies = [
('tracker', '0001_initial'),
]
operations = [
migrations.CreateModel(
name='DataPoint',
fields=[
('id', models.AutoField(auto_created=True, primary_key=True, serialize=False, verbose_name='ID')),
('change_from', models.CharField(choices=[('1', 'Researching'), ('2', 'Applied'), ('3', 'Interviewed For'), ('4', 'Offer Made'), ('5', 'Rejected')], default='1', max_length=50)),
('change_to', models.CharField(choices=[('1', 'Researching'), ('2', 'Applied'), ('3', 'Interviewed For'), ('4', 'Offer Made'), ('5', 'Rejected')], default='1', max_length=50)),
('change_date', models.DateTimeField(auto_now_add=True)),
('job', models.ForeignKey(on_delete=django.db.models.deletion.CASCADE, to='tracker.Job')),
],
),
]
# Generated by Django 2.0.3 on 2018-04-09 11:25
from django.db import migrations
class Migration(migrations.Migration):
dependencies = [
('tracker', '0002_datapoint'),
]
operations = [
migrations.RemoveField(
model_name='datapoint',
name='change_from',
),
]
from django.db import models
from django.contrib.auth.models import User
APPLICATION_STATUS = (
("1", 'Researching'),
("2", 'Applied'),
("3", 'Interviewed For'),
("4", 'Offer Made'),
("5", 'Rejected'),
)
class Job(models.Model):
APPLICATION_STATUS = (
("1", 'Researching'),
("2", 'Applied'),
("3", 'Interviewed For'),
("4", 'Offer Made'),
("5", 'Rejected'),
)
user = models.ForeignKey(User, on_delete=models.CASCADE, related_name="applications")
position_title = models.CharField(max_length=100)
company = models.CharField(max_length=100, blank=True)
......@@ -38,3 +39,8 @@ class Note(models.Model):
def __str__(self):
return self.text[:10]
class DataPoint(models.Model):
job = models.ForeignKey(Job, on_delete=models.CASCADE)
change_to = models.CharField(max_length=50, choices=APPLICATION_STATUS, default='1')
change_date = models.DateTimeField(auto_now_add=True)
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Job, DataPoint
@receiver(post_save, sender=Job)
def job_handler(sender, instance, **kwargs):
try:
dp = DataPoint.objects.filter(job=instance.id).order_by('-change_date')[0]
if dp.change_to != instance.status:
dp = DataPoint()
dp.job = instance
dp.change_to = instance.status
dp.save()
except IndexError:
dp = DataPoint()
dp.job = instance
dp.change_to = instance.status
dp.save()
......@@ -10,9 +10,6 @@
<form action="" method="post">
{% csrf_token %}
<p>Are you sure you want to delete {{ object.position_title|title }} {% if object.company %} at {{ object.company|upper }}{% endif %}?</p>
<a href="{% url 'tracker:edit' object.id %}" class="btn btn-secondary">Back</a>
<input class="btn btn-danger" type="submit" value="Confirm" />
</form>
</div>
</div>
<a href="{% url 'tracker:edit' object.id %}" class="btn btn-outline-secondary"><i class="fas fa-ban"></i> Back</a>
<button type="submit" class="btn btn-outline-danger"><i class="far fa-trash-alt"></i> Confirm</button>
{% endblock %}
......@@ -5,7 +5,7 @@
{% block title %}Edit {{ job.position_title|title }}{% endblock %}
{% block content %}
<div class="container">
<div class="container mb-3">
<h2 class="mt-3">View/Edit Job</h2>
<form action="" method="post" id="editForm">
{% csrf_token %}
......@@ -30,17 +30,26 @@
</div>
</div>
</div>
<div class="form-group">
<div class="row">
<div class="col">
<div class="row">
<div class="col-md-4">
<div class="form-group">
{{ form.company.label_tag }}
{% render_field form.company class="form-control" placeholder="Awesome company inc." %}
</div>
<div class="col">
</div>
<div class="col-md-5">
<div class="form-group">
{{ form.url.label_tag }}
{% render_field form.url class="form-control" placeholder="https://awesomecompany.com" %}
</div>
</div>
<div class="col-md-3">
<div class="form-group">
{{ form.date_applied.label_tag }}
{{ form.date_applied|add_class:"form-control" }}
</div>
</div>
</div>
<h4 class="mt-3 p-1 bg-secondary text-white">Contact</h3>
<div class="form-group">
{{ form.contact_person.label_tag }}
......@@ -79,8 +88,9 @@
</div>
</div>
</form>
<button type="submit" class="btn btn-outline-primary" form="editForm"><i class="far fa-ok"></i>Save</button>
<button type="submit" class="btn btn-outline-primary" form="editForm"><i class="far fa-check-circle"></i> Save</button>
<a class="btn btn-outline-danger" href="{% url 'tracker:delete' object.id %}"><i class="far fa-trash-alt"></i> Delete</a>
</div>
{% endblock %}
{% block scripts %}
......@@ -113,5 +123,19 @@
if (el.value == "https://")
el.value = '';
});
Date.prototype.toDateInputValue = (function() {
var local = new Date(this);
local.setMinutes(this.getMinutes() - this.getTimezoneOffset());
return local.toJSON().slice(0,10);
});
var el = document.getElementById('id_status');
el.addEventListener('change', function(event){
var dateApplied = document.getElementById('id_date_applied');
if (event.target.value == 2 && dateApplied.value == ''){
dateApplied.value = new Date().toDateInputValue();
}
});
</script>
{% endblock %}
......@@ -40,7 +40,7 @@
{% endfor %}
{% include 'tracker/add.html' %}
<button type="button" class="btn btn-outline-primary" data-toggle="modal" data-target="#addModal">Add Job</button>
<button type="button" class="btn btn-outline-primary" data-toggle="modal" data-target="#addModal"><i class="fas fa-plus"></i> Add Job</button>
{% endblock %}
{% block scripts %}
......@@ -49,7 +49,6 @@
var target = event.target;
if(target.className == 'card-body' || target.parentElement.className == 'card-body' ){
url = target.querySelector('.job-url') || target.parentElement.querySelector('.job-url')
console.log(url)
window.location.href = url.href;
}
});
......
from django.test import TestCase
from django.urls import reverse
from .models import Job
# Create your tests here.
class IndexPageTests(TestCase):
def empty_dashboard(self):
self.client.force_login('test_user')
response = self.client.get('/')
html = response.content.decode('utf8')
self.assertIn('Dashboard', html)
self.assertIn('<title>Dashboard | JAT</title>', html)
self.assertIn('Add Job', html)
......@@ -9,7 +9,7 @@ from django.contrib.auth.models import User
from django.contrib.auth.mixins import LoginRequiredMixin
from django.contrib.auth.decorators import login_required
from .forms import JobAddForm, JobForm
from .models import Note, Job
from .models import Note, Job, DataPoint
class IndexView(LoginRequiredMixin, ListView):
template_name = 'tracker/index.html'
......@@ -29,6 +29,9 @@ def add(request):
job = form.save(commit=False)
job.user = User.objects.get(pk=request.user.id)
job.save()
point = DataPoint()
point.job = job
point.save()
messages.success(request,f"{job.position_title} created")
return redirect(reverse('tracker:index'))
else:
......@@ -44,7 +47,7 @@ class EditView(LoginRequiredMixin, SuccessMessageMixin, UpdateView):
form_class = JobForm
success_url = reverse_lazy('tracker:index')
success_message = "%(position_title)s was successfully updated"
class DeleteJobView(LoginRequiredMixin, DeleteView):
model = Job
template_name = 'tracker/delete.html'
......
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