Explorar el Código

Converted final two apps over to new structure

master
David Winterbottom hace 14 años
padre
commit
b2c8270e29

+ 1
- 0
examples/vanilla/settings.py Ver fichero

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

+ 1
- 1
examples/vanilla/templates/layout.html Ver fichero

@@ -8,7 +8,7 @@
8 8
         <div id="header">
9 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 12
                 {{ search_form.as_p }}
13 13
                 <input type="submit" value="Go!" /> 
14 14
             </form>

+ 7
- 2
oscar/app.py Ver fichero

@@ -7,16 +7,21 @@ from oscar.apps.basket.app import application as basket_app
7 7
 from oscar.apps.checkout.app import application as checkout_app
8 8
 from oscar.apps.promotions.app import application as promotions_app
9 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 14
 class Shop(Application):
13 15
     name = None
16
+    
14 17
     product_app = product_app
15 18
     customer_app = customer_app
16 19
     basket_app = basket_app
17 20
     checkout_app = checkout_app
18 21
     promotions_app = promotions_app
19 22
     order_management_app = order_management_app
23
+    search_app = search_app
24
+    reports_app = reports_app
20 25
     
21 26
     def get_urls(self):
22 27
         urlpatterns = patterns('',
@@ -25,8 +30,8 @@ class Shop(Application):
25 30
             (r'checkout/', include(self.checkout_app.urls)),
26 31
             (r'order-management/', include(self.order_management_app.urls)),
27 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 35
             (r'^$', include(self.promotions_app.urls)),             
31 36
         )
32 37
         return urlpatterns

+ 20
- 0
oscar/apps/reports/app.py Ver fichero

@@ -0,0 +1,20 @@
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 Ver fichero

@@ -1,4 +1,4 @@
1
-{% extends "layout_admin.html" %}
1
+{% extends "layout.html" %}
2 2
 
3 3
 {% load currency_filters %}
4 4
 
@@ -9,7 +9,7 @@
9 9
 
10 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 14
     {{ form.as_p }} 
15 15
     <input type="submit" value="Generate report" />

+ 20
- 15
oscar/apps/reports/views.py Ver fichero

@@ -1,25 +1,30 @@
1 1
 from django.http import HttpResponse, HttpResponseForbidden, Http404
2 2
 from django.template.response import TemplateResponse
3
+from django.views.generic import TemplateView
3 4
 
4 5
 from oscar.core.loading import import_module
5 6
 report_forms = import_module('reports.forms', ['ReportForm'])
6 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 30
 def _get_generator(form):

+ 31
- 0
oscar/apps/search/app.py Ver fichero

@@ -0,0 +1,31 @@
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 Ver fichero

@@ -7,7 +7,7 @@
7 7
 <h2>Search for '{{ query }}'</h2>
8 8
 
9 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 11
 {% endif %}
12 12
 
13 13
 

+ 1
- 1
oscar/apps/search/views.py Ver fichero

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

Loading…
Cancelar
Guardar