diff --git a/go/go/templates/admin/useradmin.html b/go/go/templates/admin/useradmin.html index 21bb38be4466e3bc69bc35a6944d4cc289360b18..dab1597aa7174b56317643f15098cd6c82e7255e 100644 --- a/go/go/templates/admin/useradmin.html +++ b/go/go/templates/admin/useradmin.html @@ -33,7 +33,7 @@

Users awaiting moderation

-
+ {% csrf_token %} @@ -151,7 +151,7 @@

Blocked Users

- + {% csrf_token %} @@ -226,7 +226,7 @@

Current Users

- + {% csrf_token %}
diff --git a/go/go/views.py b/go/go/views.py index ab85cba69f64bfd84e704f82250f309897f5846b..c479623139352749b1b2e2f26cc9380fb85e7b6d 100644 --- a/go/go/views.py +++ b/go/go/views.py @@ -1,7 +1,9 @@ """ 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) diff --git a/go/settings/test_urls.py b/go/settings/test_urls.py index 31307cf09c9d7679f19b7f351cdf15163fd9ff59..e407eecafc61ccac42c6fde9280b8435306bd43e 100644 --- a/go/settings/test_urls.py +++ b/go/settings/test_urls.py @@ -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/ - Delete a link, no content display. diff --git a/go/settings/urls.py b/go/settings/urls.py index d61b2301613d9b7e647c092703abeded4a61349b..4b95538b3e16446b8fc7ff06e3e11eb6f85e40ab 100644 --- a/go/settings/urls.py +++ b/go/settings/urls.py @@ -1,7 +1,8 @@ """ 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/ - View URL data. Cached for 15 minutes - url(r'^view/(?P[-\w]+)$', cache_page(60*15)(go.views.view), name='view'), + url(r'^view/(?P[-\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/ - Edit link form url(r'^edit/(?P[-\w]+)$', go.views.edit, name='edit'), @@ -49,25 +48,18 @@ urlpatterns = [ url(r'^delete/(?P[-\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[-\w]+)$', go.views.redirection, name='redirection'), ]