Skip to content
GitLab
Menu
Projects
Groups
Snippets
Loading...
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
SRCT
go
Commits
45e9d702
Unverified
Commit
45e9d702
authored
Mar 13, 2017
by
David Haynes
Browse files
PEP8 compliance for URL model
- Plus __str__ now prints like registereduser does
parent
8d88d8e1
Changes
1
Hide whitespace changes
Inline
Side-by-side
go/go/models.py
View file @
45e9d702
# Future Imports
# Future Imports
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
,
division
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
,
division
# Python stdlib Imports
import
string
# Django Imports
# Django Imports
from
django.db
import
models
from
django.db
import
models
from
django.contrib.auth.models
import
User
from
django.contrib.auth.models
import
User
...
@@ -12,7 +15,6 @@ from django.utils.encoding import python_2_unicode_compatible
...
@@ -12,7 +15,6 @@ from django.utils.encoding import python_2_unicode_compatible
# Other Imports
# Other Imports
from
hashids
import
Hashids
# http://hashids.org/python/
from
hashids
import
Hashids
# http://hashids.org/python/
import
string
# generate the salt and initialize 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
))
...
@@ -24,9 +26,6 @@ class RegisteredUser(models.Model):
...
@@ -24,9 +26,6 @@ class RegisteredUser(models.Model):
exists, indicates that that user is registered.
exists, indicates that that user is registered.
"""
"""
# Is this User Blocked?
blocked
=
models
.
BooleanField
(
default
=
False
)
# Let's associate a User to this RegisteredUser
# Let's associate a User to this RegisteredUser
user
=
models
.
OneToOneField
(
User
)
user
=
models
.
OneToOneField
(
User
)
...
@@ -51,7 +50,10 @@ class RegisteredUser(models.Model):
...
@@ -51,7 +50,10 @@ class RegisteredUser(models.Model):
# Are you approved to use Go?
# Are you approved to use Go?
approved
=
models
.
BooleanField
(
default
=
False
)
approved
=
models
.
BooleanField
(
default
=
False
)
# print(RegisteredUser)
# Is this User Blocked?
blocked
=
models
.
BooleanField
(
default
=
False
)
# str(RegisteredUser)
def
__str__
(
self
):
def
__str__
(
self
):
return
'<Registered User: %s - Approval Status: %s>'
%
(
self
.
user
,
self
.
approved
)
return
'<Registered User: %s - Approval Status: %s>'
%
(
self
.
user
,
self
.
approved
)
...
@@ -64,37 +66,37 @@ def handle_regUser_creation(sender, instance, created, **kwargs):
...
@@ -64,37 +66,37 @@ def handle_regUser_creation(sender, instance, created, **kwargs):
RegisteredUser
.
objects
.
create
(
user
=
instance
)
RegisteredUser
.
objects
.
create
(
user
=
instance
)
"""
This model represents a stored URL redirection rule. Each URL has an
owner, target url, short identifier, click counter, and expiration
date.
"""
@
python_2_unicode_compatible
@
python_2_unicode_compatible
class
URL
(
models
.
Model
):
class
URL
(
models
.
Model
):
"""
This model represents a stored URL redirection rule. Each URL has an
owner, target url, short identifier, click counter, and expiration
date.
"""
# Who is the owner of this Go link
# Who is the owner of this Go link
owner
=
models
.
ForeignKey
(
RegisteredUser
)
owner
=
models
.
ForeignKey
(
RegisteredUser
)
# When was this link created?
# 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
# What is the target URL for this Go link
target
=
models
.
URLField
(
max_length
=
1000
)
target
=
models
.
URLField
(
max_length
=
1000
)
# What is the actual go link (short url) for this URL
# What is the actual go link (short url) for this URL
short
=
models
.
SlugField
(
max_length
=
20
,
primary_key
=
True
)
short
=
models
.
SlugField
(
max_length
=
20
,
primary_key
=
True
)
# how many people have visited this Go link
# how many people have visited this Go link
clicks
=
models
.
IntegerField
(
default
=
0
)
clicks
=
models
.
IntegerField
(
default
=
0
)
# how many people have visited this Go link through the qr code
# 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
# 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
# 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)
# print(URL)
def
__str__
(
self
):
def
__str__
(
self
):
return
'<
%s
: %s>'
%
(
self
.
owner
.
user
,
self
.
target
)
return
'<
Owner: %s - Target URL
: %s>'
%
(
self
.
owner
.
user
,
self
.
target
)
# metadata for URL's
# metadata for URL's
class
Meta
:
class
Meta
:
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment