Browse Source

Converted final two apps over to new structure

master
David Winterbottom 14 years ago
parent
commit
b2c8270e29

+ 1
- 0
examples/vanilla/settings.py View File

207
     'oscar.apps.reports',
207
     'oscar.apps.reports',
208
     'oscar.apps.search',
208
     'oscar.apps.search',
209
     'pyzen',
209
     'pyzen',
210
+    'sorl.thumbnail',
210
 )
211
 )
211
 
212
 
212
 AUTHENTICATION_BACKENDS = (
213
 AUTHENTICATION_BACKENDS = (

+ 1
- 1
examples/vanilla/templates/layout.html View File

8
         <div id="header">
8
         <div id="header">
9
             <p><a href="{% url promotions:home %}">Oscar // Flexible e-commerce for Django</a></p>
9
             <p><a href="{% url promotions:home %}">Oscar // Flexible e-commerce for Django</a></p>
10
             
10
             
11
-            <form method="get" action="{% url oscar-search %}">
11
+            <form method="get" action="{% url search:search %}">
12
                 {{ search_form.as_p }}
12
                 {{ search_form.as_p }}
13
                 <input type="submit" value="Go!" /> 
13
                 <input type="submit" value="Go!" /> 
14
             </form>
14
             </form>

+ 7
- 2
oscar/app.py View File

7
 from oscar.apps.checkout.app import application as checkout_app
7
 from oscar.apps.checkout.app import application as checkout_app
8
 from oscar.apps.promotions.app import application as promotions_app
8
 from oscar.apps.promotions.app import application as promotions_app
9
 from oscar.apps.order_management.app import application as order_management_app
9
 from oscar.apps.order_management.app import application as order_management_app
10
+from oscar.apps.search.app import application as search_app
11
+from oscar.apps.reports.app import application as reports_app
10
 
12
 
11
 
13
 
12
 class Shop(Application):
14
 class Shop(Application):
13
     name = None
15
     name = None
16
+    
14
     product_app = product_app
17
     product_app = product_app
15
     customer_app = customer_app
18
     customer_app = customer_app
16
     basket_app = basket_app
19
     basket_app = basket_app
17
     checkout_app = checkout_app
20
     checkout_app = checkout_app
18
     promotions_app = promotions_app
21
     promotions_app = promotions_app
19
     order_management_app = order_management_app
22
     order_management_app = order_management_app
23
+    search_app = search_app
24
+    reports_app = reports_app
20
     
25
     
21
     def get_urls(self):
26
     def get_urls(self):
22
         urlpatterns = patterns('',
27
         urlpatterns = patterns('',
25
             (r'checkout/', include(self.checkout_app.urls)),
30
             (r'checkout/', include(self.checkout_app.urls)),
26
             (r'order-management/', include(self.order_management_app.urls)),
31
             (r'order-management/', include(self.order_management_app.urls)),
27
             (r'accounts/', include(self.customer_app.urls)),
32
             (r'accounts/', include(self.customer_app.urls)),
28
-            (r'reports/', include('oscar.apps.reports.urls')),
29
-            (r'search/', include('oscar.apps.search.urls')),
33
+            (r'reports/', include(self.reports_app.urls)),
34
+            (r'search/', include(self.search_app.urls)),
30
             (r'^$', include(self.promotions_app.urls)),             
35
             (r'^$', include(self.promotions_app.urls)),             
31
         )
36
         )
32
         return urlpatterns
37
         return urlpatterns

+ 20
- 0
oscar/apps/reports/app.py View File

1
+from django.conf.urls.defaults import patterns, url
2
+from django.contrib.admin.views.decorators import staff_member_required
3
+from haystack.query import SearchQuerySet
4
+
5
+from oscar.core.application import Application
6
+from oscar.apps.reports.views import DashboardView
7
+
8
+
9
+class ReportsApplication(Application):
10
+    name = 'reports'
11
+    
12
+    dashboard_view = DashboardView
13
+
14
+    def get_urls(self):
15
+        urlpatterns = patterns('',
16
+            url(r'^$', self.dashboard_view.as_view(), name='dashboard'),
17
+        )
18
+        return urlpatterns
19
+
20
+application = ReportsApplication()

+ 2
- 2
oscar/apps/reports/templates/reports/dashboard.html View File

1
-{% extends "layout_admin.html" %}
1
+{% extends "layout.html" %}
2
 
2
 
3
 {% load currency_filters %}
3
 {% load currency_filters %}
4
 
4
 
9
 
9
 
10
 {% block content %}
10
 {% block content %}
11
 
11
 
12
-<form method="GET" action="{% url oscar-report-dashboard %}">
12
+<form method="GET" action="{% url reports:dashboard %}">
13
 
13
 
14
     {{ form.as_p }} 
14
     {{ form.as_p }} 
15
     <input type="submit" value="Generate report" />
15
     <input type="submit" value="Generate report" />

+ 20
- 15
oscar/apps/reports/views.py View File

1
 from django.http import HttpResponse, HttpResponseForbidden, Http404
1
 from django.http import HttpResponse, HttpResponseForbidden, Http404
2
 from django.template.response import TemplateResponse
2
 from django.template.response import TemplateResponse
3
+from django.views.generic import TemplateView
3
 
4
 
4
 from oscar.core.loading import import_module
5
 from oscar.core.loading import import_module
5
 report_forms = import_module('reports.forms', ['ReportForm'])
6
 report_forms = import_module('reports.forms', ['ReportForm'])
6
 report_utils = import_module('reports.utils', ['GeneratorRepository'])
7
 report_utils = import_module('reports.utils', ['GeneratorRepository'])
7
 
8
 
8
-def dashboard(request):
9
-    if 'report_type' in request.GET:
10
-        form = report_forms.ReportForm(request.GET)
11
-        if form.is_valid():
12
-            generator = _get_generator(form)
13
-            if not generator.is_available_to(request.user):
14
-                return HttpResponseForbidden("You do not have access to this report")
15
-            
16
-            response = HttpResponse(mimetype=generator.mimetype)
17
-            response['Content-Disposition'] = 'attachment; filename=%s' % generator.filename()
18
-            generator.generate(response)
19
-            return response
20
-    else:
21
-        form = report_forms.ReportForm()
22
-    return TemplateResponse(request, 'reports/dashboard.html', {'form': form})
9
+
10
+class DashboardView(TemplateView):
11
+    template_name = 'reports/dashboard.html'
12
+    
13
+    def get(self, request, *args, **kwargs):
14
+        if 'report_type' in request.GET:
15
+            form = report_forms.ReportForm(request.GET)
16
+            if form.is_valid():
17
+                generator = _get_generator(form)
18
+                if not generator.is_available_to(request.user):
19
+                    return HttpResponseForbidden("You do not have access to this report")
20
+                
21
+                response = HttpResponse(mimetype=generator.mimetype)
22
+                response['Content-Disposition'] = 'attachment; filename=%s' % generator.filename()
23
+                generator.generate(response)
24
+                return response
25
+        else:
26
+            form = report_forms.ReportForm()
27
+        return TemplateResponse(request, self.template_name, {'form': form})
23
 
28
 
24
 
29
 
25
 def _get_generator(form):
30
 def _get_generator(form):

+ 31
- 0
oscar/apps/search/app.py View File

1
+from django.conf.urls.defaults import patterns, url
2
+from django.contrib.admin.views.decorators import staff_member_required
3
+from haystack.query import SearchQuerySet
4
+
5
+from oscar.core.application import Application
6
+from oscar.apps.search.views import SuggestionsView, MultiFacetedSearchView
7
+from oscar.apps.search.search_indexes import ProductIndex
8
+from oscar.apps.search.forms import MultiFacetedSearchForm
9
+
10
+
11
+class SearchApplication(Application):
12
+    name = 'search'
13
+    
14
+    suggestions_view = SuggestionsView
15
+    search_view = MultiFacetedSearchView
16
+
17
+    def get_urls(self):
18
+        sqs = SearchQuerySet()
19
+        for field_name, field in ProductIndex.fields.items():
20
+            if field.faceted is True:
21
+                # Ensure we facet the results set by the defined facetable fields
22
+                sqs.facet(field_name)
23
+        
24
+        urlpatterns = patterns('',
25
+            url(r'^suggest/$', self.suggestions_view.as_view(), name='suggest'),
26
+            url(r'^$', self.search_view(form_class=MultiFacetedSearchForm, 
27
+                                        searchqueryset=sqs), name='search'),
28
+        )
29
+        return urlpatterns
30
+
31
+application = SearchApplication()

+ 1
- 1
oscar/apps/search/templates/search/results.html View File

7
 <h2>Search for '{{ query }}'</h2>
7
 <h2>Search for '{{ query }}'</h2>
8
 
8
 
9
 {% if suggestion %}
9
 {% if suggestion %}
10
-Did you mean <a href="{% url oscar-search %}?q={{ suggestion }}">{{ suggestion }}</a>?
10
+Did you mean <a href="{% url search:search %}?q={{ suggestion }}">{{ suggestion }}</a>?
11
 {% endif %}
11
 {% endif %}
12
 
12
 
13
 
13
 

+ 1
- 1
oscar/apps/search/views.py View File

11
 product_models = import_module('product.models', ['Item'])
11
 product_models = import_module('product.models', ['Item'])
12
 
12
 
13
 
13
 
14
-class Suggestions(View):
14
+class SuggestionsView(View):
15
     u"""
15
     u"""
16
     Auto suggest view
16
     Auto suggest view
17
 
17
 

Loading…
Cancel
Save