Commit e837676f authored by David Haynes's avatar David Haynes
Browse files

associate a registereduser with every user on creation (Closes #7)

- registered users now have a one to one relationship to their user
- nice comments added as well
parent 79441961
...@@ -3,15 +3,15 @@ from django.db import models ...@@ -3,15 +3,15 @@ from django.db import models
from django.contrib.auth.models import User from django.contrib.auth.models import User
from django.utils import timezone from django.utils import timezone
from django.core.cache import cache from django.core.cache import cache
from django.db.models.signals import post_save
from django.dispatch import receiver
# Other Imports # Other Imports
import string import string
from hashids import Hashids from hashids import Hashids
hashids = Hashids(salt="srct.gmu.edu", alphabet=(string.ascii_lowercase + string.digits)) hashids = Hashids(salt="srct.gmu.edu", alphabet=(string.ascii_lowercase + string.digits))
class URL(models.Model): class URL(models.Model):
""" """
This model represents a stored URL redirection rule. Each URL has an This model represents a stored URL redirection rule. Each URL has an
...@@ -59,27 +59,38 @@ class RegisteredUser(models.Model): ...@@ -59,27 +59,38 @@ class RegisteredUser(models.Model):
that that user is registered. that that user is registered.
""" """
user = models.OneToOneField( # Let's associate a User to this RegisteredUser
User, user = models.OneToOneField(User)
on_delete=models.CASCADE,
primary_key=True,
)
# What is your name?
full_name = models.CharField( full_name = models.CharField(
blank=False, blank=False,
max_length=100, max_length=100,
) )
# What organization are you associated with?
organization = models.CharField( organization = models.CharField(
null=True,
blank=False, blank=False,
max_length=100, max_length=100,
) )
# Why do you want to use Go?
description = models.TextField(blank=True) description = models.TextField(blank=True)
approved = models.BooleanField(default=False) # Have you filled out the registration form?
registered = models.BooleanField(default=False) registered = models.BooleanField(default=False)
# Are you approved to use Go?
approved = models.BooleanField(default=False)
# print(RegisteredUser)
def __unicode__(self): def __unicode__(self):
return '<Registered User: %s - Approval Status: %s>' % (self.username, self.approved) return '<Registered User: %s - Approval Status: %s>' % (self.user, self.approved)
# When a post_save is called on a User object (and it is newly created), this is
# called to create an associated RegisteredUser
@receiver(post_save, sender=User)
def handle_regUser_creation(sender, instance, created, **kwargs):
if created:
RegisteredUser.objects.create(user=instance)
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment