Commit 62759ab3 authored by David Haynes's avatar David Haynes
Browse files

Comment up models.py and updates PK on URL model (Closes #45)

- ez comments
- also close a bite sized issue because I'm evil
- also it was bothering me
parent 57af3414
Pipeline #492 passed with stage
in 7 minutes and 28 seconds
...@@ -8,16 +8,17 @@ from django.dispatch import receiver ...@@ -8,16 +8,17 @@ from django.dispatch import receiver
# Other Imports # Other Imports
import string import string
# http://hashids.org/python/
from hashids import Hashids from hashids import Hashids
# generate the salt and initialize 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))
"""
This is simply a wrapper model for the user object which, if an object
exists, indicates that that user is registered.
"""
class RegisteredUser(models.Model): class RegisteredUser(models.Model):
"""
This is simply a wrapper model which, if an object exists, indicates
that that user is registered.
"""
# Let's associate a User to this RegisteredUser # Let's associate a User to this RegisteredUser
user = models.OneToOneField(User) user = models.OneToOneField(User)
...@@ -56,31 +57,44 @@ def handle_regUser_creation(sender, instance, created, **kwargs): ...@@ -56,31 +57,44 @@ def handle_regUser_creation(sender, instance, created, **kwargs):
RegisteredUser.objects.create(user=instance) RegisteredUser.objects.create(user=instance)
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
owner, target url, short identifier, click counter, and expiration owner, target url, short identifier, click counter, and expiration
date. date.
""" """
class URL(models.Model):
# Who is the owner of this Go link
owner = models.ForeignKey(RegisteredUser) owner = models.ForeignKey(RegisteredUser)
# When was this link created?
date_created = models.DateTimeField(default=timezone.now) date_created = models.DateTimeField(default=timezone.now)
# What is the target URL for this Go link
target = models.URLField(max_length=1000) target = models.URLField(max_length=1000)
short = models.SlugField(primary_key=True, max_length=20) # What is the actual go link (short url) for this URL
clicks = models.IntegerField(default=0) short = models.SlugField(max_length=20)
# how many people have visited this Go link
clicks = models.IntegerField(default=0)
# how many people have visited this Go link through the qr code
qrclicks = models.IntegerField(default=0) qrclicks = models.IntegerField(default=0)
# how many people have visited the go link through social media
socialclicks = models.IntegerField(default=0) socialclicks = models.IntegerField(default=0)
# does this Go link expire on a certain date
expires = models.DateTimeField(blank=True, null=True) expires = models.DateTimeField(blank=True, null=True)
# print(URL)
def __unicode__(self): def __unicode__(self):
return '<%s : %s>' % (self.owner.user, self.target) return '<%s : %s>' % (self.owner.user, self.target)
# metadata for URL's
class Meta: class Meta:
# they should be ordered by their short links
ordering = ['short'] ordering = ['short']
# legacy method to ensure that generated short URL's are valid
# should be updated to be simpler
@staticmethod @staticmethod
def generate_valid_short(): def generate_valid_short():
if cache.get("hashids_counter") is None: if cache.get("hashids_counter") is None:
......
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