Skip to content

Commit

Permalink
Converted final two apps over to new structure
Browse files Browse the repository at this point in the history
  • Loading branch information
codeinthehole committed Jun 15, 2011
1 parent cccce7a commit b2c8270
Show file tree
Hide file tree
Showing 9 changed files with 84 additions and 22 deletions.
1 change: 1 addition & 0 deletions examples/vanilla/settings.py
Original file line number Diff line number Diff line change
Expand Up @@ -207,6 +207,7 @@
'oscar.apps.reports',
'oscar.apps.search',
'pyzen',
'sorl.thumbnail',
)

AUTHENTICATION_BACKENDS = (
Expand Down
2 changes: 1 addition & 1 deletion examples/vanilla/templates/layout.html
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,7 @@
<div id="header">
<p><a href="{% url promotions:home %}">Oscar // Flexible e-commerce for Django</a></p>

<form method="get" action="{% url oscar-search %}">
<form method="get" action="{% url search:search %}">
{{ search_form.as_p }}
<input type="submit" value="Go!" />
</form>
Expand Down
9 changes: 7 additions & 2 deletions oscar/app.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,16 +7,21 @@
from oscar.apps.checkout.app import application as checkout_app
from oscar.apps.promotions.app import application as promotions_app
from oscar.apps.order_management.app import application as order_management_app
from oscar.apps.search.app import application as search_app
from oscar.apps.reports.app import application as reports_app


class Shop(Application):
name = None

product_app = product_app
customer_app = customer_app
basket_app = basket_app
checkout_app = checkout_app
promotions_app = promotions_app
order_management_app = order_management_app
search_app = search_app
reports_app = reports_app

def get_urls(self):
urlpatterns = patterns('',
Expand All @@ -25,8 +30,8 @@ def get_urls(self):
(r'checkout/', include(self.checkout_app.urls)),
(r'order-management/', include(self.order_management_app.urls)),
(r'accounts/', include(self.customer_app.urls)),
(r'reports/', include('oscar.apps.reports.urls')),
(r'search/', include('oscar.apps.search.urls')),
(r'reports/', include(self.reports_app.urls)),
(r'search/', include(self.search_app.urls)),
(r'^$', include(self.promotions_app.urls)),
)
return urlpatterns
Expand Down
20 changes: 20 additions & 0 deletions oscar/apps/reports/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
from django.conf.urls.defaults import patterns, url
from django.contrib.admin.views.decorators import staff_member_required
from haystack.query import SearchQuerySet

from oscar.core.application import Application
from oscar.apps.reports.views import DashboardView


class ReportsApplication(Application):
name = 'reports'

dashboard_view = DashboardView

def get_urls(self):
urlpatterns = patterns('',
url(r'^$', self.dashboard_view.as_view(), name='dashboard'),
)
return urlpatterns

application = ReportsApplication()
4 changes: 2 additions & 2 deletions oscar/apps/reports/templates/reports/dashboard.html
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
{% extends "layout_admin.html" %}
{% extends "layout.html" %}

{% load currency_filters %}

Expand All @@ -9,7 +9,7 @@ <h2>Reporting dashboard</h2>

{% block content %}

<form method="GET" action="{% url oscar-report-dashboard %}">
<form method="GET" action="{% url reports:dashboard %}">

{{ form.as_p }}
<input type="submit" value="Generate report" />
Expand Down
35 changes: 20 additions & 15 deletions oscar/apps/reports/views.py
Original file line number Diff line number Diff line change
@@ -1,25 +1,30 @@
from django.http import HttpResponse, HttpResponseForbidden, Http404
from django.template.response import TemplateResponse
from django.views.generic import TemplateView

from oscar.core.loading import import_module
report_forms = import_module('reports.forms', ['ReportForm'])
report_utils = import_module('reports.utils', ['GeneratorRepository'])

def dashboard(request):
if 'report_type' in request.GET:
form = report_forms.ReportForm(request.GET)
if form.is_valid():
generator = _get_generator(form)
if not generator.is_available_to(request.user):
return HttpResponseForbidden("You do not have access to this report")

response = HttpResponse(mimetype=generator.mimetype)
response['Content-Disposition'] = 'attachment; filename=%s' % generator.filename()
generator.generate(response)
return response
else:
form = report_forms.ReportForm()
return TemplateResponse(request, 'reports/dashboard.html', {'form': form})

class DashboardView(TemplateView):
template_name = 'reports/dashboard.html'

def get(self, request, *args, **kwargs):
if 'report_type' in request.GET:
form = report_forms.ReportForm(request.GET)
if form.is_valid():
generator = _get_generator(form)
if not generator.is_available_to(request.user):
return HttpResponseForbidden("You do not have access to this report")

response = HttpResponse(mimetype=generator.mimetype)
response['Content-Disposition'] = 'attachment; filename=%s' % generator.filename()
generator.generate(response)
return response
else:
form = report_forms.ReportForm()
return TemplateResponse(request, self.template_name, {'form': form})


def _get_generator(form):
Expand Down
31 changes: 31 additions & 0 deletions oscar/apps/search/app.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
from django.conf.urls.defaults import patterns, url
from django.contrib.admin.views.decorators import staff_member_required
from haystack.query import SearchQuerySet

from oscar.core.application import Application
from oscar.apps.search.views import SuggestionsView, MultiFacetedSearchView
from oscar.apps.search.search_indexes import ProductIndex
from oscar.apps.search.forms import MultiFacetedSearchForm


class SearchApplication(Application):
name = 'search'

suggestions_view = SuggestionsView
search_view = MultiFacetedSearchView

def get_urls(self):
sqs = SearchQuerySet()
for field_name, field in ProductIndex.fields.items():
if field.faceted is True:
# Ensure we facet the results set by the defined facetable fields
sqs.facet(field_name)

urlpatterns = patterns('',
url(r'^suggest/$', self.suggestions_view.as_view(), name='suggest'),
url(r'^$', self.search_view(form_class=MultiFacetedSearchForm,
searchqueryset=sqs), name='search'),
)
return urlpatterns

application = SearchApplication()
2 changes: 1 addition & 1 deletion oscar/apps/search/templates/search/results.html
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
<h2>Search for '{{ query }}'</h2>

{% if suggestion %}
Did you mean <a href="{% url oscar-search %}?q={{ suggestion }}">{{ suggestion }}</a>?
Did you mean <a href="{% url search:search %}?q={{ suggestion }}">{{ suggestion }}</a>?
{% endif %}


Expand Down
2 changes: 1 addition & 1 deletion oscar/apps/search/views.py
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@
product_models = import_module('product.models', ['Item'])


class Suggestions(View):
class SuggestionsView(View):
u"""
Auto suggest view
Expand Down

0 comments on commit b2c8270

Please sign in to comment.