File diff c23f799fa13a → 1ce6f36532e3
www/conservancy/apps/assignment/models.py
Show inline comments
 
new file 100644
 
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('Email address (to contact you if we have questions)')
 
    country_of_residence = CountryField()
 
    repositories = models.TextField(
 
        'Code repositories containing contributions of yours whose copyright you are assigning',
 
        help_text='List of URLs, one per line',
 
        validators=[validate_mutiple_urls],
 
    )
 
    all_emails = models.TextField(
 
        'All email addresses or other unique user identities, such as nicknames or handles, used by you to contribute to the above (i.e. in the commit logs)',
 
    )
 
    period_begins = models.DateField(
 
        'Assignment period begins',
 
    )
 
    period_end_type = models.CharField(
 
        'Time period to assign',
 
        max_length=50,
 
        choices=[
 
            ('all future contributions', 'all future contributions'),
 
            ('a specific past date', 'a specific past date'),
 
        ],
 
    )
 
    period_ends = models.DateField(
 
        'Assignment period ends (if applicable)',
 
        blank=True,
 
        null=True,
 
    )
 
    attestation_of_copyright = models.BooleanField(
 
        'By checking the box below, I am confirming that I agree to be bound by the terms of the Copyright Assignment Agreement above.',
 
    )