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
02c26f85
Commit
02c26f85
authored
Jan 02, 2017
by
David Haynes
Browse files
Modify print functions for models to be python3 compatabile
- unicode() --> str()
parent
8b1a8f77
Changes
1
Hide whitespace changes
Inline
Side-by-side
go/go/models.py
View file @
02c26f85
...
@@ -8,11 +8,11 @@ from django.utils import timezone
...
@@ -8,11 +8,11 @@ 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.db.models.signals
import
post_save
from
django.dispatch
import
receiver
from
django.dispatch
import
receiver
from
django.utils.encoding
import
python_2_unicode_compatible
# Other Imports
# Other Imports
from
hashids
import
Hashids
# http://hashids.org/python/
import
string
import
string
# http://hashids.org/python/
from
hashids
import
Hashids
# 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
))
...
@@ -21,37 +21,38 @@ hashids = Hashids(salt="srct.gmu.edu", alphabet=(string.ascii_lowercase + string
...
@@ -21,37 +21,38 @@ hashids = Hashids(salt="srct.gmu.edu", alphabet=(string.ascii_lowercase + string
This is simply a wrapper model for the user object which, if an object
This is simply a wrapper model for the user object which, if an object
exists, indicates that that user is registered.
exists, indicates that that user is registered.
"""
"""
@
python_2_unicode_compatible
class
RegisteredUser
(
models
.
Model
):
class
RegisteredUser
(
models
.
Model
):
# Is this User Blocked?
# Is this User Blocked?
blocked
=
models
.
BooleanField
(
default
=
False
)
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
)
# What is your name?
# 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?
# What organization are you associated with?
organization
=
models
.
CharField
(
organization
=
models
.
CharField
(
blank
=
False
,
blank
=
False
,
max_length
=
100
,
max_length
=
100
,
)
)
# Why do you want to use Go?
# Why do you want to use Go?
description
=
models
.
TextField
(
blank
=
True
)
description
=
models
.
TextField
(
blank
=
True
)
# Have you filled out the registration form?
# Have you filled out the registration form?
registered
=
models
.
BooleanField
(
default
=
False
)
registered
=
models
.
BooleanField
(
default
=
False
)
# Are you approved to use Go?
# Are you approved to use Go?
approved
=
models
.
BooleanField
(
default
=
False
)
approved
=
models
.
BooleanField
(
default
=
False
)
# print(RegisteredUser)
# print(RegisteredUser)
def
__
unicode
__
(
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
)
...
@@ -68,6 +69,7 @@ def handle_regUser_creation(sender, instance, created, **kwargs):
...
@@ -68,6 +69,7 @@ def handle_regUser_creation(sender, instance, created, **kwargs):
owner, target url, short identifier, click counter, and expiration
owner, target url, short identifier, click counter, and expiration
date.
date.
"""
"""
@
python_2_unicode_compatible
class
URL
(
models
.
Model
):
class
URL
(
models
.
Model
):
# Who is the owner of this Go link
# Who is the owner of this Go link
...
@@ -91,7 +93,7 @@ class URL(models.Model):
...
@@ -91,7 +93,7 @@ class URL(models.Model):
expires
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
expires
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
# print(URL)
# print(URL)
def
__
unicode
__
(
self
):
def
__
str
__
(
self
):
return
'<%s : %s>'
%
(
self
.
owner
.
user
,
self
.
target
)
return
'<%s : %s>'
%
(
self
.
owner
.
user
,
self
.
target
)
# metadata for URL's
# metadata for URL's
...
@@ -113,6 +115,6 @@ class URL(models.Model):
...
@@ -113,6 +115,6 @@ class URL(models.Model):
URL
.
objects
.
get
(
short__iexact
=
short
)
URL
.
objects
.
get
(
short__iexact
=
short
)
tries
+=
1
tries
+=
1
cache
.
incr
(
"hashids_counter"
)
cache
.
incr
(
"hashids_counter"
)
except
URL
.
DoesNotExist
:
except
URL
.
DoesNotExist
as
ex
:
return
short
return
short
return
None
return
None
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