Skip to content

Commit

Permalink
Merge branch 'clintonb-custom-request'
Browse files Browse the repository at this point in the history
  • Loading branch information
palewire committed Jan 16, 2017
2 parents fde7a72 + 85dec91 commit f6a2cd3
Show file tree
Hide file tree
Showing 7 changed files with 21 additions and 15 deletions.
File renamed without changes.
3 changes: 1 addition & 2 deletions bakery/feeds.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@
import logging
from django.conf import settings
from bakery.views import BuildableMixin
from django.test.client import RequestFactory
from django.contrib.syndication.views import Feed
logger = logging.getLogger(__name__)

Expand All @@ -22,7 +21,7 @@ def build_method(self):

def build_queryset(self):
logger.debug("Building %s" % self.build_path)
self.request = RequestFactory().get(self.build_path)
self.request = self.create_request(self.build_path)
self.prep_directory(self.build_path)
path = os.path.join(settings.BUILD_DIR, self.build_path)
self.build_file(path, self.get_content())
14 changes: 12 additions & 2 deletions bakery/views/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,16 @@ class BuildableMixin(object):
"""
Common methods we will use in buildable views.
"""
def create_request(self, path):
"""
Returns a GET request object for use when building views.
If inheriting views require additional request attributes
(e.g. user, site), override this method and define those
attributes on the returned object.
"""
return RequestFactory().get(path)

def get_content(self):
"""
How to render the HTML or other content for the page.
Expand Down Expand Up @@ -110,7 +120,7 @@ def build_method(self):

def build(self):
logger.debug("Building %s" % self.template_name)
self.request = RequestFactory().get(self.build_path)
self.request = self.create_request(self.build_path)
path = os.path.join(settings.BUILD_DIR, self.build_path)
self.prep_directory(self.build_path)
self.build_file(path, self.get_content())
Expand Down Expand Up @@ -161,7 +171,7 @@ def build(self):
self.build_path,
self.get_redirect_url()
))
self.request = RequestFactory().get(self.build_path)
self.request = self.create_request(self.build_path)
path = os.path.join(settings.BUILD_DIR, self.build_path)
self.prep_directory(self.build_path)
self.build_file(path, self.get_content())
Expand Down
9 changes: 4 additions & 5 deletions bakery/views/dates.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from datetime import date
from django.conf import settings
from bakery.views import BuildableMixin
from django.test.client import RequestFactory
from django.views.generic.dates import (
ArchiveIndexView,
YearArchiveView,
Expand Down Expand Up @@ -48,7 +47,7 @@ def build_method(self):

def build_queryset(self):
logger.debug("Building %s" % self.build_path)
self.request = RequestFactory().get(self.build_path)
self.request = self.create_request(self.build_path)
self.prep_directory(self.build_path)
path = os.path.join(settings.BUILD_DIR, self.build_path)
self.build_file(path, self.get_content())
Expand Down Expand Up @@ -105,7 +104,7 @@ def build_year(self, dt):
"""
self.year = str(dt.year)
logger.debug("Building %s" % self.year)
self.request = RequestFactory().get(self.get_url())
self.request = self.create_request(self.get_url())
path = self.get_build_path()
self.build_file(path, self.get_content())

Expand Down Expand Up @@ -189,7 +188,7 @@ def build_month(self, dt):
self.month = str(dt.month)
self.year = str(dt.year)
logger.debug("Building %s-%s" % (self.year, self.month))
self.request = RequestFactory().get(self.get_url())
self.request = self.create_request(self.get_url())
path = self.get_build_path()
self.build_file(path, self.get_content())

Expand Down Expand Up @@ -288,7 +287,7 @@ def build_day(self, dt):
self.year = str(dt.year)
self.day = str(dt.day)
logger.debug("Building %s-%s-%s" % (self.year, self.month, self.day))
self.request = RequestFactory().get(self.get_url())
self.request = self.create_request(self.get_url())
path = self.get_build_path()
self.build_file(path, self.get_content())

Expand Down
3 changes: 1 addition & 2 deletions bakery/views/detail.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@
from .base import BuildableMixin
from django.conf import settings
from django.views.generic import DetailView
from django.test.client import RequestFactory
from django.core.exceptions import ImproperlyConfigured
logger = logging.getLogger(__name__)

Expand Down Expand Up @@ -62,7 +61,7 @@ def set_kwargs(self, obj):

def build_object(self, obj):
logger.debug("Building %s" % obj)
self.request = RequestFactory().get(self.get_url(obj))
self.request = self.create_request(self.get_url(obj))
self.set_kwargs(obj)
path = self.get_build_path(obj)
self.build_file(path, self.get_content())
Expand Down
3 changes: 1 addition & 2 deletions bakery/views/list.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
from .base import BuildableMixin
from django.conf import settings
from django.views.generic import ListView
from django.test.client import RequestFactory
logger = logging.getLogger(__name__)


Expand Down Expand Up @@ -39,7 +38,7 @@ def build_method(self):

def build_queryset(self):
logger.debug("Building %s" % self.build_path)
self.request = RequestFactory().get(self.build_path)
self.request = self.create_request(self.build_path)
self.prep_directory(self.build_path)
path = os.path.join(settings.BUILD_DIR, self.build_path)
self.build_file(path, self.get_content())
4 changes: 2 additions & 2 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ def run(self):

setup(
name='django-bakery',
version='0.8.11',
version='0.8.12',
description='A set of helpers for baking your Django site out as flat files',
author='The Los Angeles Times Data Desk',
author_email='[email protected]',
Expand All @@ -111,10 +111,10 @@ def run(self):
'Programming Language :: Python :: 2.7',
'Programming Language :: Python :: 3',
'Programming Language :: Python :: 3.5',
'Programming Language :: Python :: Implementation :: PyPy',
'Framework :: Django',
'Framework :: Django :: 1.8',
'Framework :: Django :: 1.9',
'Framework :: Django :: 1.10',
'License :: OSI Approved :: MIT License',
],
install_requires=[
Expand Down

0 comments on commit f6a2cd3

Please sign in to comment.