Developer Journal: 28 April 2020

Posted on Tue 28 April 2020 in dev-journal

Yesterday I wrote a very simple test for a delete route:

@patch('app.models.launch_task')
def test_delete_removes_worker_from_db(self, mock_launch):
    mock_launch.return_value = ""
    login_user(self.client, email=self.user.email, password='password')

    self.client.delete(self.base_url)
    workers = SiteWorker.query.all()
    self.assertEqual(len(workers), 0)

To allow that test to pass I added a delete route:

@bp.route('<int:worker_id>', methods=['DELETE'])
@login_required
def delete_worker(site_id, worker_id):
    # create a provisioner command to stop, disable, and delete the current
    # worker setup on the server as well as the site_worker in the database
    site = Site.query.get(site_id)
    client = Client(
        server.ipv4_address,
        current_app.config['SSH_PRIV_KEY_FILE'])
    site.launch_task("Deleting workers",
                        client.delete_workers,
                        site.domain)

    worker = SiteWorker.query.filter_by(id=worker_id).first()
    db.session.delete(worker)
    db.session.commit()

    return redirect(url_for("workers.index", site_id=site_id))

Then to tie this all together I can add a button to each of the workers on the worker index page. I may change this to use a form instead of the link but this works well for what I need right now.

<a data-action="" 
data-method="delete"
data-remote="true"
data-disable-with="Deleting"
data-confirm="Are you sure you want to delete this worker?"
class="text-red-600 mt-8 ml-8" 
href="{{ url_for("workers.delete_worker", site_id=site.id, worker_id=worker.id) }}">Delete
</a>

The last piece of this feature is to allow custom workers, to start this off an extra form field is necessary:

custom_worker = StringField("Advanced use only: custom worker")

Mocking up a page to help users of an app fill out speaker evaluations. These evaluations are used to determine the amount of credits a conference attendee has earned. We need to make sure that we give users an easy way to find the evaluations for the talks they attended.

Currently the evaluations are just listed with no ability to sort or filter.

Evaluation currently

While I'm in here I'm going to update the evaluation page...

Evaluation Update Comparison

To help users find the talks for the evaluations they have not completed at the time of the talk - we introduce filters. Selecting a talk will begin by choosing the day the talk occured and from there additional filters are used to help fine tune the search.

Evaluation Filter