add validators to participant model

This commit is contained in:
Dustin J. Mitchell 2020-10-14 12:55:59 +00:00 коммит произвёл Dustin J. Mitchell
Родитель ff53696415
Коммит 09fa1262a5
3 изменённых файлов: 39 добавлений и 12 удалений

Просмотреть файл

@ -1,14 +1,14 @@
Stuff to do!
* figure out
* how flexible is admin/ -- can this all be done there?
* user authentication
* SSO-linked?
* Simplest possible!
* critical for admin; just need an identity for enrollment
* use moderator example
* pairing
* provide data to a react app, allow filtering, etc.
* hardening
* use moderator as an example
* CSP
@ -18,8 +18,17 @@ Stuff to do!
* enrollment
* replace Alchemer with.. a regular old form (or a react app)
* pairing
* provide data to a react app, allow filtering, etc.
* notes
* provide a way to add notes to a participant (not via admin)
* emails
* provide a way to create batches of emails and send them, and track what's
been sent
* misc
* linting
* CI
* move repo to mozilla/
* deployment
* in heroku

Просмотреть файл

@ -1,6 +1,7 @@
# Generated by Django 3.1.2 on 2020-10-14 12:42
# Generated by Django 3.1.2 on 2020-10-14 12:55
from django.db import migrations, models
import mentoring.participants.models
class Migration(migrations.Migration):
@ -21,12 +22,12 @@ class Migration(migrations.Migration):
('full_name', models.CharField(help_text="The participant's full name (as they would prefer to be called).", max_length=512)),
('manager', models.CharField(help_text="The participant's manager's name.", max_length=512)),
('manager_email', models.EmailField(help_text="The participant's manager's email address. This is used to verify approval. ", max_length=254)),
('approved', models.BooleanField(help_text='Whether this participant\'s participation has been approved by their manager.\nNull means "not yet"; we treat silence from managers as consent.')),
('time_availability', models.CharField(help_text="The participant's time availability, as a sequence of Y and N for each UTC hour,\nso `NNNYYYYYYYYYNNNNNNNNNNNN` indicates availability from 03:00-12:00 UTC.", max_length=24)),
('approved', models.BooleanField(help_text='Whether this participant\'s participation has been approved by their manager.\nNull means "not yet"; we treat silence from managers as consent.', null=True)),
('time_availability', models.CharField(help_text="The participant's time availability, as a sequence of Y and N for each UTC hour,\nso `NNNYYYYYYYYYNNNNNNNNNNNN` indicates availability from 03:00-12:00 UTC.", max_length=24, validators=[mentoring.participants.models.validate_time_availability])),
('org', models.CharField(help_text="Participant's organization (roughly, executive to whom they report)", max_length=100, null=True)),
('org_level', models.CharField(help_text="Participant's current organizational level, e.g., `P3` or `M4`", max_length=10, null=True)),
('time_at_org_level', models.CharField(help_text="Participant's time at current organizational level, e.g., `2-3 y`", max_length=10, null=True)),
('interests', models.JSONField(help_text="A learner's areas of interest, or a mentor's areas in which they can offer mentorship;\nformat is an array of open-text strings.", null=True)),
('interests', models.JSONField(help_text="A learner's areas of interest, or a mentor's areas in which they can offer mentorship;\nformat is an array of open-text strings.", null=True, validators=[mentoring.participants.models.validate_interests])),
('track_change', models.CharField(help_text='Whether the participant is interested in changing tracks (between IC and Manager)', max_length=64, null=True)),
('org_chart_distance', models.CharField(help_text='Preference for a pairing nearby or distant in the org chart (open text)', max_length=20, null=True)),
('comments', models.TextField(blank=True, help_text="Open comments from the participant's enrollment")),

Просмотреть файл

@ -1,6 +1,23 @@
from django.db import models
from textwrap import dedent
from django.core.exceptions import ValidationError
def validate_time_availability(time_availability):
if len(time_availability) != 24:
raise ValidationError('time_availability must be 24 characters')
if any(c not in 'YN' for c in time_availability):
raise ValidationError('time_availability must contain only Y and N characters')
def validate_interests(interests):
if type(interests) != type(list):
raise ValidationError('interests must be a list')
if any(type(i) != type('') for i in interests):
raise ValidationError('interests must contain strings')
class Participant(models.Model):
"""
A Participant in the program.
@ -39,17 +56,17 @@ class Participant(models.Model):
manager_email = models.EmailField(null=False, help_text=dedent('''\
The participant's manager's email address. This is used to verify approval. '''))
approved = models.BooleanField(help_text=dedent('''\
approved = models.BooleanField(null=True, help_text=dedent('''\
Whether this participant's participation has been approved by their manager.
Null means "not yet"; we treat silence from managers as consent.'''))
time_availability = models.CharField(
max_length=24,
null=False,
validators=[validate_time_availability],
help_text=dedent('''\
The participant's time availability, as a sequence of Y and N for each UTC hour,
so `NNNYYYYYYYYYNNNNNNNNNNNN` indicates availability from 03:00-12:00 UTC.'''),
# TODO: add a validator
)
org = models.CharField(max_length=100, null=True, help_text=dedent('''\
@ -64,7 +81,7 @@ class Participant(models.Model):
interests = models.JSONField(null=True, blank=False, help_text=dedent('''\
A learner's areas of interest, or a mentor's areas in which they can offer mentorship;
format is an array of open-text strings.'''),
# TODO: add a validator
validators=[validate_interests],
)
track_change = models.CharField(null=True, max_length=64, help_text=dedent('''\