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
2fb09317
Unverified
Commit
2fb09317
authored
Mar 20, 2017
by
David Haynes
Browse files
Pendatic fix for comments
- one day I'll make up my mind on style
parent
46c5a592
Pipeline
#1105
passed with stage
in 1 minute and 1 second
Changes
11
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
go/go/admin.py
View file @
2fb09317
...
...
@@ -11,7 +11,7 @@ from go.models import URL, RegisteredUser
class
URLAdmin
(
admin
.
ModelAdmin
):
"""
Define what attributes display in the URL Admin
Define what attributes display in the URL Admin
"""
list_display
=
(
"target"
,
"short"
,
"owner"
,
"clicks"
,
"date_created"
,
"expires"
)
...
...
@@ -21,7 +21,7 @@ admin.site.register(URL, URLAdmin)
class
RegisteredUserInline
(
admin
.
StackedInline
):
"""
Define an inline admin descriptor for User model
Define an inline admin descriptor for User model
"""
model
=
RegisteredUser
...
...
@@ -29,7 +29,7 @@ class RegisteredUserInline(admin.StackedInline):
class
UserAdmin
(
UserAdmin
):
"""
Define a new User admin
Define a new User admin
"""
# see above class that we defined
...
...
go/go/cas_callbacks.py
View file @
2fb09317
...
...
@@ -5,13 +5,14 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
from
django.contrib.auth.models
import
User
from
django.conf
import
settings
# th
ird party i
mports
#
O
th
er I
mports
import
requests
"""
parse what peoplefinder sends back to us and make a list out of it
"""
def
pfparse
(
pf_name_result
):
"""
Parse what peoplefinder sends back to us and make a list out of it
"""
# name comes in format of Anderson, Nicholas J
name_list
=
pf_name_result
.
split
(
','
)
# there's random whitespace with the first name
...
...
@@ -27,10 +28,11 @@ def pfparse(pf_name_result):
new_name_list
=
[
first_name
,
name_list
[
0
]]
return
new_name_list
"""
get information from peoplefinder
"""
def
pfinfo
(
uname
):
"""
Get information from peoplefinder
"""
base_url
=
settings
.
PF_URL
url
=
base_url
+
"basic/all/"
+
str
(
uname
)
try
:
...
...
@@ -65,16 +67,16 @@ def pfinfo(uname):
# if the name is not in peoplefinder, return empty first and last name
except
IndexError
as
ex
:
print
(
"Name not found in peoplefinder."
)
return
[
''
,
''
]
return
[
''
,
''
]
except
Exception
as
ex
:
print
(
"Unknown peoplefinder error:"
,
ex
)
print
(
"Returning empty user info tuple."
)
return
[
''
,
''
]
"""
create a django user based off of the peoplefinder info we parsed earlier
"""
def
create_user
(
tree
):
"""
Create a django user based off of the peoplefinder info we parsed earlier
"""
print
(
"Parsing CAS information."
)
try
:
...
...
go/go/forms.py
View file @
2fb09317
...
...
@@ -2,7 +2,7 @@
from
__future__
import
unicode_literals
,
absolute_import
,
print_function
,
division
# Python stdlib Imports
from
datetime
import
date
,
datetime
,
timedelta
from
datetime
import
datetime
,
timedelta
from
six.moves
import
urllib
# Django Imports
...
...
@@ -22,11 +22,16 @@ from bootstrap3_datetime.widgets import DateTimePicker
class
URLForm
(
forms
.
ModelForm
):
"""
The form that is used in URL creation.
The form that is used in URL creation.
"""
# Prevent redirect loop links
# target -------------------------------------------------------------------
def
clean_target
(
self
):
"""
Prevent redirect loop links
"""
# get the entered target link
target
=
self
.
cleaned_data
.
get
(
'target'
)
try
:
...
...
@@ -57,13 +62,19 @@ class URLForm(forms.ModelForm):
})
)
# Check to make sure the short url has not been used
# short --------------------------------------------------------------------
def
unique_short
(
value
):
"""
Check to make sure the short url has not been used
"""
try
:
# if we're able to get a URL with the same short url
URL
.
objects
.
get
(
short__iexact
=
value
)
except
URL
.
DoesNotExist
as
ex
:
return
# then raise a ValidationError
raise
ValidationError
(
'Short url already exists.'
)
...
...
@@ -77,14 +88,16 @@ class URLForm(forms.ModelForm):
min_length
=
3
,
)
# define some string date standards
# expires ------------------------------------------------------------------
# Define some string date standards
DAY
=
'1 Day'
WEEK
=
'1 Week'
MONTH
=
'1 Month'
CUSTOM
=
'Custom Date'
NEVER
=
'Never'
#
d
efine a tuple of string date standards to be used as our date choices
#
D
efine a tuple of string date standards to be used as our date choices
EXPIRATION_CHOICES
=
(
(
DAY
,
DAY
),
(
WEEK
,
WEEK
),
...
...
@@ -102,8 +115,11 @@ class URLForm(forms.ModelForm):
widget
=
forms
.
RadioSelect
(),
)
# Check if the selected date is a valid date
def
valid_date
(
value
):
"""
Check if the selected date is a valid date
"""
# a valid date is one that is greater than today
if
value
>
timezone
.
now
():
return
...
...
@@ -130,8 +146,11 @@ class URLForm(forms.ModelForm):
)
)
# on initialization of the form, crispy forms renders this layout
def
__init__
(
self
,
*
args
,
**
kwargs
):
"""
On initialization of the form, crispy forms renders this layout
"""
# Grab that host info
self
.
host
=
kwargs
.
pop
(
'host'
,
None
)
super
(
URLForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
...
...
@@ -191,8 +210,11 @@ class URLForm(forms.ModelForm):
<br />"""
),
StrictButton
(
'Shorten'
,
css_class
=
"btn btn-primary btn-md col-md-4"
,
type
=
'submit'
)))
# metadata about this ModelForm
class
Meta
:
"""
Metadata about this ModelForm
"""
# what model this form is for
model
=
URL
# what attributes are included
...
...
@@ -200,7 +222,7 @@ class URLForm(forms.ModelForm):
class
SignupForm
(
forms
.
ModelForm
):
"""
The form that is used when a user is signing up to be a RegisteredUser
The form that is used when a user is signing up to be a RegisteredUser
"""
# The full name of the RegisteredUser
...
...
@@ -230,15 +252,20 @@ class SignupForm(forms.ModelForm):
# A user becomes registered when they agree to the TOS
registered
=
forms
.
BooleanField
(
required
=
True
,
# ***Need to replace lower url with production URL*** ie. go.gmu.edu/about#terms
# ***Need to replace lower url with production URL***
# ie. go.gmu.edu/about#terms
label
=
mark_safe
(
'Do you accept the <a href="http://127.0.0.1:8000/about#terms">Terms of Service</a>?'
),
)
# on initialization of the form, crispy forms renders this layout
def
__init__
(
self
,
request
,
*
args
,
**
kwargs
):
# Necessary to call request in forms.py, is otherwise restricted to views.py and models.py
"""
On initialization of the form, crispy forms renders this layout
"""
# Necessary to call request in forms.py, is otherwise restricted to
# views.py and models.py
self
.
request
=
request
super
(
SignupForm
,
self
).
__init__
(
*
args
,
**
kwargs
)
self
.
helper
=
FormHelper
()
...
...
@@ -261,8 +288,11 @@ class SignupForm(forms.ModelForm):
StrictButton
(
'Submit'
,
css_class
=
'btn btn-primary btn-md col-md-4'
,
type
=
'submit'
),
css_class
=
'col-md-6'
)))
# metadata about this ModelForm
class
Meta
:
"""
Metadata about this ModelForm
"""
# what model this form is for
model
=
RegisteredUser
# what attributes are included
...
...
go/go/models.py
View file @
2fb09317
...
...
@@ -22,8 +22,8 @@ hashids = Hashids(salt="srct.gmu.edu", alphabet=(string.ascii_lowercase + string
@
python_2_unicode_compatible
class
RegisteredUser
(
models
.
Model
):
"""
This is simply a wrapper model for the user object which, if an object
exists, indicates that that user is registered.
This is simply a wrapper model for the user object which, if an object
exists, indicates that that user is registered.
"""
# Let's associate a User to this RegisteredUser
...
...
@@ -53,15 +53,21 @@ class RegisteredUser(models.Model):
# Is this User Blocked?
blocked
=
models
.
BooleanField
(
default
=
False
)
# str(RegisteredUser)
def
__str__
(
self
):
"""
str(RegisteredUser)
"""
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
):
"""
When a post_save is called on a User object (and it is newly created), this
is called to create an associated RegisteredUser
"""
if
created
:
RegisteredUser
.
objects
.
create
(
user
=
instance
)
...
...
@@ -69,9 +75,9 @@ def handle_regUser_creation(sender, instance, created, **kwargs):
@
python_2_unicode_compatible
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.
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
...
...
@@ -94,19 +100,27 @@ class URL(models.Model):
# does this Go link expire on a certain date
expires
=
models
.
DateTimeField
(
blank
=
True
,
null
=
True
)
# print(URL)
def
__str__
(
self
):
"""
print(URL)
"""
return
'<Owner: %s - Target URL: %s>'
%
(
self
.
owner
.
user
,
self
.
target
)
# metadata for URL's
class
Meta
:
"""
metadata for URLs
"""
# they should be ordered by their short links
ordering
=
[
'short'
]
# legacy method to ensure that generated short URL's are valid
# should be updated to be simpler
@
staticmethod
def
generate_valid_short
():
"""
legacy method to ensure that generated short URL's are valid
should be updated to be simpler
"""
if
cache
.
get
(
"hashids_counter"
)
is
None
:
cache
.
set
(
"hashids_counter"
,
URL
.
objects
.
count
())
cache
.
incr
(
"hashids_counter"
)
...
...
go/go/test_cas_callbacks.py
View file @
2fb09317
...
...
@@ -5,17 +5,17 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
from
django.test
import
TestCase
# App Imports
from
go.cas_callbacks
import
pfparse
,
pfinfo
,
create_user
from
go.cas_callbacks
import
pfparse
,
pfinfo
class
CasCallbacksTest
(
TestCase
):
"""
Test cases for the functions in call_callbacks.
Test cases for the functions in call_callbacks.
"""
def
test_pf_peoplefinder_method
(
self
):
"""
Presently enrolled student who has been added to peoplefinder
Presently enrolled student who has been added to peoplefinder
"""
actual
=
pfinfo
(
'dhaynes3'
)
...
...
@@ -24,8 +24,8 @@ class CasCallbacksTest(TestCase):
def
test_pfparse_peoplefinder_method
(
self
):
"""
Test the parsing method to ensure that first and last names are seperated
accordingly and correctly.
Test the parsing method to ensure that first and last names are seperated
accordingly and correctly.
"""
actual
=
pfparse
(
"Haynes, David M"
)
...
...
@@ -34,7 +34,7 @@ class CasCallbacksTest(TestCase):
def
test_pfinfo_ldap_method
(
self
):
"""
student no longer in peoplefinder, or who hasn't yet been added
student no longer in peoplefinder, or who hasn't yet been added
"""
actual
=
pfinfo
(
'lfaraone'
)
...
...
@@ -43,7 +43,7 @@ class CasCallbacksTest(TestCase):
def
test_pfinfo_employee_method
(
self
):
"""
student employees will have their staff info return before their student info
student employees will have their staff info return before their student info
"""
actual
=
pfinfo
(
'nander13'
)
...
...
@@ -52,7 +52,7 @@ class CasCallbacksTest(TestCase):
def
test_pfinfo_dne
(
self
):
"""
a name not found for either (should never happen, but gracefully handle anyway)
a name not found for either (should never happen, but gracefully handle anyway)
"""
actual
=
pfinfo
(
'bobama'
)
...
...
go/go/test_forms.py
View file @
2fb09317
...
...
@@ -5,28 +5,28 @@ from __future__ import unicode_literals, absolute_import, print_function, divisi
from
django.test
import
TestCase
# App Imports
from
go.forms
import
*
from
go.forms
import
URLForm
,
SignupForm
class
URLFormTest
(
TestCase
):
"""
Test cases for the URL form
Test cases for the URL form
"""
def
test_django_test
(
self
):
"""
Default test case, does not actually test anything
Default test case, does not actually test anything
"""
self
.
assertEqual
(
"Hello World!"
,
"Hello World!"
)
class
SignupForm
(
TestCase
):
"""
Test cases for the Signup form
Test cases for the Signup form
"""
def
test_django_test
(
self
):
"""
Default test case, does not actually test anything
Default test case, does not actually test anything
"""
self
.
assertEqual
(
"Hello World!"
,
"Hello World!"
)
go/go/test_models.py
View file @
2fb09317
...
...
@@ -12,13 +12,13 @@ from go.models import URL, RegisteredUser
class
RegisteredUserTest
(
TestCase
):
"""
Test cases for the RegisteredUser Model
Test cases for the RegisteredUser Model
"""
def
setUp
(
self
):
"""
Set up any variables such as dummy objects that will be utilised in
testing methods
Set up any variables such as dummy objects that will be utilised in
testing methods
"""
User
.
objects
.
create
(
username
=
'dhaynes'
,
password
=
'password'
)
...
...
@@ -27,7 +27,7 @@ class RegisteredUserTest(TestCase):
def
test_registereduser_creation
(
self
):
"""
check if RegisteredUsers are actually made
check if RegisteredUsers are actually made
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -38,7 +38,7 @@ class RegisteredUserTest(TestCase):
def
test_full_name
(
self
):
"""
check if full_name char field functions as intentioned
check if full_name char field functions as intentioned
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -50,7 +50,7 @@ class RegisteredUserTest(TestCase):
def
test_full_name_length
(
self
):
"""
check if full_name char field functions as intentioned
check if full_name char field functions as intentioned
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -74,7 +74,7 @@ class RegisteredUserTest(TestCase):
def
test_organization
(
self
):
"""
check if organization char field functions as intentioned
check if organization char field functions as intentioned
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -86,7 +86,7 @@ class RegisteredUserTest(TestCase):
def
test_organization_length
(
self
):
"""
check if organization char field functions as intentioned
check if organization char field functions as intentioned
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -112,7 +112,7 @@ class RegisteredUserTest(TestCase):
def
test_description_blank
(
self
):
"""
- add in description (blank)
- add in description (blank)
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -121,7 +121,7 @@ class RegisteredUserTest(TestCase):
def
test_description_text
(
self
):
"""
- add in description (text)
- add in description (text)
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -139,7 +139,7 @@ class RegisteredUserTest(TestCase):
def
test_registered
(
self
):
"""
test the registered bool
test the registered bool
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -151,7 +151,7 @@ class RegisteredUserTest(TestCase):
def
test_registered_default
(
self
):
"""
test the registered bool
test the registered bool
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -163,7 +163,7 @@ class RegisteredUserTest(TestCase):
def
test_approved
(
self
):
"""
test the approved bool
test the approved bool
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -175,7 +175,7 @@ class RegisteredUserTest(TestCase):
def
test_approved_default
(
self
):
"""
test the approved bool default
test the approved bool default
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -187,7 +187,7 @@ class RegisteredUserTest(TestCase):
def
test_blocked
(
self
):
"""
test the blocked bool
test the blocked bool
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -199,7 +199,7 @@ class RegisteredUserTest(TestCase):
def
test_approved_default
(
self
):
"""
test the blocked bool default
test the blocked bool default
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -212,7 +212,7 @@ class RegisteredUserTest(TestCase):
def
test_check_str
(
self
):
"""
check printing
check printing
"""
get_user
=
User
.
objects
.
get
(
username
=
'dhaynes'
)
...
...
@@ -224,13 +224,13 @@ class RegisteredUserTest(TestCase):
class
URLTest
(
TestCase
):
"""
Test cases for the URL Model
Test cases for the URL Model
"""
def
setUp
(
self
):
"""
Set up any variables such as dummy objects that will be utilised in
testing methods
Set up any variables such as dummy objects that will be utilised in
testing methods
"""
# Setup a blank URL object with an owner
...
...
@@ -246,7 +246,7 @@ class URLTest(TestCase):
def
test_change_owner
(
self
):
"""
Test the ability to change the owner of a URL
Test the ability to change the owner of a URL
"""
# Original owner
...
...
@@ -268,7 +268,7 @@ class URLTest(TestCase):
def
test_date_created
(
self
):
"""
Test that the timedate is set properly on URL creation
Test that the timedate is set properly on URL creation
"""
# Get a date
...
...
@@ -290,7 +290,7 @@ class URLTest(TestCase):
def
test_target
(
self
):
"""
Test that the target field properly accepts a URL
Test that the target field properly accepts a URL
"""
# Get a URL
...
...
@@ -309,7 +309,7 @@ class URLTest(TestCase):
def
test_target_length
(
self
):
"""
Test that we can't input a URL longer than 1000 chars
Test that we can't input a URL longer than 1000 chars
"""
# Get a URL
...
...
@@ -333,7 +333,7 @@ class URLTest(TestCase):
def
test_short
(
self
):
"""
Test that the short field functions as intended
Test that the short field functions as intended
"""
# Get a short
...
...
@@ -352,7 +352,7 @@ class URLTest(TestCase):
def
test_short_dupe
(
self
):
"""
Test that the short field primary key functions as intended
Test that the short field primary key functions as intended
"""
# Get a short
...
...
@@ -375,7 +375,7 @@ class URLTest(TestCase):
def
test_short_length
(
self
):
"""
Test that a short field can be no longer than 20 characters
Test that a short field can be no longer than 20 characters
"""
# Get a invalid short
...
...
@@ -398,7 +398,7 @@ class URLTest(TestCase):
def
test_clicks
(
self
):
"""
Test that clicks incremention works
Test that clicks incremention works
"""
# Get the URL to test
...
...
@@ -416,7 +416,7 @@ class URLTest(TestCase):
def
test_qrclicks
(
self
):
"""
Test that cliqrclickscks incremention works
Test that cliqrclickscks incremention works
"""
# Get the URL to test
...
...
@@ -434,7 +434,7 @@ class URLTest(TestCase):
def
test_socialclicks
(
self
):
"""
Test that socialclicks incremention works
Test that socialclicks incremention works
"""
# Get the URL to test
...
...
@@ -452,7 +452,7 @@ class URLTest(TestCase):
def
test_expires
(
self
):
"""
Test that the expires field functions as intended
Test that the expires field functions as intended
"""
tomorrow
=
timezone
.
now
()
+
timezone
.
timedelta
(
days
=
1
)
...
...
@@ -473,7 +473,7 @@ class URLTest(TestCase):
def
test_check_str
(
self
):
"""
check printing
check printing
"""
# Get the URL to test
...
...
@@ -492,7 +492,7 @@ class URLTest(TestCase):