Some actual code #1
Changes from 7 commits
e491e70
3b285ce
5c7d293
6fd9d1c
b638cf1
e9b9476
82643f6
a5ee37f
e22102b
b0d40ba
5e8bfe6
7e70786
c950a38
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -26,6 +26,7 @@ _site/ | |
*.log | ||
*.sql | ||
*.sqlite | ||
*.sqlite3 | ||
|
||
# OS generated files # | ||
###################### | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,89 @@ | ||
import os | ||
from unipath import Path | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
CFGOV_REFRESH = Path(__file__).ancestor(5).child('cfgov-refresh') | ||
|
||
SECRET_KEY = os.environ.get('SECRET_KEY', os.urandom(32)) | ||
|
||
# Application definition | ||
|
||
INSTALLED_APPS = ( | ||
'django.contrib.admin', | ||
'django.contrib.auth', | ||
'django.contrib.contenttypes', | ||
'django.contrib.sessions', | ||
'django.contrib.messages', | ||
'django.contrib.staticfiles', | ||
'sheerlike', | ||
) | ||
|
||
MIDDLEWARE_CLASSES = ( | ||
'sheerlike.middleware.GlobalRequestMiddleware', | ||
'django.contrib.sessions.middleware.SessionMiddleware', | ||
'django.middleware.common.CommonMiddleware', | ||
'django.middleware.csrf.CsrfViewMiddleware', | ||
'django.contrib.auth.middleware.AuthenticationMiddleware', | ||
'django.contrib.auth.middleware.SessionAuthenticationMiddleware', | ||
'django.contrib.messages.middleware.MessageMiddleware', | ||
'django.middleware.clickjacking.XFrameOptionsMiddleware', | ||
'django.middleware.security.SecurityMiddleware', | ||
) | ||
|
||
ROOT_URLCONF = 'cfgov.urls' | ||
|
||
TEMPLATES = [ | ||
{ | ||
'BACKEND': 'django.template.backends.django.DjangoTemplates', | ||
'DIRS': [], | ||
'APP_DIRS': True, | ||
'OPTIONS': { | ||
'context_processors': [ | ||
'django.template.context_processors.debug', | ||
'django.template.context_processors.request', | ||
'django.contrib.auth.context_processors.auth', | ||
'django.contrib.messages.context_processors.messages', | ||
], | ||
}, | ||
}, | ||
{ | ||
'BACKEND': 'django.template.backends.jinja2.Jinja2', | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we not want this before the DjangoTemplates engine? Wouldn't this cause this to always try django templating first and then fall back on Jinja2? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That's a good point-- you're probably right There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Fixed in a5ee37f |
||
'OPTIONS':{ | ||
'environment':'sheerlike.environment' | ||
} | ||
}, | ||
] | ||
|
||
WSGI_APPLICATION = 'cfgov.wsgi.application' | ||
|
||
|
||
# Database | ||
# https://docs.djangoproject.com/en/1.8/ref/settings/#databases | ||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.8/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
# Static files (CSS, JavaScript, Images) | ||
# https://docs.djangoproject.com/en/1.8/howto/static-files/ | ||
|
||
STATIC_URL = '/static/' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from .base import * | ||
|
||
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__))) | ||
|
||
CFGOV_REFRESH = Path(__file__).ancestor(5).child('cfgov-refresh') | ||
|
||
DEBUG = True | ||
|
||
|
||
ALLOWED_HOSTS = ['*'] | ||
|
||
# Application definition | ||
|
||
|
||
DATABASES = { | ||
'default': { | ||
'ENGINE': 'django.db.backends.sqlite3', | ||
'NAME': os.path.join(BASE_DIR, 'db.sqlite3'), | ||
} | ||
} | ||
|
||
|
||
# Internationalization | ||
# https://docs.djangoproject.com/en/1.8/topics/i18n/ | ||
|
||
LANGUAGE_CODE = 'en-us' | ||
|
||
TIME_ZONE = 'UTC' | ||
|
||
USE_I18N = True | ||
|
||
USE_L10N = True | ||
|
||
USE_TZ = True | ||
|
||
|
||
|
||
STATIC_URL = '/static/' | ||
|
||
|
||
|
||
SHEER_SITES=[CFGOV_REFRESH] | ||
SHEER_ELASTICSEARCH_SERVER = 'localhost:9200' | ||
SHEER_ELASTICSEARCH_INDEX = 'content' |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,95 @@ | ||
from django.conf.urls import include, url | ||
from django.contrib import admin | ||
from django.views.generic.base import RedirectView, TemplateView | ||
|
||
from sheerlike.views.generic import SheerTemplateView | ||
|
||
|
||
urlpatterns = [ | ||
url(r'^$', SheerTemplateView.as_view(), name='home'), | ||
|
||
url(r'^blog/', include([ | ||
url(r'^$', TemplateView.as_view(template_name='blog/index.html'), | ||
name='index'), | ||
url(r'^(?P<doc_id>[\w-]+)/$', | ||
SheerTemplateView.as_view(doc_type='posts', | ||
local_name='post', | ||
default_template='blog/_single.html',), | ||
name='detail'),], namespace='blog')), | ||
|
||
url(r'^newsroom/', include([ | ||
url(r'^$', TemplateView.as_view(template_name='newsroom/index.html'), | ||
name='index'), | ||
url(r'^press-resources/$', | ||
TemplateView.as_view(template_name='newsroom/press-resources/index.html'), | ||
name='press-resources'), | ||
url(r'^(?P<doc_id>[\w-]+)/$', | ||
SheerTemplateView.as_view(doc_type='newsroom', | ||
local_name='newsroom', | ||
default_template='newsroom/_single.html',), | ||
name='detail'),], namespace='newsroom')), | ||
|
||
url(r'^budget/',include([ | ||
url(r'^$', TemplateView.as_view(template_name='budget/index.html'), name='home'), | ||
url(r'^(?P<page_slug>[\w-]+)/$', | ||
SheerTemplateView.as_view(), | ||
name='page'), | ||
], namespace="budget")), | ||
|
||
url(r'^the-bureau/', include([ | ||
url(r'^$', SheerTemplateView.as_view(template_name='the-bureau/index.html'), | ||
name='index'), | ||
url(r'^(?P<page_slug>[\w-]+)/$', | ||
SheerTemplateView.as_view(), | ||
name='page'), | ||
], namespace='the-bureau')), | ||
|
||
url(r'^doing-business-with-us/', include([ | ||
url(r'^$', | ||
TemplateView.as_view(template_name='doing-business-with-us/index.html'), | ||
name='index'), | ||
url(r'^(?P<page_slug>[\w-]+)/$', | ||
SheerTemplateView.as_view(), | ||
name='page'), | ||
|
||
], namespace='business')), | ||
|
||
url(r'^contact-us/', include([ | ||
url(r'^$', | ||
TemplateView.as_view(template_name='contact-us/index.html'), | ||
name='index'), | ||
|
||
], namespace='contact-us')), | ||
|
||
url(r'^events/', include([ | ||
url(r'^$', TemplateView.as_view(template_name='events/index.html'), | ||
name='events'), | ||
url(r'^(?P<doc_id>[\w-]+)/$', | ||
SheerTemplateView.as_view(doc_type='events', | ||
local_name='event', | ||
default_template='events/_single.html',),name='event_archive') | ||
])), | ||
|
||
url(r'^offices/', include([ | ||
url(r'^(?P<doc_id>[\w-]+)/$', | ||
SheerTemplateView.as_view(doc_type='office', | ||
local_name='office', | ||
default_template='offices/_single.html',),name='detail') | ||
], namespace='offices')), | ||
|
||
url(r'^sub-pages/', include([ | ||
url(r'^(?P<doc_id>[\w-]+)/$', | ||
SheerTemplateView.as_view(doc_type='sub_page', | ||
local_name='sub_page', | ||
default_template='sub-pages/_single.html',),name='detail') | ||
], namespace='sub_page')), | ||
url(r'^activity-log/$', TemplateView.as_view(template_name='activity-log/index.html'), name='activity-log'), | ||
] | ||
|
||
from sheerlike import register_permalink | ||
|
||
register_permalink('posts', 'blog:detail') | ||
register_permalink('newsroom', 'newsroom:detail') | ||
register_permalink('office', 'offices:detail') | ||
register_permalink('sub_page', 'sub_page:detail') | ||
register_permalink('events', 'event_archive') |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,16 @@ | ||
""" | ||
WSGI config for cfgov project. | ||
|
||
It exposes the WSGI callable as a module-level variable named ``application``. | ||
|
||
For more information on this file, see | ||
https://docs.djangoproject.com/en/1.8/howto/deployment/wsgi/ | ||
""" | ||
|
||
import os | ||
|
||
from django.core.wsgi import get_wsgi_application | ||
|
||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cfgov.settings") | ||
|
||
application = get_wsgi_application() |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.contrib import admin | ||
|
||
# Register your models here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.db import models | ||
|
||
# Create your models here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,51 @@ | ||
from django.views.generic.base import View | ||
|
||
|
||
|
||
class PDFGeneratorView(View): | ||
render_url = None | ||
stylesheet_url= None | ||
filename = None | ||
|
||
def get_render_url(self): | ||
if self.render_url is None: | ||
raise ImproperlyConfigured( | ||
"PDFGeneratorView requires either a definition of " | ||
"'render_url' or an implementation of 'get_render_url()'") | ||
|
||
def get_stylesheer_url(self): | ||
if self.stylesheet_url is None: | ||
raise ImproperlyConfigured( | ||
"PDFGeneratorView requires either a definition of " | ||
"'stylesheer_url' or an implementation of 'get_stylesheer_url()'") | ||
|
||
def get_filename(self): | ||
if self.filename is None: | ||
raise ImproperlyConfigured( | ||
"PDFGeneratorView requires either a definition of " | ||
"'filename' or an implementation of 'get_filename()'") | ||
|
||
def generate_pdf(self): | ||
pdf_reactor = PDFreactor() | ||
pdf_reactor.setLogLevel(PDFreactor.LOG_LEVEL_WARN) | ||
pdf_reactor.setLicenseKey(PDFREACTOR_LICENSE) | ||
pdf_reactor.setAuthor('CFPB') | ||
pdf_reactor.setAddTags(True) | ||
pdf_reactor.setAddBookmarks(True) | ||
pdf_reactor.addUserStyleSheet('', '', '', self.get_stylesheet_url()) | ||
result = \ | ||
pdf_reactor.renderDocumentFromURL('{0}?{1}'.format(self.get_render_url(), | ||
self.request.query_string)) | ||
# Check if successful | ||
if result is None: | ||
# Not successful, print error and log | ||
print "error was ", pdf_reactor.getError(), " log was ", \ | ||
pdf_reactor.getLog() | ||
fail_with_code_and_message('Error while rendering PDF') | ||
else: | ||
# Set the correct header for PDF output and echo PDF content | ||
resp = make_response(result) | ||
resp.mimetype = 'application/pdf' | ||
resp.headers["Content-Disposition"] = "attachment; filename={0}".format(filename) | ||
return resp | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.test import TestCase | ||
|
||
# Create your tests here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,3 @@ | ||
from django.shortcuts import render | ||
|
||
# Create your views here. |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,10 @@ | ||
#!/usr/bin/env python | ||
import os | ||
import sys | ||
|
||
if __name__ == "__main__": | ||
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "cfgov.settings.local") | ||
|
||
from django.core.management import execute_from_command_line | ||
|
||
execute_from_command_line(sys.argv) |
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,6 @@ | ||
unipath>=1.1,<=2.0 | ||
django>=1.8,<=1.9 | ||
git+https://github.com/rosskarchner/django-sheerlike.git#egg=sheerlike | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Do we want to keep you as the owner here? Just until your PR get's pulled in? There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Just until the PR's get pulled in-- there's no code in the CFPB version of sheerlike yet. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Latest commit fixes this |
||
six==1.9.0 | ||
python-dateutil==2.4.2 | ||
requests |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why are we using
ancestor
instead ofparent
?There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Also concerning my other comment, this could be
CFGOV_REFRESH = Path(__file__).ancestor(5).child('cfgov-refresh').child('dist')
to solve that problem.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
because the equivalent of ancestor(5) would be parent.parent.parent.parent.parent? ;)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think I'd prefer to keep CFGOV_REFRESH pointed at the top level project..., we can add .child('dist') in the SHEER_SITES setting.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Addressed in latest commit
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Yeah I realized the parent() thing during lunch /facepalm 😟
Should we create a PROJECT_ROOT setting instead and then get the parent from that? Seems like we'd find putting the settings file where we want useful?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That might make sense for deployment scenarios, but I really think the simplest thing here is assuming both repos are sitting next to each other.