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
844c403a
Commit
844c403a
authored
Mar 26, 2017
by
David Haynes
Browse files
Merge branch '2.2-dev' into 43-unittests
parents
b55d8f4d
67650bec
Changes
5
Hide whitespace changes
Inline
Side-by-side
go/go/templates/core/index.html
View file @
844c403a
<!-- include the base html template -->
{% extends 'layouts/base.html' %}
<!-- load django crispy forms' tags -->
{% load crispy_forms_tags %}
<!-- define the page title block -->
{% block title %}
SRCT Go
•
A University Branded URL Shortener
SRCT Go
•
My Links
{% endblock %}
<!-- define the content block for the page -->
...
...
@@ -21,42 +18,27 @@ SRCT Go • A University Branded URL Shortener
<i
class=
"fa fa-circle fa-stack-2x"
></i>
<i
class=
"fa fa-link fa-stack-1x fa-inverse"
></i>
</span>
<i
class=
"fa"
>
Shorten URL
</i>
<i
class=
"fa"
>
My Links
</i>
</strong></h1>
</div>
</div>
<div
class=
"newlink"
style=
"text-align: right;"
>
<a
href=
"{% url 'new_link' %}"
><i
class=
"fa fa-plus"
aria-hidden=
"true"
></i>
Add new link
</a>
</div>
</div>
<!-- call django crispy forms to render the go link creation form here -->
{% crispy form %}
<!-- load some JS to hide/show the custom date field -->
<script
type=
"text/javascript"
>
$
(
function
()
{
// hide by default
$
(
"
div_id_expires_custom
"
).
hide
();
// if the expires_custom checkbox is checked..
if
(
$
(
"
#id_expires_5
"
).
is
(
"
:checked
"
))
{
// display the field
$
(
"
#div_id_expires_custom
"
).
slideDown
();
}
else
{
// keep it up
$
(
"
#div_id_expires_custom
"
).
slideUp
();
}
// if the expires_custom checkbox is clicked..
$
(
"
#div_id_expires
"
).
click
(
function
()
{
// if the expires_custom checkbox is checked..
if
(
$
(
"
#id_expires_5
"
).
is
(
"
:checked
"
))
{
// display the field
$
(
"
#div_id_expires_custom
"
).
slideDown
();
}
else
{
// keep it hidden
$
(
"
#div_id_expires_custom
"
).
slideUp
();
}
})
})
</script>
<!-- show all of the links -->
<div
class=
"row"
>
<!-- for every url in the urls list-->
{% for url in urls %}
<legend>
<!-- include the link box for this url -->
{% include 'link_box.html' %}
</legend>
<!-- unless the list is empty -->
{% empty %}
<h3>
None found
<i
class=
"fa fa-frown-o"
></i></h3>
{% endfor %}
</div>
{% endblock %}
go/go/templates/
my
_link
s
.html
→
go/go/templates/
core/new
_link.html
View file @
844c403a
<!-- include the base html template -->
{% extends 'layouts/base.html' %}
<!-- load django crispy forms' tags -->
{% load crispy_forms_tags %}
<!-- define the page title block -->
{% block title %}
SRCT Go
•
My Links
SRCT Go
•
A University Branded URL Shortener
{% endblock %}
<!-- define the content block for the page -->
...
...
@@ -18,27 +21,42 @@ SRCT Go • My Links
<i
class=
"fa fa-circle fa-stack-2x"
></i>
<i
class=
"fa fa-link fa-stack-1x fa-inverse"
></i>
</span>
<i
class=
"fa"
>
My Links
</i>
<i
class=
"fa"
>
Shorten URL
</i>
</strong></h1>
</div>
</div>
<div
class=
"newlink"
style=
"text-align: right;"
>
<a
href=
"{% url 'index' %}"
><i
class=
"fa fa-plus"
aria-hidden=
"true"
></i>
Add new link
</a>
</div>
</div>
<!-- show all of the links -->
<div
class=
"row"
>
<!-- for every url in the urls list-->
{% for url in urls %}
<legend>
<!-- include the link box for this url -->
{% include 'link_box.html' %}
</legend>
<!-- unless the list is empty -->
{% empty %}
<h3>
None found
<i
class=
"fa fa-frown-o"
></i></h3>
{% endfor %}
</div>
<!-- call django crispy forms to render the go link creation form here -->
{% crispy form %}
<!-- load some JS to hide/show the custom date field -->
<script
type=
"text/javascript"
>
$
(
function
()
{
// hide by default
$
(
"
div_id_expires_custom
"
).
hide
();
// if the expires_custom checkbox is checked..
if
(
$
(
"
#id_expires_5
"
).
is
(
"
:checked
"
))
{
// display the field
$
(
"
#div_id_expires_custom
"
).
slideDown
();
}
else
{
// keep it up
$
(
"
#div_id_expires_custom
"
).
slideUp
();
}
// if the expires_custom checkbox is clicked..
$
(
"
#div_id_expires
"
).
click
(
function
()
{
// if the expires_custom checkbox is checked..
if
(
$
(
"
#id_expires_5
"
).
is
(
"
:checked
"
))
{
// display the field
$
(
"
#div_id_expires_custom
"
).
slideDown
();
}
else
{
// keep it hidden
$
(
"
#div_id_expires_custom
"
).
slideUp
();
}
})
})
</script>
{% endblock %}
go/go/templates/layouts/navigation.html
View file @
844c403a
...
...
@@ -27,7 +27,7 @@
{% if user.is_authenticated %}
<!-- only if they are an approved user -->
{% if user.registereduser.approved %}
<li><a
href=
"{% url '
my
_link
s
' %}"
>
My
Link
s
</a></li>
<li><a
href=
"{% url '
new
_link' %}"
>
New
Link
</a></li>
{% endif %}
<!-- only if the current user has not registered to use go -->
{% if not user.registereduser.registered %}
...
...
go/go/views.py
View file @
844c403a
...
...
@@ -28,20 +28,42 @@ from go.models import URL, RegisteredUser
from
go.forms
import
URLForm
,
SignupForm
def
index
(
request
):
"""
If a user is logged in, this view displays all the information about all
of their URLs. Otherwise, it will show the public landing page
"""
# If the user is not authenticated, show them a public landing page.
if
not
request
.
user
.
is_authenticated
():
return
render
(
request
,
'public_landing.html'
)
# Do not display this page to unapproved users
if
not
request
.
user
.
registereduser
.
approved
:
return
render
(
request
,
'not_registered.html'
)
# Get the current domain info
domain
=
"%s://%s"
%
(
request
.
scheme
,
request
.
META
.
get
(
'HTTP_HOST'
))
+
"/"
# Grab a list of all the URL's that are currently owned by the user
urls
=
URL
.
objects
.
filter
(
owner
=
request
.
user
.
registereduser
)
# Render my_links.html passing the list of URL's and Domain to the template
return
render
(
request
,
'core/index.html'
,
{
'urls'
:
urls
,
'domain'
:
domain
,
})
@
login_required
def
new_link
(
request
):
"""
This view handles the homepage that the user is presented with when
they request '/'. If they're not logged in, they're redirected to
they request '/
newLink
'. If they're not logged in, they're redirected to
login. If they're logged in but not registered, they're given the
not_registered error page. If they are logged in AND registered, they
get the URL registration form.
"""
# If the user is blocked, redirect them to the blocked page.
# If the user is not authenticated, show them a public landing page.
if
not
request
.
user
.
is_authenticated
():
return
render
(
request
,
'public_landing.html'
)
# If the user isn't approved, then display the you're not approved page.
el
if
not
request
.
user
.
registereduser
.
approved
:
if
not
request
.
user
.
registereduser
.
approved
:
if
request
.
user
.
registereduser
.
blocked
:
return
render
(
request
,
'banned.html'
)
else
:
...
...
@@ -73,16 +95,30 @@ def index(request):
# Else, there is an error, redisplay the form with the validation errors
else
:
# Render index.html passing the form to the template
return
render
(
request
,
'core/
index
.html'
,
{
return
render
(
request
,
'core/
new_link
.html'
,
{
'form'
:
url_form
,
})
# Render index.html passing the form to the template
return
render
(
request
,
'core/
index
.html'
,
{
return
render
(
request
,
'core/
new_link
.html'
,
{
'form'
:
url_form
,
})
@
login_required
def
my_links
(
request
):
"""
for compatibility, just in case
shows the same thing as /, but requires login to be consistent with
/newLink
"""
if
not
request
.
user
.
registereduser
.
approved
:
if
request
.
user
.
registereduser
.
blocked
:
return
render
(
request
,
'banned.html'
)
else
:
return
render
(
request
,
'not_registered.html'
)
return
index
(
request
)
# Rate limits are completely arbitrary
@
ratelimit
(
key
=
'user'
,
rate
=
'3/m'
,
method
=
'POST'
,
block
=
True
)
@
ratelimit
(
key
=
'user'
,
rate
=
'25/d'
,
method
=
'POST'
,
block
=
True
)
...
...
go/settings/urls.py
View file @
844c403a
...
...
@@ -31,8 +31,11 @@ urlpatterns = [
# /signup - Signup page for access. Cached for 15 minutes
url
(
r
'^signup/?$'
,
cache_page
(
60
*
15
)(
go
.
views
.
signup
),
name
=
'signup'
),
# /myLinks - My-Links page, view and review links. Cached for 5 seconds
url
(
r
'^myLinks/?$'
,
cache_page
(
5
)(
go
.
views
.
my_links
),
name
=
'my_links'
),
# /new - My-Links page, view and review links.
url
(
r
'^newLink/?$'
,
go
.
views
.
new_link
,
name
=
'new_link'
),
# /myLinks - My-Links page, view and review links.
url
(
r
'^myLinks/?$'
,
go
.
views
.
my_links
,
name
=
'my_links'
),
# /delete/<short> - Delete a link, no content display.
url
(
r
'^delete/(?P<short>[-\w]+)$'
,
go
.
views
.
delete
,
name
=
'delete'
),
...
...
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