diff --git a/www/conservancy/apps/assignment/models.py b/www/conservancy/apps/assignment/models.py index c06d5717fd24edf89828033bc7435e276f54de71..d7bb22ecd0a6b78dabb4165bbcf6d91c259c422c 100644 --- a/www/conservancy/apps/assignment/models.py +++ b/www/conservancy/apps/assignment/models.py @@ -1,33 +1,59 @@ from __future__ import unicode_literals +import uuid + +from django.core.validators import URLValidator, ValidationError from django.db import models +from django_countries.fields import CountryField + + +def validate_mutiple_urls(value): + """Map the URLValidator() over text containing multiple URLs.""" + candidate_urls = [c.strip() for c in value.split()] + invalid_urls = [] + # TODO: Improve this https://docs.djangoproject.com/en/3.2/ref/forms/validation/#raising-multiple-errors + validator = URLValidator() + for url in candidate_urls: + try: + validator(url) + except ValidationError: + invalid_urls.append(url) + print(invalid_urls) + if invalid_urls: + raise ValidationError('These don\'t seem to be complete URLs:\n{}'.format('\n'.join(invalid_urls))) class Assignment(models.Model): """A copyright assignment to Conservancy.""" + uuid = models.UUIDField(primary_key=True, default=uuid.uuid4, editable=False) full_name = models.CharField(max_length=255) - email = models.EmailField() - place_of_residence = models.TextField( - 'Country of citizenship or residential address', - blank=True) - - repository = models.URLField( - 'Code repository', - blank=True, + email = models.EmailField('Email address (to contact you if we have questions)') + country_of_residence = CountryField() + repositories = models.TextField( + 'Code repositories contributed to that you\'d like to assign', + help_text='List of URLs, one per line', + validators=[validate_mutiple_urls], ) - coverage = models.CharField( - verbose_name='Time period to assign', + all_emails = models.TextField( + 'All email addresses and/or names used by you to contribute to the above', + ) + period_begins = models.DateField( + 'Assignment period begins', + ) + period_end_type = models.CharField( + 'Time period to assign', max_length=50, choices=[ - ('up to this year', 'One-off up to and including this year'), - ('ongoing', 'All existing and new contributions'), - ('specific', 'A specific period (details below)'), + ('all future contributions', 'all future contributions'), + ('a specific past date', 'a specific past date'), ], - default='up to this year', ) - coverage_from = models.DateField(blank=True) - coverage_to = models.DateField(blank=True) + period_ends = models.DateField( + 'Assignment period ends (if applicable)', + blank=True, + null=True, + ) attestation_of_copyright = models.BooleanField( - 'I attest that I own the copyright on these works' + 'I agree to be bound by the terms of the Copyright Assignment Agreement above, and that I own the copyright in the works defined above', )