New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Fix #1007 -- small improvements to training request workflow #1030
Changes from all commits
9978cc4
141893d
e9e3395
ee8c3ac
38bdc11
23aa5fe
3736524
7fcedd0
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -1850,11 +1850,11 @@ def build_choice_field_with_other_option(choices, default, verbose_name=None): | |
|
||
@reversion.register | ||
class TrainingRequest(ActiveMixin, CreatedUpdatedMixin, models.Model): | ||
STATES = ( | ||
STATES = [ | ||
('p', 'Pending'), # initial state | ||
('a', 'Accepted'), # state after matching a Person record | ||
('d', 'Discarded'), | ||
) | ||
] | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Why a list rather than a tuple? |
||
state = models.CharField(choices=STATES, default='p', max_length=1) | ||
|
||
person = models.ForeignKey(Person, null=True, blank=True, | ||
|
@@ -2043,17 +2043,17 @@ class TrainingRequest(ActiveMixin, CreatedUpdatedMixin, models.Model): | |
def clean(self): | ||
super().clean() | ||
|
||
if self.state == 'a' and self.person is None: | ||
raise ValidationError({'person': 'Accepted training request must ' | ||
'be matched to a person.'}) | ||
|
||
if self.state == 'p' and self.person is not None: | ||
raise ValidationError({'person': 'Pending training requests cannot ' | ||
'be matched to a person.'}) | ||
if self.state == 'p' and self.person is not None \ | ||
and self.person.get_training_tasks().exists(): | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch - thanks. |
||
raise ValidationError({'state': 'Pending training request cannot ' | ||
'be matched with a training.'}) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Good catch 👍 |
||
|
||
def get_absolute_url(self): | ||
return reverse('trainingrequest_details', args=[self.pk]) | ||
|
||
def __str__(self): | ||
return "Training request #{}".format(self.pk) | ||
|
||
|
||
@reversion.register | ||
class TrainingRequirement(models.Model): | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
why a list rather than a tuple?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Because here it's more readable to write:
rather than