aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorSean Smith <ssmith@iol.unh.edu>2020-08-19 11:58:56 -0400
committerSean Smith <ssmith@iol.unh.edu>2020-08-19 15:01:20 -0400
commit90a55772df44dfaeadced5fb3dc4dab0c9c49c6f (patch)
tree6474d161f648008277178bce3ceba88c75df7613 /src
parent0c71a0ce238a1ca816cec35b62e228a97102aa6a (diff)
Enforce company constraints
Signed-off-by: Sean Smith <ssmith@iol.unh.edu> Change-Id: Id5726e5c9930e684c23cebafb98d5fbcb95e67bc
Diffstat (limited to 'src')
-rw-r--r--src/account/models.py20
1 files changed, 18 insertions, 2 deletions
diff --git a/src/account/models.py b/src/account/models.py
index 6828ee1..2c133bb 100644
--- a/src/account/models.py
+++ b/src/account/models.py
@@ -11,6 +11,8 @@
from django.contrib.auth.models import User
from django.db import models
from django.apps import apps
+from django.core.exceptions import ValidationError
+import re
import json
import random
@@ -50,13 +52,27 @@ class UserProfile(models.Model):
oauth_token = models.CharField(max_length=1024, blank=False)
oauth_secret = models.CharField(max_length=1024, blank=False)
- jira_url = models.CharField(max_length=100, default='')
- full_name = models.CharField(max_length=100, default='')
+ jira_url = models.CharField(max_length=100, null=True, blank=True, default='')
+ full_name = models.CharField(max_length=100, null=True, blank=True, default='')
booking_privledge = models.BooleanField(default=False)
class Meta:
db_table = 'user_profile'
+ def clean(self, *args, **kwargs):
+ company = self.company
+ regex = r'[a-z\_\-\.\$]*'
+ pattern = re.compile(regex)
+
+ if not pattern.fullmatch(company):
+ raise ValidationError('Company may only include lowercase letters, _, -, . and $')
+
+ super().clean(*args, **kwargs)
+
+ def save(self, *args, **kwargs):
+ self.full_clean()
+ super().save(*args, **kwargs)
+
def __str__(self):
return self.user.username