Unverified Commit ed835333 authored by David Haynes's avatar David Haynes
Browse files

Merge branch '109-my-links-to-index' into 2.2-dev

parents b266fc9e ef15de60
Pipeline #1121 passed with stage
in 1 minute and 12 seconds
<!-- 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 &bull; A University Branded URL Shortener
SRCT Go &bull; My Links
{% endblock %}
<!-- define the content block for the page -->
......@@ -21,42 +18,27 @@ SRCT Go &bull; 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 'index' %}"><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>&nbsp;&nbsp;&nbsp;None found <i class="fa fa-frown-o"></i></h3>
{% endfor %}
</div>
{% endblock %}
<!-- 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 &bull; My Links
SRCT Go &bull; A University Branded URL Shortener
{% endblock %}
<!-- define the content block for the page -->
......@@ -18,27 +21,42 @@ SRCT Go &bull; 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>&nbsp;&nbsp;&nbsp;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 %}
......@@ -27,7 +27,7 @@
{% if user.is_authenticated %}
<!-- only if they are an approved user -->
{% if user.registereduser.approved %}
<li><a href="{% url 'my_links' %}">My Links</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 %}
......
......@@ -24,20 +24,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.
elif not request.user.registereduser.approved:
if not request.user.registereduser.approved:
if request.user.registereduser.blocked:
return render(request, 'banned.html')
else:
......@@ -77,10 +99,24 @@ def index(request):
# 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)
......
......@@ -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'),
......
Markdown is supported
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment