Changeset - dd2774211489
[Not reviewed]
2 2 1
Ben Sturmfels (bsturmfels) - 3 months ago 2024-03-06 07:46:40
ben@sturm.com.au
Move Python code out of the "conservancy/static" directory

Having Python code in "conservancy/static" is a bit suprising to people familiar
with Django. The name "static" is usually reserved for assets like CSS, JS and
images.

I'm moving `conservancy/static/views.py` to `conservancy/views.py` and removing
`conservancy/static/__init__.py`.
4 files changed with 3 insertions and 3 deletions:
0 comments (0 inline, 0 general)
conservancy/static/__init__.py
Show inline comments
 
deleted file
conservancy/supporter/urls.py
Show inline comments
 
from django.conf.urls import url
 
from django.views.generic import TemplateView
 

	
 
from . import views as supp_views
 
from ..static import views as static_views
 
from .. import views as static_views
 

	
 
INDEX_VIEW = supp_views.index
 
urlpatterns = [
 
    url(r'^$', INDEX_VIEW),
 
    url(r'^banners?/?$', TemplateView.as_view(template_name='supporter/banners.html')),
 
]
 
urlpatterns.extend(
 
    url(r'^{}(?:\.html|/|)$'.format(basename), INDEX_VIEW)
 
    for basename in ['index', '2015-supporter-appeal', '2016-supporter-appeal']
 
)
 
urlpatterns.append(url(r'', static_views.index))
conservancy/urls.py
Show inline comments
...
 
@@ -2,49 +2,49 @@
 
# Copyright 2010, 2012 Bradley M. Kuhn
 

	
 
# This software's license gives you freedom; you can copy, convey,
 
# propagate, redistribute, modify and/or redistribute modified versions of
 
# this program under the terms of the GNU Affero General Public License
 
# (AGPL) as published by the Free Software Foundation (FSF), either
 
# version 3 of the License, or (at your option) any later version of the
 
# AGPL published by the FSF.
 
#
 
# This program is distributed in the hope that it will be useful, but
 
# WITHOUT ANY WARRANTY; without even the implied warranty of
 
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU Affero
 
# General Public License for more details.
 
#
 
# You should have received a copy of the GNU Affero General Public License
 
# along with this program in a file in the toplevel directory called
 
# "AGPLv3".  If not, see <http://www.gnu.org/licenses/>.
 

	
 
from django.conf.urls import url
 
from django.urls import include, path
 
from django.contrib import admin
 

	
 
from . import feeds, frontpage, sponsors
 
from .fundgoal import views as fundgoal_views
 
from .static import views as static_views
 
from . import views as static_views
 

	
 
admin.autodiscover()
 

	
 
urlpatterns = [
 
    url(r'^$', frontpage.view),
 
    url(r'^sponsors$', frontpage.view),
 
    url(r'^sponsors/$', sponsors.view),
 
    url(r'^sponsors/index.html$', sponsors.view),
 
    url(r'^admin/', admin.site.urls),
 
    url(r'^feeds/blog/?$', feeds.BlogFeed()),
 
    url(r'^feeds/news/?$', feeds.PressReleaseFeed()),
 
    url(r'^feeds/omnibus/?$', feeds.OmnibusFeed()),
 
    url(r'^feeds/?$', feeds.view),
 
    url(r'^news/', include('conservancy.news.urls')),
 
    url(r'^blog/', include('conservancy.blog.urls')),
 
    # formerly static templated things... (dirs with templates)
 
    url(r'^error/(40[134]|500)(?:/index\.html|/|)$', static_views.handler),
 
    url(r'^error', static_views.index),
 
    url(r'^about', static_views.index),
 
    url(r'^activities', static_views.index),
 
    url(r'^donate', static_views.index),
 
    url(r'^copyleft-compliance', static_views.index, {'fundraiser_sought': 'vmware-match-0'}),
 
    url(r'^learn', static_views.index),
 
    url(r'^press', static_views.index),
conservancy/views.py
Show inline comments
 
file renamed from conservancy/static/views.py to conservancy/views.py
 
import mimetypes
 
import os.path
 

	
 
from django.http import HttpResponse
 
from django.template.response import TemplateResponse
 

	
 
from ..local_context_processors import fundgoal_lookup
 
from .local_context_processors import fundgoal_lookup
 

	
 
STATIC_ROOT = os.path.abspath(os.path.dirname(__file__))
 
FILESYSTEM_ENCODING = 'utf-8'
 

	
 
def handler(request, errorcode):
 
    path = os.path.join('error', str(errorcode), 'index.html')
 
    fullpath = os.path.join(STATIC_ROOT, path)
 
    if not os.path.exists(fullpath):
 
        return HttpResponse("Internal error: " + path, status=int(errorcode))
 
    else:
 
        return TemplateResponse(request, path, status=int(errorcode))
 

	
 
def handler401(request):
 
    return handler(request, 401)
 

	
 
def handler403(request):
 
    return handler(request, 403)
 

	
 
def handler404(request):
 
    return handler(request, 404)
 

	
 
def handler500(request):
 
    return handler(request, 500)
 

	
0 comments (0 inline, 0 general)