Verified Commit 8a7c8eb4 authored by David Haynes's avatar David Haynes 🙆

More sane URL names

- /myLinks -> /my
- /newLink -> /new
- /useradmin -> /manage
parent e44a2976
Pipeline #1959 failed with stages
in 1 minute and 22 seconds
......@@ -33,7 +33,7 @@
<input class="inputfilter" type="text" id="appliedInput"
placeholder="Search Usernames or Full Names">
<h3>Users awaiting moderation</h3>
<form method="post" action="useradmin">
<form method="post" action="manage">
<!-- csrf protection -->
{% csrf_token %}
<!-- define out table of users that need approval -->
......@@ -151,7 +151,7 @@
<input class="inputfilter" type="text" id="blockedInput"
placeholder="Search Usernames or Full Names">
<h3>Blocked Users</h3>
<form method="post" action="useradmin">
<form method="post" action="manage">
<!-- csrf protection -->
{% csrf_token %}
<table class="table table-striped table-hover" id="blockedTable">
......@@ -226,7 +226,7 @@
<input class="inputfilter" type="text" id="currentInput"
placeholder="Search Usernames or Full Names">
<h3>Current Users</h3>
<form method="post" action="useradmin">
<form method="post" action="manage">
<!-- csrf protection -->
{% csrf_token %}
<table class="table table-striped table-hover " id="currentTable">
......
"""
go/views.py
"""
The functions that handle a request to a given URL. Get some data, manipulate
it, and return a rendered template.
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
......@@ -27,7 +29,6 @@ from ratelimit.decorators import ratelimit
from .forms import SignupForm, URLForm, EditForm
from .models import URL, RegisteredUser
def index(request):
"""
If a user is logged in, this view displays all the information about all
......@@ -43,15 +44,15 @@ def index(request):
# List of sort methods and their display name "Column" : "Name"
SORT_METHODS = {
"-date_created":"Most Recent",
"-date_created": "Most Recent",
"date_created": "Oldest",
"short":"Alphabetical (A-Z)",
"-short":"Alphabetical (Z-A)",
"-clicks":"Most Popular",
"clicks":"Least Popular",
"-expires":"Expiring Soon"
"short": "Alphabetical (A-Z)",
"-short": "Alphabetical (Z-A)",
"-clicks": "Most Popular",
"clicks": "Least Popular",
"-expires": "Expiring Soon"
}
# Get the requested sort method, default to "-date_created" : "Most Recent"
sort_method = request.GET.get('sort', '-date_created')
......@@ -83,7 +84,6 @@ def new_link(request):
not_registered error page. If they are logged in AND registered, they
get the URL registration form.
"""
# If the user isn't approved, then display the you're not approved page.
if not request.user.registereduser.approved:
if request.user.registereduser.blocked:
......@@ -91,7 +91,6 @@ def new_link(request):
else:
return render(request, 'not_registered.html')
# Initialize a URL form
url_form = URLForm(host=request.META.get('HTTP_HOST')) # unbound form
......@@ -107,7 +106,7 @@ def new_link(request):
# Call our post method to assemble our new URL object
res = post(request, url_form)
# If there is a 500 error returned, handle it
# 500 error
if res == 500:
return HttpResponseServerError(render(request, '500.html'))
......@@ -121,7 +120,6 @@ def new_link(request):
'form': url_form,
})
# Render index.html passing the form to the template
return render(request, 'core/new_link.html', {
'form': url_form,
......@@ -414,15 +412,18 @@ def signup(request):
to_admin = EmailMessage(
'Signup from %s' % (request.user.registereduser.user),
######################
'%s signed up at %s\n\n'
'Username: %s\n'
'Organization: %s\n\n'
'Message: %s\n\n'
'You can contact the user directly by replying to this email or '
'reply all to contact the user and notfiy the mailing list.\n'
'Please head to go.gmu.edu/useradmin to approve or '
'deny this application.'
%(
"""
%s signed up at %s\n\n
Username: %s\n
Organization: %s\n\n
Message: %s\n\n
You can contact the user directly by replying to this email or reply all to contact the user and notify the mailing list.\n
Please head to go.gmu.edu/manage to approve or deny this application.'
"""
% (
str(full_name), str(timezone.now()).strip(),
str(request.user.registereduser.user), str(organization),
str(description)
......@@ -437,12 +438,15 @@ def signup(request):
send_mail(
'We have received your Go application!',
######################
'Hey there %s,\n\n'
'The Go admins have received your application and are '
'currently in the process of reviewing it.\n\n'
'You will receive another email when you have been '
'approved.\n\n'
'- Go Admins'
"""
Hey there %s,\n\n
The Go admins have received your application and are currently in the process of reviewing it.\n\n
You will receive another email when you have been approved.\n\n
- Go Admins
"""
% (str(full_name)),
######################
settings.EMAIL_FROM,
......@@ -468,7 +472,7 @@ def redirection(request, short):
# Get the current domain info
domain = "%s://%s" % (request.scheme, request.META.get('HTTP_HOST')) + "/"
# Get the URL object that relates to the requested Go link
url = get_object_or_404(URL, short__iexact=short)
# Increment our clicks by one
......@@ -490,7 +494,7 @@ def redirection(request, short):
if 'social' in request.GET:
url.socialclicks += 1
# Save our data and redirect the user towards thier destination
# Save our data and redirect the user towards their destination
url.save()
return redirect(url.target)
......@@ -499,7 +503,6 @@ def staff_member_required(view_func, redirect_field_name=REDIRECT_FIELD_NAME, lo
Decorator function for views that checks that the user is logged in and is
a staff member, displaying the login page if necessary.
"""
return user_passes_test(
lambda u: u.is_active and u.is_staff,
login_url=login_url,
......@@ -564,7 +567,7 @@ def useradmin(request):
)
# Delete their associated RegisteredUsers
to_deny.user.delete()
return HttpResponseRedirect('useradmin')
return HttpResponseRedirect('manage')
# If we're blocking users
elif '_block' in request.POST:
......@@ -613,7 +616,7 @@ def useradmin(request):
)
to_un_block.blocked = False
to_un_block.save()
return HttpResponseRedirect('useradmin')
return HttpResponseRedirect('manage')
# If we're removing existing users
elif '_remove' in request.POST:
......@@ -635,14 +638,12 @@ def useradmin(request):
[user_mail]
)
to_remove.user.delete()
return HttpResponseRedirect('useradmin')
return HttpResponseRedirect('manage')
# Get a list of all RegisteredUsers that need to be approved
need_approval = RegisteredUser.objects.filter(registered=True).filter(
approved=False).filter(blocked=False)
need_approval = RegisteredUser.objects.filter(registered=True).filter(approved=False).filter(blocked=False)
# Get a list of all RegisteredUsers that are currently users
current_users = RegisteredUser.objects.filter(approved=True).filter(
registered=True).filter(blocked=False)
current_users = RegisteredUser.objects.filter(approved=True).filter(registered=True).filter(blocked=False)
# Get a list of all RegisteredUsers that are blocked
blocked_users = RegisteredUser.objects.filter(blocked=True)
......
......@@ -74,13 +74,20 @@ class UrlsTest(TestCase):
url = reverse('signup')
self.assertEqual(url, '/signup')
def test_new(self):
"""
/new - Create a new Go Link
"""
url = reverse("new_link")
self.assertEqual(url, '/new')
def test_my_links_reverse(self):
"""
/myLinks - My-Links page, view and review links.
/my - My-Links page, view and review links.
"""
url = reverse('my_links')
self.assertEqual(url, '/myLinks')
self.assertEqual(url, '/my')
def test_edit_reverse_chars(self):
"""
......@@ -114,7 +121,6 @@ class UrlsTest(TestCase):
url = reverse('edit', args=['dhaynes123_-'])
self.assertEqual(url, '/edit/dhaynes123_-')
def test_delete_reverse_chars(self):
"""
/delete/<short> - Delete a link, no content display.
......
"""
settings/urls.py
"""
The URLs of the project and their associated view that requests are routed to.
"""
# Future Imports
from __future__ import (absolute_import, division, print_function,
unicode_literals)
......@@ -20,27 +21,25 @@ import go.views
# application. Such modules are expected to register models with the admin.
admin.autodiscover()
# Main list of project URL's
urlpatterns = [
# / - Homepage url. Cached for 1 second (this is the page you see after
# logging in, so having it show as not logged in is strange)
url(r'^$', cache_page(1)(go.views.index), name='index'),
# /view/<short> - View URL data. Cached for 15 minutes
url(r'^view/(?P<short>[-\w]+)$', cache_page(60*15)(go.views.view), name='view'),
url(r'^view/(?P<short>[-\w]+)$', cache_page(60 * 15)(go.views.view), name='view'),
# /about - About page. Cached for 15 minutes
url(r'^about/?$', cache_page(60*15)(TemplateView.as_view(template_name='core/about.html')),
name='about'),
url(r'^about/?$',cache_page(60 * 15)(TemplateView.as_view(template_name='core/about.html')), name='about'),
# /signup - Signup page for access. Cached for 15 minutes
url(r'^signup/?$', cache_page(60*15)(go.views.signup), name='signup'),
url(r'^signup/?$', cache_page(60 * 15)(go.views.signup), name='signup'),
# /newLink - My-Links page, view and review links.
url(r'^newLink/?$', go.views.new_link, name='new_link'),
# /new - Create a new Go Link
url(r'^new/?$', 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'),
# /my - My-Links page, view and review links.
url(r'^my/?$', go.views.my_links, name='my_links'),
# /edit/<short> - Edit link form
url(r'^edit/(?P<short>[-\w]+)$', go.views.edit, name='edit'),
......@@ -49,25 +48,18 @@ urlpatterns = [
url(r'^delete/(?P<short>[-\w]+)$', go.views.delete, name='delete'),
# /registered - registration complete page. Cached for 15 minutes
url(r'^registered/?$', cache_page(60*15)(TemplateView.as_view(template_name='registered.html')),
name='registered'),
url(r'^registered/?$', cache_page(60 * 15)(TemplateView.as_view(template_name='registered.html')), name='registered'),
# /admin - Administrator interface.
url(r'^admin/?', admin.site.urls, name='go_admin'),
# /useradmin - user approval interface
url(r'^useradmin/?$', go.views.useradmin, name='useradmin'),
]
# /manage - user approval interface
url(r'^manage/?$', go.views.useradmin, name='useradmin'),
# Handle authentication pages
urlpatterns += [
# Auth pages
# Authentication URLs
url(r'^login$', django.contrib.auth.views.login, name='go_login'),
url(r'^logout$', django.contrib.auth.views.logout, {'next_page': '/'},
name='go_logout'),
]
url(r'^logout$', django.contrib.auth.views.logout, {'next_page': '/'}, name='go_logout'),
urlpatterns += [
# Redirection regex.
url(r'^(?P<short>[-\w]+)$', go.views.redirection, name='redirection'),
]
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