Commit 25215037 authored by David Haynes's avatar David Haynes 🙆
Browse files

code cleanup - remove unnecessary views methods

- ie. About page has no logic, thus render with a TemplateView
- Also some new documentation for imports to make it look less messy
parent eb8ceb58
from go.models import URL, RegisteredUser # Django Imports
from go.forms import URLForm, SignupForm
from datetime import timedelta
from django.conf import settings from django.conf import settings
from django.http import HttpResponseServerError # Http404 from django.http import HttpResponseServerError # Http404
from django.utils import timezone from django.utils import timezone
# from django.contrib.auth.models import User
from django.core.exceptions import PermissionDenied # ValidationError from django.core.exceptions import PermissionDenied # ValidationError
from django.core.mail import send_mail from django.core.mail import send_mail
from django.contrib.auth import REDIRECT_FIELD_NAME from django.contrib.auth import REDIRECT_FIELD_NAME
from django.contrib.auth.decorators import user_passes_test, login_required from django.contrib.auth.decorators import user_passes_test, login_required
from django.shortcuts import render, get_object_or_404, redirect from django.shortcuts import render, get_object_or_404, redirect
# import os
# App Imports
from go.models import URL, RegisteredUser
from go.forms import URLForm, SignupForm
# Other Imports
from datetime import timedelta
############################################################################## ##############################################################################
""" """
...@@ -45,31 +47,6 @@ def is_registered(user): ...@@ -45,31 +47,6 @@ def is_registered(user):
return False return False
##############################################################################
"""
Define error page handling here.
"""
def error_404(request):
"""
Error 404 view, in case a url is not found.
"""
return render(request, '404.html', {
},
)
def error_500(request):
"""
Error 500 view, in case a server error occurs.
"""
return render(request, '500.html', {
},
)
############################################################################## ##############################################################################
""" """
Define user views here. Define user views here.
...@@ -248,7 +225,7 @@ def signup(request): ...@@ -248,7 +225,7 @@ def signup(request):
full_name = signup_form.cleaned_data.get('full_name') full_name = signup_form.cleaned_data.get('full_name')
description = signup_form.cleaned_data.get('description') description = signup_form.cleaned_data.get('description')
organization = signup_form.cleaned_data.get('organization') organization = signup_form.cleaned_data.get('organization')
# Only send mail if we've defined the mailserver # Only send mail if we've defined the mailserver
if settings.EMAIL_HOST and settings.EMAIL_PORT: if settings.EMAIL_HOST and settings.EMAIL_PORT:
# TODO rewrite see #14 # TODO rewrite see #14
...@@ -339,21 +316,3 @@ def useradmin(request): ...@@ -339,21 +316,3 @@ def useradmin(request):
'need_approval': need_approval 'need_approval': need_approval
}, },
) )
##############################################################################
"""
Define static user views here.
"""
def about(request):
return render(request, 'core/about.html', {
},
)
def registered(request):
return render(request, 'registered.html', {
},
)
# Django Imports
from django.conf.urls import patterns, include, url from django.conf.urls import patterns, include, url
import go.views
import django.contrib.auth.views import django.contrib.auth.views
from django.contrib import admin from django.contrib import admin
from django.conf import settings from django.conf import settings
from django.views.generic import TemplateView
# App Imports
import go.views
admin.autodiscover() admin.autodiscover()
handle404 = "error_404" handle404 = TemplateView.as_view(template_name="404.html")
handle500 = "error_500" handle500 = TemplateView.as_view(template_name="500.html")
urlpatterns = [ urlpatterns = [
# / - Homepage url. # / - Homepage url.
...@@ -17,7 +21,7 @@ urlpatterns = [ ...@@ -17,7 +21,7 @@ urlpatterns = [
url(r'^view/(?P<short>\w+)$', go.views.view, name='view'), url(r'^view/(?P<short>\w+)$', go.views.view, name='view'),
# /about - About page. # /about - About page.
url(r'^about/?$', go.views.about, name='about'), url(r'^about/?$', TemplateView.as_view(template_name='core/about.html'), name='about'),
# /signup - Signup page for access. # /signup - Signup page for access.
url(r'^signup/?$', go.views.signup, name='signup'), url(r'^signup/?$', go.views.signup, name='signup'),
...@@ -29,7 +33,7 @@ urlpatterns = [ ...@@ -29,7 +33,7 @@ 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 # /registered - registration complete page
url(r'^registered/?$', go.views.registered, name='registered'), url(r'^registered/?$', TemplateView.as_view(template_name='registered.html'), name='registered'),
# /admin - Administrator interface. # /admin - Administrator interface.
url(r'^admin/?', admin.site.urls), url(r'^admin/?', admin.site.urls),
......
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