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