Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
133 additions
and
11 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1 @@ | ||
import view_points |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,44 @@ | ||
from django.http import Http404 | ||
from django.conf import settings | ||
from django.core.urlresolvers import get_script_prefix | ||
from django.template.response import TemplateResponse | ||
|
||
from models import ViewPoint | ||
|
||
class DockitCMSMiddleware(object): | ||
ignore_script_prefix = False | ||
|
||
def process_response(self, request, response): | ||
if response.status_code != 404: | ||
return response # No need to check for a flashpage for non-404 responses. | ||
url = request.path_info | ||
chomped_url = url | ||
if self.ignore_script_prefix: | ||
prefix = None | ||
else: | ||
prefix = get_script_prefix() | ||
|
||
if prefix and chomped_url.startswith(prefix): | ||
chomped_url = chomped_url[len(prefix)-1:] | ||
try: | ||
#TODO find a more efficient way to do this | ||
for view_point in ViewPoint.objects.all(): | ||
if chomped_url.startswith(view_point.url): | ||
try: | ||
response = view_point.dispatch(request) | ||
except Http404: | ||
pass | ||
else: | ||
break | ||
if isinstance(response, TemplateResponse): | ||
response.render() | ||
return response | ||
# Return the original response if any errors happened. Because this | ||
# is a middleware, we can't assume the errors will be caught elsewhere. | ||
except Http404: | ||
return response | ||
except: | ||
if settings.DEBUG: | ||
raise | ||
return response | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,29 @@ | ||
from common import BaseViewPointClass, register_view_point_class | ||
|
||
from dockit.views import ListView, DetailView | ||
|
||
from django.conf.urls.defaults import patterns | ||
from django import forms | ||
|
||
class ListViewPointForm(forms.Form): | ||
list_template_name = forms.CharField() | ||
detail_template_name = forms.CharField() | ||
paginate_by = forms.IntegerField(required=False) | ||
|
||
class ListViewPointClass(BaseViewPointClass): | ||
form_class = ListViewPointForm | ||
|
||
def get_urls(self, view_point_doc): | ||
document = view_point_doc.collection.get_document() | ||
params = view_point_doc.view_config | ||
return patterns('', | ||
(r'$', ListView.as_view(model=document, | ||
template_name=params['list_template_name'], | ||
paginate_by=params.get('paginate_by', None)), | ||
), | ||
(r'^(?P<pk>.+)/$', DetailView.as_view(model=document, | ||
template_name=params['detail_template_name']), | ||
), | ||
) | ||
|
||
register_view_point_class('list', ListViewPointClass) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.