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
32abc9ea
Commit
32abc9ea
authored
Feb 26, 2017
by
Grady Moran
Browse files
cleaned up comments and fixed a typo
(Closes
#108
)
parent
33b00692
Pipeline
#974
passed with stage
in 1 minute and 14 seconds
Changes
1
Pipelines
1
Hide whitespace changes
Inline
Side-by-side
go/go/forms.py
View file @
32abc9ea
...
...
@@ -16,8 +16,7 @@ from crispy_forms.layout import Layout, Fieldset, Submit, HTML, Div, Field
from
crispy_forms.bootstrap
import
StrictButton
,
PrependedText
,
Accordion
,
AccordionGroup
from
bootstrap3_datetime.widgets
import
DateTimePicker
from
datetime
import
date
,
datetime
,
timedelta
from
six.moves
import
urllib
# this probably isn't supposed to be formatted like this
from
six.moves
import
urllib
"""
The form that is used in URL creation.
...
...
@@ -28,18 +27,19 @@ class URLForm(forms.ModelForm):
def
clean_target
(
self
):
# get the entered target link
target
=
self
.
cleaned_data
.
get
(
'target'
)
# if the entered target link leads to an infinite loop or just has some issue
# note it WILL permit links that have go in an intermediary stage... such as bit.ly -> go -> not go.
try
:
final_url
=
urllib
.
request
.
urlopen
(
target
).
geturl
()
# if visiting the provided url results in an HTTP error, or redirects
# to a page that results in an HTTP error
except
urllib
.
error
.
URLError
as
e
:
# to permit users to enter sites that return most errors, but
# prevent them from entering sites that result in an HTTP 300 error
if
any
(
int
(
str
(
e
)[
11
:
14
])
==
errorNum
for
errorNum
in
range
(
300
,
308
)):
raise
ValidationError
(
"Link result in a 300 error"
)
raise
ValidationError
(
"Link result
s
in a 300 error"
)
else
:
final_url
=
""
# if the host (go.gmu.edu) is in the entered target link or where it redirects
# if the host (go.gmu.edu) is in the entered target link or where it
# redirects
if
self
.
host
in
final_url
or
self
.
host
in
target
:
raise
ValidationError
(
"You can't make a Go link to Go silly!"
)
else
:
...
...
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